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)
Shrinking your code with R8 R8 is the new code shrinker from Google, and it's enabled by default when you build a release APK or AAB. To disable R8, pass the --no-shrink flag to flutter build apk or flutter build appbundle .
To disable the shrinker, pass the `--no-shrink` flag to this command. BUILD FAILED in 46s [!] The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the `--no-shrink` flag to this command.
Java answers related to “The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the `--no-shrink` flag to this command.” Java queries related to “The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the `--no-shrink` flag to this command.”
The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the `--no-shrink` flag to this command. the shrinker may have failed to optimize the java bytecode. to disable the shrinker, pass the `--no-shrink` flag to this command.
The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the --no-shrink flag to this command. Hope!!! it helps. Go to android/app/build.gradle and then copy and paste this and change the application id.
# A version number is three numbers separated by dots, like 1.2.43 # followed by an optional build number separated by a +. # Both the version and the builder number may be overridden in flutter # build by specifying --build-name and --build-number, respectively.
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
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. ;)
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
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:
https://codelabs.developers.google.com/codelabs/flutter-firebase/index.html#3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With