Getting Error while Dexing. after upgrading flutter to 3.19.0
T

7

8

After upgrading to flutter 3.19.0 i am getting the following error while running my application on android it is working fine on ios and when i open only android directory in android studio and run the project in that case also it is working fine.

ERROR:D8: com.android.tools.r8.kotlin.H
ERROR:D8: com.android.tools.r8.kotlin.H
ERROR:D8: com.android.tools.r8.kotlin.H
ERROR:D8: com.android.tools.r8.kotlin.H

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeExtDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform firebase-auth-22.3.1.aar (com.google.firebase:firebase-auth:22.3.1) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=23, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingWithClasspathTransform: /home/munsif/.gradle/caches/transforms-3/ba579288272952d282e3eb784bb3facc/transformed/jetified-firebase-auth-22.3.1-runtime.jar.
         > Error while dexing.
   > Failed to transform play-services-location-21.1.0.aar (com.google.android.gms:play-services-location:21.1.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=23, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingWithClasspathTransform: /home/munsif/.gradle/caches/transforms-3/c40ae925c2dff28a07b701244ea18adb/transformed/jetified-play-services-location-21.1.0-runtime.jar.
         > Error while dexing.
   > Failed to transform recaptcha-18.4.0.aar (com.google.android.recaptcha:recaptcha:18.4.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=23, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingWithClasspathTransform: /home/munsif/.gradle/caches/transforms-3/6a9b2598905fd8f95f3e5a4db9115179/transformed/jetified-recaptcha-18.4.0-runtime.jar.
         > Error while dexing.
   > Failed to transform kotlin-stdlib-1.9.0.jar (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=23, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingWithClasspathTransform: /home/munsif/.gradle/caches/transforms-3/ae0183353754275aa55a66ddf2de48d6/transformed/jetified-kotlin-stdlib-1.9.0.jar.
         > Error while dexing.

I tried adding these to gradle.properties

android.useAndroidX=true
android.enableJetifier=true

enabling multiDex like this in build.gradle:

android {
    defaultConfig {
        ...
        multiDexEnabled true
    }
}

add this line to build.gradle

implementation 'com.android.support:multidex:1.0.3'

all these methods didn't solved my problem: any solution for this problem?

Tunisia answered 19/2 at 7:58 Comment(0)
T
8

Changing the compileSdkVersion solved my problem.

I changed compileSdkVersion in android/app/build.gradle

From

 compileSdkVersion flutter.compileSdkVersion

TO

compileSdkVersion 33

and the error gone.

EDIT:

I got the same issue when i change the compile sdk to 34 which flutter recommended me because i was using url_launcher and video_player which use compileSdk 34. and as i changed the compileSdkVersion to 34 i got the same issue again and that i solved by changing the minSdkVersion to 24 from 21

Change From

minSdkVersion 21

To

minSdkVersion 24

Thanks to Johnyp

Tunisia answered 19/2 at 9:48 Comment(3)
This didn't solve my problem. – Idolla
I solved it later by setting kotlin version to 1.7.21 – Idolla
Thank You :-) Solve the Problem πŸ‘ – Valadez
L
17

Changing minSdkVersion solved it for me. When having minSdkVersion 21 i had the exact same issue, increasing it to 24 solved the issue for me.

minSdkVersion 24
Lingwood answered 19/2 at 13:47 Comment(4)
I do also spent hours on this. This is the right solution. No need to change compileSdkVersion flutter.compileSdkVersion. – Gusti
Thanks for the solution, spent couple of hours – Stacey
no need to change to 24: https://mcmap.net/q/1321842/-failed-to-transform-firebase-auth-22-3-1-aar – Unwashed
Great. I didn't think that might work. Thanks – Impalpable
T
8

Changing the compileSdkVersion solved my problem.

I changed compileSdkVersion in android/app/build.gradle

From

 compileSdkVersion flutter.compileSdkVersion

TO

compileSdkVersion 33

and the error gone.

EDIT:

I got the same issue when i change the compile sdk to 34 which flutter recommended me because i was using url_launcher and video_player which use compileSdk 34. and as i changed the compileSdkVersion to 34 i got the same issue again and that i solved by changing the minSdkVersion to 24 from 21

Change From

minSdkVersion 21

To

minSdkVersion 24

Thanks to Johnyp

Tunisia answered 19/2 at 9:48 Comment(3)
This didn't solve my problem. – Idolla
I solved it later by setting kotlin version to 1.7.21 – Idolla
Thank You :-) Solve the Problem πŸ‘ – Valadez
C
1

Munsif's answer works, but Flutter supports minSdk 21. Additionally, firebase also supports sdk 21. as well. There is no reason to remove support for older SDKs.

So each persons specific build issue might be slightly different. But you need to migrate your build.gradle files to use the new declarative plugins block. This is very important as you may need to update your android gradle plugin and wrapper to 8.0+. This requirement depends on your libraries. But if you can get it working, it's best to do so.

To quote the most important part of that link above:

To build a Flutter app for Android, Flutter's Gradle plugins must be applied. Historically, this was done imperatively with Gradle's legacy, imperative apply script method.

In Flutter 3.16, support was added for applying these plugins with Gradle's declarative plugins {} block (also called the Plugin DSL) and it is now the recommended approach. Since Flutter 3.16, projects generated with flutter create use the Plugin DSL to apply Gradle plugins. Projects created with versions of Flutter prior to 3.16 need to be migrated manually.

The key part here is, manually. After you do that, update your AGP to something 8.0+. In my case I did:

id "com.android.application" version "8.1.1" apply false

Fix any build issues that arise from that based on your specific needs. I had the exact same build issue, but got flutter on Android running again on 3.19 without needing to bump the minSdk version to 24.

Commuter answered 8/4 at 3:10 Comment(0)
C
1

In order to keep using minSdk=21, and still compile your project to sdk=34, use older gradle version.

Use classpath 'com.android.tools.build:gradle:7.3.0'
Catalog answered 8/5 at 5:34 Comment(0)
B
1

Just change minSdk to 24

defaultConfig {
        applicationId "com.example.app"
        minSdk = 24
        targetSdk = flutter.targetSdkVersion
        versionCode = flutterVersionCode.toInteger()
        versionName = flutterVersionName
    }
Brie answered 4/7 at 17:3 Comment(0)
R
0

Change minSdkVersion to 24, that helped me.

Rodrigues answered 28/4 at 15:53 Comment(0)
P
0

This error only happens when running the app locally (debugging). It should builds fine for release & debug with minSdkVersion 21.

Add the following to the /app/src/build.gradle file:

buildTypes {
    debug {
        minSdkVersion 21
        signingConfig signingConfigs.debug
    }
}
Production answered 5/6 at 8:48 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.