Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Always download CodeScanner model instead of relying on Google Play Services #2355

Merged
merged 3 commits into from
Jan 8, 2024

Conversation

mrousavy
Copy link
Owner

@mrousavy mrousavy commented Jan 8, 2024

What

Instead of using RegEx replaces, this change adds a new prop to the build.gradle setup of VisionCamera: VisionCamera_enableCodeScanner.

VisionCamera_enableCodeScanner can be configured in your app's gradle.properties file:

# Can be set to true to include the full 2.4 MB MLKit dependency
#VisionCamera_enableCodeScanner=true

  • When VisionCamera_enableCodeScanner is set to false (the default), the Google Play Services MLKit library will be used which only includes the code for Barcode detection but not the 2.4 MB model. On phones that support Google Play Services, the model can be dynamically downloaded once you use a CodeScanner (useCodeScanner).
  • When VisionCamera_enableCodeScanner is set to true, VisionCamera will include the full MLKit dependency instead of the dynamic google play services one, and will bundle the 2.4 MB model into your app. This will work on every Android phone then, even without Google Play Services.

if (enableCodeScanner) {
// User enabled code-scanner, so we bundle the 2.4 MB model in the app.
implementation 'com.google.mlkit:barcode-scanning:17.2.0'
} else {
// Fall-back to just including the code for the CodeScanner to avoid the 2.4 MB bundle in the app.
// On devices with Google Play Services, this can also download the CodeScanner model on-demand.
implementation "com.google.android.gms:play-services-mlkit-barcode-scanning:18.3.0"
}

Changes

Tested on

Related issues

Copy link

vercel bot commented Jan 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-vision-camera ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 8, 2024 0:14am

@mrousavy mrousavy merged commit 5c99728 into main Jan 8, 2024
7 checks passed
@mrousavy mrousavy deleted the feat/always-download-model branch January 8, 2024 12:14
@kyjus25
Copy link

kyjus25 commented Jan 8, 2024

v3.7.0 works great! Thank you again!

@mrousavy
Copy link
Owner Author

mrousavy commented Jan 8, 2024

Awesome thanks for confirming!

isaaccolson pushed a commit to isaaccolson/deliveries-mobile that referenced this pull request Oct 30, 2024
… `CodeScanner` always works (mrousavy#2355)

* feat: Always download model instead of relying on Google Play Services

* feat: Use `VisionCamera_enableCodeScanner` flag instead of unsafely replacing

* Update CODE_SCANNING.mdx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants