Frederik Delißen

Add optional gradle property for unbundled scanner

@@ -27,11 +27,17 @@ See the example app for detailed implementation information. @@ -27,11 +27,17 @@ See the example app for detailed implementation information.
27 27
28 ## Platform specific setup 28 ## Platform specific setup
29 ### Android 29 ### Android
30 -This packages uses the **bundled version** of MLKit Barcode-scanning for Android. This version is more accurate and immediately available to devices. However, this version will increase the size of the app with approximately 3 to 10 MB. The alternative for this is to use the **unbundled version** of MLKit Barcode-scanning for Android. This version is older than the bundled version however this only increases the size by around 600KB.  
31 -To use this version you must alter the mobile_scanner gradle file to replace `com.google.mlkit:barcode-scanning:17.0.2` with `com.google.android.gms:play-services-mlkit-barcode-scanning:18.0.0`. Keep in mind that if you alter the gradle files directly in your project it can be overriden when you update your pubspec.yaml. I am still searching for a way to properly replace the module in gradle but have yet to find one. 30 +This package uses by default the **bundled version** of MLKit Barcode-scanning for Android. This version is immediately available to the devicee. But it will increase the size of the app by approximately 3 to 10 MB.
  31 +
  32 +The alternative is to use the **unbundled version** of MLKit Barcode-scanning for Android. This version is downloaded on first use via Google Play Services. It increases the app size by around 600KB.
32 33
33 [You can read more about the difference between the two versions here.](https://developers.google.com/ml-kit/vision/barcode-scanning/android) 34 [You can read more about the difference between the two versions here.](https://developers.google.com/ml-kit/vision/barcode-scanning/android)
34 35
  36 +To use the **unbundled version** of the MLKit Barcode-scanning, add the following line to your `/android/gradle.properties` file:
  37 +```
  38 +dev.steenbakker.mobile_scanner.useUnbundled=true
  39 +```
  40 +
35 ### iOS 41 ### iOS
36 **Add the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:** 42 **Add the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:**
37 NSCameraUsageDescription - describe why your app needs access to the camera. This is called Privacy - Camera Usage Description in the visual editor. 43 NSCameraUsageDescription - describe why your app needs access to the camera. This is called Privacy - Camera Usage Description in the visual editor.
@@ -50,10 +50,14 @@ android { @@ -50,10 +50,14 @@ android {
50 dependencies { 50 dependencies {
51 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 51 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
52 52
53 - // Use this dependency to bundle the model with your app 53 + def useUnbundled = project.findProperty('dev.steenbakker.mobile_scanner.useUnbundled') ?: false
  54 + if (useUnbundled.toBoolean()) {
  55 + // Dynamically downloaded model via Google Play Services
  56 + implementation 'com.google.android.gms:play-services-mlkit-barcode-scanning:18.1.0'
  57 + } else {
  58 + // Bundled model in app
54 implementation 'com.google.mlkit:barcode-scanning:17.2.0' 59 implementation 'com.google.mlkit:barcode-scanning:17.2.0'
55 - // Use this dependency to use the dynamically downloaded model in Google Play Services  
56 -// implementation 'com.google.android.gms:play-services-mlkit-barcode-scanning:18.1.0' 60 + }
57 61
58 implementation 'androidx.camera:camera-camera2:1.2.3' 62 implementation 'androidx.camera:camera-camera2:1.2.3'
59 implementation 'androidx.camera:camera-lifecycle:1.2.3' 63 implementation 'androidx.camera:camera-lifecycle:1.2.3'