Android Gradle build fails dexBuilderDebug task, after updating to Kotlin 1.4
Asked Answered
E

2

19

I've tried to update my Android project to Kotlin 1.4.0, since it's now oficially stable, and after update I've encountered a problem. I will not post the entire stack here, since it's very long, but the mot top part of it looks like this:

...
> Task :app:transformClassesWithFirebasePerformancePluginForDebug
java.lang.ClassNotFoundException: javax.mail.internet.MimeBodyPart
> Task :app:mergeDebugJavaResource
> Task :app:dexBuilderDebug FAILED
org.gradle.workers.WorkerExecutionException: There was a failure while executing work items
...

Looking for a cause, lower in the stack, I've found this:

...
Caused by: org.gradle.tooling.BuildException: Failed to process: 
/bitrise/src/app/build/intermediates/transforms/FirebasePerformancePlugin/debug/0, 
/bitrise/src/app/build/intermediates/transforms/FirebasePerformancePlugin/debug/1,
/bitrise/src/app/build/intermediates/transforms/FirebasePerformancePlugin/debug/2
...

Which directs me to the conclusion, that Firebase Performance library cannot be build correctly. I'm using Firebase Performance version 19.0.8 with gradle classpath plugin version 1.3.1. I have not changed it for a while, and reverting to earlier versions does not resolve the issue. The last error registered on stack is this:

Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.
    at com.android.builder.dexing.D8DexArchiveBuilder.getExceptionToRethrow(D8DexArchiveBuilder.java:151)
    at com.android.builder.dexing.D8DexArchiveBuilder.convert(D8DexArchiveBuilder.java:118)
    at com.android.build.gradle.internal.dexing.DexWorkActionKt.process(DexWorkAction.kt:194)
    ... 33 more
Caused by: java.lang.IllegalStateException: Unexpected non-class file: META-INF/versions/9/kotlin/reflect/jvm/internal/impl/serialization/deserialization/builtins/BuiltInsResourceLoader.class

I've determined, that removing Firebase Performance library and reverting back to Kotlin 1.3.71 resolves the problem, but I'd like to keep them both for future of the project, so I'm looking for other solution.

My build.gradle file:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
apply plugin: 'androidx.navigation.safeargs.kotlin'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.firebase.firebase-perf'
apply from: "dependencies.gradle"
apply from: "buildtypes.gradle"

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 100
        versionName "1.0.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        archivesBaseName = "$applicationId-$versionName-$versionCode"
    }

    compileOptions {
        coreLibraryDesugaringEnabled true
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }

    buildFeatures {
        dataBinding = true
    }
}

And a complete list of dependencies:

    coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:$versions.coreDesugaring"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    implementation "androidx.core:core:$versions.core"
    implementation "androidx.core:core-ktx:$versions.core"
    implementation "androidx.appcompat:appcompat:$versions.appCompat"
    implementation "androidx.browser:browser:$versions.browser"
    implementation "androidx.constraintlayout:constraintlayout:$versions.constraintLayout"
    implementation "androidx.legacy:legacy-support-v4:$versions.legacy"

    // UI
    implementation "com.google.android.material:material:$versions.material"
    implementation "com.appyvet:materialrangebar:$versions.materialRangeBar"
    implementation "com.wdullaer:materialdatetimepicker:$versions.datetimepicker"

    // Lifecycle
    implementation "androidx.lifecycle:lifecycle-extensions:$versions.lifecycle"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$versions.lifecycle"

    // Navigation component
    implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
    implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"

    // Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$versions.coroutines"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$versions.coroutines"

    // Koin
    implementation "org.koin:koin-android:$versions.koin"
    implementation "org.koin:koin-androidx-ext:$versions.koin"
    implementation "org.koin:koin-androidx-scope:$versions.koin"
    implementation "org.koin:koin-androidx-viewmodel:$versions.koin"

    // Work Manager
    implementation "androidx.work:work-runtime:$versions.work"
    implementation "androidx.work:work-runtime-ktx:$versions.work"

    // Flipper
    debugImplementation "com.facebook.soloader:soloader:$versions.soloader"
    debugImplementation "com.facebook.flipper:flipper-network-plugin:$versions.flipper"
    debugImplementation "com.kgurgul.flipper:flipper-realm-android:$versions.flipperRealm"
    debugImplementation "com.facebook.flipper:flipper:$versions.flipper"
    releaseImplementation "com.facebook.flipper:flipper-noop:$versions.flipper"

    // Location & Maps
    implementation "com.google.android.gms:play-services-maps:$versions.playLocation"
    implementation "com.google.android.gms:play-services-location:$versions.playLocation"
    implementation "com.google.maps.android:android-maps-utils:$versions.mapUtils"

    // Logging
    implementation "com.jakewharton.timber:timber:$versions.timber"
    implementation "org.slf4j:slf4j-api:$versions.slf4j"
    implementation "com.github.tony19:logback-android:$versions.logback"

    // Databases
    implementation "com.github.sevar83:android-spatialite:$versions.spatialite"

    // Archives
    implementation "org.zeroturnaround:zt-zip:$versions.ztZip"

    // Dialogs
    implementation "com.afollestad.material-dialogs:core:$versions.materialDialogs"
    implementation "com.afollestad.material-dialogs:datetime:$versions.materialDialogs"
    implementation "com.afollestad.material-dialogs:lifecycle:$versions.materialDialogs"

    // Permissions
    implementation "com.karumi:dexter:$versions.dexter"
    implementation("dev.doubledot.doki:library:$versions.doki") {
        transitive = true
    }

    // JSON
    implementation "com.squareup.moshi:moshi:$versions.moshi"
    implementation "com.squareup.moshi:moshi-kotlin:$versions.moshi"

    // Firebase
    implementation "com.google.firebase:firebase-analytics:$firebase_versions.analytics"
    implementation "com.google.firebase:firebase-crashlytics:$firebase_versions.crashlytics"
    implementation "com.google.firebase:firebase-perf:$firebase_versions.performance"

    // Payments
    implementation "com.android.billingclient:billing:$versions.billing"
    implementation "com.android.billingclient:billing-ktx:$versions.billing"

    // Testing
    testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
    testImplementation "junit:junit:$test_version.junit"
    testImplementation "androidx.test:core:$test_version.androidTest"
    testImplementation "androidx.test:runner:$test_version.androidTest"

Why is this build failing? Is it Kotlin's 1.4.0 fault, or is there something wrong with dependencies? Can this issue be solved without reverting to previous Kotlin version?

Energumen answered 20/8, 2020 at 15:57 Comment(5)
if you use 1.3.72 then?Aldrich
i don't know why this got downvoted so i upvoted you: we're also having issues with 1.4 and just staying on 1.3 forever isn't going to work. for your case, try doing a ./gradlew clean - we'll post our fix when we figure it outPrevocalic
When using 1.3.72 everything works fine. I've done clean rebuilds, and nothing seems to help.Energumen
Here is the issue: github.com/firebase/firebase-android-sdk/issues/1888Diatessaron
We're seeing this issue too, staying to 1.3 is not really a solution, do you have any updates?Spontaneous
S
3

Not the best solution but at least for me, it worked: If you are building from command line using the Gradle wrapper:

./gradlew clean assembleDebug -Pdisable-performance-plugin

If you run your project from Android Studio:

enter image description here

Then you are able to run your project using Kotlin 1.4 until they fix the issue.

As a side effect, build times seem to be improved.

Spontaneous answered 27/8, 2020 at 13:57 Comment(0)
U
3

It seems to be an AGP issue which is going to be addressed in version 4.1.0. More details are here - https://issuetracker.google.com/issues/165535092

As a workaround would suggest to apply 4.1.0-rc02 Update

classpath 'com.android.tools.build:gradle:4.1.0-rc02'
Uno answered 17/9, 2020 at 3:17 Comment(2)
I changed import with this but I'm getting an error; This version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot open this project, please retry with version 4.1 or newer.Outage
Yeah, you should bump Android Studio as well @CaferMertCeyhan. It was Android Studio 4.1 RC 2 at the moment of writing the answer. At the moment it's AS 4.1 (release channel)Uno

© 2022 - 2024 — McMap. All rights reserved.