Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter :The shrinker may have failed to optimize the Java bytecode

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)

like image 307
materoy Avatar asked Mar 18 '20 18:03

materoy


People also ask

How do you turn off the shrinker in flutter?

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 .

How do I turn off shrinker?

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.

How to disable the Java bytecode Shrinker?

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.”

Why is the Java Shrinker not working?

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.

How to disable the Shrinker in Android Studio?

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.

What is the difference between version and build number in flutter?

# 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.


4 Answers

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

like image 108
Sarang Pal Avatar answered Oct 06 '22 21:10

Sarang Pal


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. ;)

like image 31
Mayur Agarwal Avatar answered Oct 06 '22 22:10

Mayur Agarwal


I have experienced similar problem while coding with flutter but BUILD FAILED in 9s Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 11.0s [!] The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the
--no-shrinkflag 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

like image 13
Eric Predicts Avatar answered Oct 06 '22 23:10

Eric Predicts


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:

  1. Open android/app/build.gradle, then find the line that says minSdkVersion 16.
  2. Change that line to minSdkVersion 21.
  3. Save the file.

https://codelabs.developers.google.com/codelabs/flutter-firebase/index.html#3

like image 9
Tomás Escamez Avatar answered Oct 06 '22 21:10

Tomás Escamez