From 82b7c7228c4e7dfe005de79978377a1cdf04b1d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20Deli=C3=9Fen?= Date: Tue, 10 Oct 2023 14:58:27 +0200 Subject: [PATCH 1/3] Add optional gradle property for unbundled scanner --- README.md | 22 ++++++++++++++-------- android/build.gradle | 12 ++++++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8ea9dd9be..3eeef22e6 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![mobile_scanner](https://github.com/juliansteenbakker/mobile_scanner/actions/workflows/flutter.yml/badge.svg)](https://github.com/juliansteenbakker/mobile_scanner/actions/workflows/flutter.yml) [![GitHub Sponsors](https://img.shields.io/github/sponsors/juliansteenbakker?label=like%20my%20work?%20sponsor%20me!)](https://github.com/sponsors/juliansteenbakker) -A universal scanner for Flutter based on MLKit. Uses CameraX on Android and AVFoundation on iOS. +A universal scanner for Flutter based on MLKit. Uses CameraX on Android and AVFoundation on iOS. ## Features Supported @@ -27,28 +27,34 @@ See the example app for detailed implementation information. ## Platform specific setup ### Android -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. -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. +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. + +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. [You can read more about the difference between the two versions here.](https://developers.google.com/ml-kit/vision/barcode-scanning/android) +To use the **unbundled version** of the MLKit Barcode-scanning, add the following line to your `/android/gradle.properties` file: +``` +dev.steenbakker.mobile_scanner.useUnbundled=true +``` + ### iOS **Add the following keys to your Info.plist file, located in /ios/Runner/Info.plist:** NSCameraUsageDescription - describe why your app needs access to the camera. This is called Privacy - Camera Usage Description in the visual editor. - + **If you want to use the local gallery feature from [image_picker](https://pub.dev/packages/image_picker)** NSPhotoLibraryUsageDescription - describe why your app needs permission for the photo library. This is called Privacy - Photo Library Usage Description in the visual editor. - + Example, ``` NSCameraUsageDescription This app needs camera access to scan QR codes - + NSPhotoLibraryUsageDescription This app needs photos access to get QR code from photo library ``` - - + + ### macOS Ensure that you granted camera permission in XCode -> Signing & Capabilities: diff --git a/android/build.gradle b/android/build.gradle index e81c0abac..fa0da60fe 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -50,10 +50,14 @@ android { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - // Use this dependency to bundle the model with your app - implementation 'com.google.mlkit:barcode-scanning:17.2.0' - // Use this dependency to use the dynamically downloaded model in Google Play Services -// implementation 'com.google.android.gms:play-services-mlkit-barcode-scanning:18.1.0' + def useUnbundled = project.findProperty('dev.steenbakker.mobile_scanner.useUnbundled') ?: false + if (useUnbundled.toBoolean()) { + // Dynamically downloaded model via Google Play Services + implementation 'com.google.android.gms:play-services-mlkit-barcode-scanning:18.1.0' + } else { + // Bundled model in app + implementation 'com.google.mlkit:barcode-scanning:17.2.0' + } implementation 'androidx.camera:camera-camera2:1.2.3' implementation 'androidx.camera:camera-lifecycle:1.2.3' From 5991132d15224d0c81d17d9ef32f6aa8aeaba8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20Deli=C3=9Fen?= Date: Tue, 10 Oct 2023 15:08:55 +0200 Subject: [PATCH 2/3] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3eeef22e6..bfb33dc22 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ See the example app for detailed implementation information. ## Platform specific setup ### Android -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. +This package uses by default the **bundled version** of MLKit Barcode-scanning for Android. This version is immediately available to the device. But it will increase the size of the app by approximately 3 to 10 MB. 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. From dd51070f2103139eacff0eec1473b4e8ac2bfad8 Mon Sep 17 00:00:00 2001 From: Volodymyr Buberenko Date: Thu, 12 Oct 2023 01:03:33 +0300 Subject: [PATCH 3/3] fix: Change Kotlin version from 1.9.10 to 1.7.22 to fix Android builds --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index e81c0abac..e3e951184 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,7 +2,7 @@ group 'dev.steenbakker.mobile_scanner' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.9.10' + ext.kotlin_version = '1.7.22' repositories { google() mavenCentral()