Flutter :The shrinker may have failed to optimize the Java bytecode
Solution 1
You just have to change the minsdkversion to 21 instead of 16.
In android\app\build.gradle
defaultConfig {
applicationId "com.company.example"
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
It worked or me. ;)
Solution 2
In the app's build.gradle
defaultConfig {
applicationId "com.company.test"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Change the minSdkversion from 16 to 21, this worked in my case
Solution 3
I have experienced similar problem while coding with flutter but BUILD FAILED in 9s
Running Gradle task 'assembleDebug'...
--no-shrink
Running Gradle task 'assembleDebug'... Done 11.0s
[!] The shrinker may have failed to optimize the Java bytecode.
To disable the shrinker, pass theflag to this command.
To learn more, see: https://developer.android.com/studio/build/shrink-code
Gradle task assembleDebug failed with exit code 1
But i have managed to run my app and this is how i did it.
1.I located android/app/build.gradle file 2. Then access below code in the gradle file
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
and changed it to
buildTypes {
debug {
minifyEnabled true
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
The app was able to run in Android emulator
Solution 4
There are two different answers to this issue but I think the most appropriate is the one given by @Sarang Pal This is the official explanation by Google:
Troubleshooting Android build fail:
If you're planning to develop using an Android device or emulator, you'll need to handle multidex support -- otherwise, your build will fail with "Cannot fit requested classes in a single dex file."
By default, Flutter supports Android SDK v16 (Jelly Bean, released 2012), but multidex doesn't really work with Jelly Bean (though, it's possible). Configuring Jelly Bean to work is beyond the scope of this codelab, so we'll change the minimum target SDK version from v16 to v21 (Lollipop, released 2014).
To change the minimum target SDK version:
- Open android/app/build.gradle, then find the line that says minSdkVersion 16.
- Change that line to minSdkVersion 21.
- Save the file.
https://codelabs.developers.google.com/codelabs/flutter-firebase/index.html#3
Solution 5
navigate to {your-app-name}\android\app\build.gradle
// change your minSdkVersion from 16 to 21
defaultConfig {
applicationId "com.example.testapp"
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
materoy
Updated on July 12, 2022Comments
-
materoy almost 2 years
I'm trying to integrate cloud firestore to and android app but all I get is this error every single time
Launching lib/main.dart on Android SDK built for x86 in debug mode... Note: /home/tr/DevTools/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.13.4+2/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. D8: Cannot fit requested classes in a single dex file (# methods: 76095 > 65536) com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: The number of method references in a .dex file cannot exceed 64K
FAILURE: Build failed with an exception.
-
What went wrong: Execution failed for task ':app:mergeDexDebug'.
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: The number of method references in a .dex file cannot exceed 64K. Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
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 6m 10s [!] The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the
--no-shrink
flag to this command. To learn more, see: https://developer.android.com/studio/build/shrink-code Exception: Gradle task assembleDebug failed with exit code 1 Exited (sigterm) -
-
David Buck almost 4 yearsWhile this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.