juliansteenbakker / mobile_scanner

A universal scanner for Flutter based on MLKit. Uses CameraX on Android and AVFoundation on iOS.
BSD 3-Clause "New" or "Revised" License
817 stars 476 forks source link

Document new Android minimum requirements in the README (Java version / minSdk / compileSdk) #922

Open burekas7 opened 8 months ago

burekas7 commented 8 months ago

The package suddenly requires Android SDK version 34 even without updating it. I'm using version 3.5.2 now which works all the time, but suddenly I start to get this requirement.

Probably after clear the cache.

I can't update my sdk now to 34 because I have a problem with other packages.

How can I solve it? How can I use mobile_scanner with sdk 33?

Thanks

burekas7 commented 8 months ago

Warning: The plugin mobile_scanner requires Android SDK version 34.
For more information about build configuration, see https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
One or more plugins require a higher Android SDK version.
Fix this issue by adding the following to /Users/aditzoref/vscodeProjects/Deliveright/mobile_xp_driver/android/app/build.gradle:
android {
  compileSdkVersion 34
  ...
}

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > One or more issues found when checking AAR metadata values:

     The minCompileSdk (34) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-33).
     Dependency: androidx.camera:camera-core:1.3.1.
     AAR metadata file: /Users/------/.gradle/caches/transforms-3/090e3908a3264c467bd84b2d12b9d4fc/transformed/jetified-camera-core-1.3.1/META-INF/com/android/build/gradle/aar-metadata.properties.

     The minCompileSdk (34) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-33).
     Dependency: androidx.camera:camera-lifecycle:1.3.1.
     AAR metadata file: /Users/------/.gradle/caches/transforms-3/f34c10f8d10da3bc85b5f2fe44189204/transformed/jetified-camera-lifecycle-1.3.1/META-INF/com/android/build/gradle/aar-metadata.properties.

     The minCompileSdk (34) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-33).
     Dependency: androidx.camera:camera-camera2:1.3.1.
     AAR metadata file: /Users/------/.gradle/caches/transforms-3/b2b6d871caeedfb83eada49bc1d8f9d1/transformed/jetified-camera-camera2-1.3.1/META-INF/com/android/build/gradle/aar-metadata.properties.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 17s
burekas7 commented 8 months ago

After updating to 34 I'm getting this error:

* What went wrong:
Execution failed for task ':mobile_scanner:compileDebugJavaWithJavac'.
> error: invalid source release: 17
VictorWork0721 commented 8 months ago

Me too after updated to 34 then getting this error:

chinghoi commented 8 months ago

After updating to 34 I'm getting this error:

* What went wrong:
Execution failed for task ':mobile_scanner:compileDebugJavaWithJavac'.
> error: invalid source release: 17

I think this error on 3.5.6, use 3.5.5 working.

burekas7 commented 8 months ago

After updating to 34 I'm getting this error:

* What went wrong:
Execution failed for task ':mobile_scanner:compileDebugJavaWithJavac'.
> error: invalid source release: 17

I think this error on 3.5.6, use 3.5.5 working.

Doesn't help, also with 3.5.5

EDIT: Works when removing the ^ with 3.5.5

chinghoi commented 8 months ago

3.5.5

If your version is ^3.5.5, change to 3.5.5, try it again.

rjahn commented 8 months ago

Is working with 3.5.5

Any information about compatibility in future versions? android sdk 33+ or 34+?

burekas7 commented 8 months ago

3.5.5

If your version is ^3.5.5, change to 3.5.5, try it again.

Thanks, it works when removing the ^ with 3.5.5.

Is going to be a fix to 3.5.6?

koji-1009 commented 8 months ago

The following commit looks like the library is now requesting ~sdk 34~ java 17. https://github.com/juliansteenbakker/mobile_scanner/commit/f125c828c148e3f0be9ed8b95e3b01f7aaa82cb6

thomasklaush commented 8 months ago

Strange thing, I can build with the higher version on my machine, but on codemagic it fails with the same error Same Flutter and plugin version

juliansteenbakker commented 8 months ago

Hi all, the version update to sdk 34 wasn't supposed to be in a minor update. I will roll this change back, and reintroduce it later in a new major version.

thomasklaush commented 8 months ago

I think the real issue (I use 34 already) is the change to Java 17 I try it currently if it works, if I upgrade my project to JAVA 17

juliansteenbakker commented 8 months ago

If you change your java setting to 17 it should work. I am using the latest versions in production without any issues. However, it should be better to have this breaking change in a new major version of mobile_scanner.

juliansteenbakker commented 8 months ago

I have reverted the upgrade on the master branch. Can someone confirm this fixes the issues?

Duskfen commented 8 months ago

when using package on master branch it works again: grafik

So i can confirm it fixes the issue

shemhazai commented 8 months ago

Unfortunately reverting the compileSdkVersion from 34 to 33 in this package still doesn't resolve the problem because other dependencies depend on compileSdkVersion 34. Logs from trying to build the android app with compileSdkVersion set to 33:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkStagingDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > One or more issues found when checking AAR metadata values:

     Dependency 'androidx.camera:camera-core:1.3.1' requires 'compileSdkVersion' to be set to 34 or higher.
     Compilation target for module ':app' is 'android-33'

     Dependency 'androidx.camera:camera-lifecycle:1.3.1' requires 'compileSdkVersion' to be set to 34 or higher.
     Compilation target for module ':app' is 'android-33'

     Dependency 'androidx.camera:camera-camera2:1.3.1' requires 'compileSdkVersion' to be set to 34 or higher.
     Compilation target for module ':app' is 'android-33'
burekas7 commented 8 months ago

I think the real issue (I use 34 already) is the change to Java 17 I try it currently if it works, if I upgrade my project to JAVA 17

I tried it also, tried to install the v17, and I still got this error.

navaronbracke commented 8 months ago

The switch to compileSdk 34 is to support Android 14, which has nothing to do with the change in Java version, those are separate. However, the switch to Java 17 was to support Android Studio Hedgehog iirc.

cc @juliansteenbakker

vbuberen commented 7 months ago

@juliansteenbakker The main reason is in updated dependencies that require SDK 34. So your revert for compileSDK doesn't solve the problem. Just validated it from pulling latest commit from master.

To address issues users have camera and lifecycle dependencies versions should be reverted to those that don't require SDK 34.

I will open a PR as it also affects one of big projects where I decided to use this plugin.

UPD: Except just reverting CameraX to 1.2.3 there is also need to revert changes made in this commit: https://github.com/juliansteenbakker/mobile_scanner/commit/240a374851034ff00e4702a1795ce48dc20efd20 The reason for that is the fact that resolutionselector was added in version 1.3.0 of CameraX. Due to this fact I would leave up to you to decide if you want to revert those changes as well to address this issue or just re-release last update as a breaking change mentioning that projects using the plugin need to have compileSDK 34 now.

juliansteenbakker commented 7 months ago

I've released v4.0.0 with the changes of the android SDK version.

vbuberen commented 7 months ago

I've released v4.0.0 with the changes of the android SDK version.

Awesome, that should work. But maybe also update README to have notes on top of previous releases with https://github.com/juliansteenbakker/mobile_scanner/commit/240a374851034ff00e4702a1795ce48dc20efd20 commit that they also require compileSDK 34? As I expect some people would still open issues and say that the plugin doesn't work for them before v4.

hls-app commented 7 months ago

I have just upgraded to ^4.0.0 and I can confirm that this is still a problem.

android {
    compileSdk 34
    ndkVersion "25.1.8937393"
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    // added this to see if this fixes the problem as I was already using 34 as compileSdk
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 21
        targetSdkVersion 34
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

I am using Codmagic for CI/CD and this only fails there. There is no problem with building this locally.

vbuberen commented 7 months ago

I am using Codmagic for CI/CD and this only fails there. There is no problem with building this locally.

Could you share the logs from Codemagic build?

hls-app commented 7 months ago

Sure,

== Building for Android ==

> flutter build appbundle --release --dart-define-from-file=api-keys.json

Running Gradle task 'bundleRelease'...                          
Building with Flutter multidex support enabled.
Checking the license for package Android SDK Platform 34 in /usr/local/share/android-sdk/licenses
License for package Android SDK Platform 34 accepted.
Preparing "Install Android SDK Platform 34 (revision: 2)".
"Install Android SDK Platform 34 (revision: 2)" ready.
Installing Android SDK Platform 34 in /usr/local/share/android-sdk/platforms/android-34
"Install Android SDK Platform 34 (revision: 2)" complete.
"Install Android SDK Platform 34 (revision: 2)" finished.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /Users/builder/.pub-cache/hosted/pub.dev/in_app_review-2.0.8/android/src/main/java/dev/britannio/in_app_review/InAppReviewPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':mobile_scanner:compileReleaseJavaWithJavac'.
> error: invalid source release: 17

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2m 6s
Running Gradle task 'bundleRelease'...                            126.8s
Gradle task bundleRelease failed with exit code 1

Build failed :|
Failed to build for Android
vbuberen commented 7 months ago

error: invalid source release: 17

You need to configure your pipeline on Codemagic correctly vie environment variables to pick Java 17. By default on MacOS runner Java 11 is selected and you need to change it. It is not related to the plugin.

Start here https://github.com/orgs/codemagic-ci-cd/discussions/2132

hls-app commented 7 months ago

Thanks mate. @vbuberen literally came to post the link you just pasted.

hls-app commented 7 months ago

For anyone facing issues with Codemagic, set your environment variable.

JAVA_HOME: /Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home

rjahn commented 7 months ago

Doesn't work standalone in my environment:

Execution failed for task ':mobile_scanner:compileReleaseJavaWithJavac'.
> error: invalid source release: 17

Used JDK is: 17.0.2

also set:

compileSdkVersion 34
targetSdkVersion 34
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
jvmTarget = '17'

in android/app/build.gradle

navaronbracke commented 7 months ago

@rjahn You'll have to select which Java version your CI system uses to build. I had to do a similar thing for Bitrise by going into the settings of my build pipeline.

rjahn commented 7 months ago

I have a simple script an set JAVA_HOME to the correct path of java 17. My build script shows 17.0.2. The script executes flutter directly.

My default JDK is java 19, if I don't set JAVA_HOME. My script shows 19.0.1 for the java version.

So this should be right. Maybe a missed property in a gradle file?

rjahn commented 7 months ago

I tried to add:

def currentJvm = org.gradle.internal.jvm.Jvm.current()
println currentJvm

to the build.gradle of mobile_scanner and this shows java 11. So you're right. Very interesting.

rjahn commented 7 months ago

setting:

org.gradle.java.home=

in android/gradle.properties solved my problem. I don't know right now, why setting JAVA_HOME doesn't work.

WieFel commented 7 months ago

I was also stuck at this problem. In the app/build.gradle I saw that

compileSdkVersion flutter.compileSdkVersion

was set. But this variable was set nowhere in my local.properties file, which is where these values are defined.

So, in my local.properties file, I added:

flutter.compileSdkVersion=34

But still, it behaved like the compileSdkVersion was not set nowhere. So I found out that I also needed to add the following to my app/build.gradle, next to where other variables are defined:

def flutterCompileSdkVersion = localProperties.getProperty('flutter.compileSdkVersion').toInteger()
if (flutterCompileSdkVersion == null) {
    flutterCompileSdkVersion = flutter.compileSdkVersion
}

And within the android { } section, set:

compileSdkVersion flutterCompileSdkVersion

All of this (along with opening the android folder in Android Studio and syncing/upgrading gradle) solved it for me. Using version 4.0.0 of the mobile_scanner package.

navaronbracke commented 7 months ago

@WieFel flutterCompileSdkVersion is defined in the Gradle plugin that is vendored by the Flutter SDK itself, and is included in the project template when you create a project. Perhaps you had removed it manually, even though you still referenced it?

See https://github.com/flutter/flutter/blob/0903bf7055d3e75921159a999ff1816154078968/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy#L46

WieFel commented 7 months ago

@navaronbracke thanks for the information. Apparently, in my case it was not set. I have never removed it. This is a project which was freshly set up using Flutter version 3.13.9 in the past November. That's why I just wanted to give the steps I made, for anyone facing the same issue

goerlitz commented 6 months ago

I'm just started working with flutter and I'm still facing this issue in my local dev env (Mac + VSCode) with an almost fresh flutter starter project.

After changing

minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion

to

minSdkVersion 21
targetSdkVersion 34

in /android/app/build.gradle

I see a lot of these errors: Duplicate class {...} found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)

I have no clue where jetified-kotlin-stdlib-1.8.22 or jetified-kotlin-stdlib-jdk8-1.7.10 is defined as a requirement and for which reason - is one of them a requirement by mobile-scanner? Why?

goerlitz commented 6 months ago

I finally figured out a solution after a bit more digging in the Gradle configuration documentation.

It seems to me that flutter create is actually generating configuration files with surprising old version numbers. In the end I only had to update 2 things to fix the errors and run the app with mobile_scanner:

  1. in /android/app/build.gradle minSdkVersion 21 no need to change targetSdkVersion

  2. in /android/settings.gradle id "org.jetbrains.kotlin.android" version "1.8.22" apply false (was set to 1.7.0)

navaronbracke commented 6 months ago

Well, that is expected. The min SDK default is being bumped from 19 to 21 I think (there was in-engine work for that recently).

As for the Kotlin version, I think that depends on the flutter create template, which is only version bumped every so often, to keep a wide compatibility range. (although Gradle 8 should be the new Gradle version that it sets up)

goerlitz commented 6 months ago

I totally understand that there can be version issues. However, for somebody new to flutter it is highly frustrating to face such errors especially when doing exactly what is written in the installation instruction and examples.

At this point in time I don't really understand the inner workings of the flutter/android/gradle configurations (yet), why this might clash with mobile_scanner or if this is something that mobile_scanner could solve or should mention in its documentation. But I feel that googling the problem and doing trial and error for 1-2h just to get it working is not a good DX.

DieGlueckswurst commented 5 months ago

I set the env variable like you @hls-app suggested, but now CodeMagic fails, with no description at all. Anyone else experiencing this?

Bildschirmfoto 2024-03-17 um 15 21 31 Bildschirmfoto 2024-03-17 um 15 22 07
mmazurovsky commented 5 months ago

this worked for me for both version 3.5.5 and 4.0.1 (i did not try other versions and didn't use ^ when specifying the version in pubspec.yaml):

  1. in build.gradle set minSdkVersion 21
  2. in gradle.properties add org.gradle.java.home={your jdk path, in my case /Users/me/.sdkman/candidates/java/current}
  3. set global java version to 17, im using sdkman (and highly recommend it) and set default version like this: sdk default java 17.0.10-amzn

all the other possible solutions mentioned in this thread didn't work for me.

I think it is worth noting the configuration process for android in the readme and in the pub.dev page of the package. I needed to spend 5 hours trying different adjustments to make it work.

Still want to thank maintainers of the package, it works great for us

navaronbracke commented 5 months ago

Reopening based on the comment above. We should indeed document the Java 17 / minSdk requirement in the README.

Currently there is only a changelog note for it.

KyoheiG3 commented 5 months ago

I also spent some time building an Android app with Github Actions. I solved the problem by setting the Java version to 17 in .gradle and using setup-java to specify the Java version before executing the Android build in Github Actions.

- uses: actions/setup-java@v4
  with:
    java-version: 17
    distribution: temurin

We can see this in the workflow of actions, but I think you need to write about CI/CD as it is not mentioned in the documentation.

https://github.com/juliansteenbakker/mobile_scanner/blob/v5.0.0-beta.2/.github/workflows/flutter.yml#L15-L18