on android latest version getting compile error
Opened this issue · 5 comments
What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
An issue was found when checking AAR metadata:
1. Dependency ':qr_code_scanner' requires core library desugaring to be enabled
for :app.
I have same the problem:
* What went wrong:
A problem occurred configuring project ':qr_code_scanner'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
> Namespace not specified. Specify a namespace in the module's build file: /Users/frank/.pub-cache/hosted/pub.dev/qr_code_scanner-1.0.1/android/build.gradle. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.
If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.
settings.gradle:
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.7.0" apply false
id "org.jetbrains.kotlin.android" version "2.0.21" apply false
id "com.google.gms.google-services" version "4.4.2" apply false
}
Did anyone find a solution?
add
// for qr_code_scanner
subprojects {
afterEvaluate { project ->
if (project.hasProperty('android')) {
project.android {
if (namespace == null) {
namespace project.group
}
}
}
}
}
in scope allprojects {}
I found an easier way to fix.
The issue was caused by Android Studio Ladybug having bundled a version of Java that isn't fully backward compatible with Flutter's plugin ecosystem (source).
Since I was using Java 11 before (installed separately using homebrew), all I need to do was to tell Flutter to use that java version, instead of the JRE bundled inside Android Studio. To do that I just have to execute this command:
$ flutter config --jdk-dir /path/to/my/java
And my flutter project was compiling correctly again without any change to the project itself.
If you don't have any other Java on your machine, see the source above to install it. They say Java 17 is the last working version.
Alternative here https://github.com/wizmea/qr_code_scanner
Alternative here https://github.com/wizmea/qr_code_scanner
This work but in my case I had to fork it and change the java/kotlin version to match my app, so you might need to do the same if u get a version mismatch