Error while merging dex Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
Asked Answered
R

9

48

Error when merging the dex

following are the dependencies.

ext {
    anko_version='0.10.5'
    support_lib='1.0.0-alpha1'
    room_lib = "1.1.0"
}
dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation "androidx.cardview:cardview:$support_lib"
    implementation "com.google.android.material:material:$support_lib"
    implementation "androidx.appcompat:appcompat:$support_lib"
    implementation "org.jetbrains.anko:anko:$anko_version"
    implementation "androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1"
    implementation "android.arch.persistence.room:runtime:$room_lib"
    annotationProcessor "android.arch.persistence.room:compiler:$room_lib"
}

error

  • What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

    com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: /app/build/intermediates/transforms/dexBuilder/debug/0.jar, Program type already present: android.support.v4.os.ResultReceiver$1

Rightist answered 17/5, 2018 at 8:51 Comment(3)
I am getting the same error. Did you find anything?Mencher
Same here. Seems like some libs are not compatible with androidx for now. I'm using anko and android-dialogs and both of them are not working - even when setting enableJetifier:-(Seraph
Please refer to this answer. This really worked for me. Multidex issue with FlutterPiercing
D
93

It's because you messed up the dependencies. You have to either fully migrate to AndroidX dependencies or stay on Support library ones. Thus, instead of

implementation "android.arch.persistence.room:runtime:$room_lib"
annotationProcessor "android.arch.persistence.room:compiler:$room_lib"

use

implementation "androidx.room:room-runtime:2.0.0-alpha1"
annotationProcessor "androidx.room:room-compiler:2.0.0-alpha1"

Also be sure to check your gradle.properties project file to contain

android.useAndroidX=true
android.enableJetifier=true

Jetifier helps libraries, which depend on old Support packages, to use the new AndroidX ones.

What is Jetifier? It's an Android Gradle Plugin task (now can also be used as a standalone tool) which is invoked during build phase. AGP (>= 3.2.0) does automatically apply dependency translation which rewrites bytecode and resources of JAR and AAR dependencies (and transitive dependencies) to reference the new androidx-packaged classes and artifacts. You can also use it as a standalone tool to individually migrate a library.

Jetifier Official Documentation

The standalone Jetifier tool migrates support-library-dependent libraries to rely on the equivalent AndroidX packages instead. The tool lets you migrate an individual library directly, instead of using the Android gradle plugin bundled with Android Studio.

P. S. I didn't test if Anko works with AndroidX dependencies, but if it doesn't even though those properties in your gradle.properties are enabled, you have no other choices, but fallback to using Support libraries as for now.

Demijohn answered 22/5, 2018 at 16:16 Comment(4)
Thanks for your help I has missing gradle.properties settingRightist
i had no idea why enableJetifier should work until you explained it. thanksWeald
+1 for the second sentence. Just a tiny addition though: this isn't just related to the dependencies like android.arch.persistence.room:..., but also any dependencies that use those. enableJetifier is effectively a shortcut that forces use of the jetpack dependencies over support packages, which is useful for dependencies that haven't migrated yet.Sightread
Halellujah. I thaught I'd have to deal with this dependency duplication nightmare on every project. Thanks for the explanation. I've lost so much time before hitting this answer.Present
I
18

add following lines on gradle.properties

android.useAndroidX=true
android.enableJetifier=true

and change your room dependencies on build.gradle(moudel:app)

implementation "androidx.room:room-runtime:2.0.0-alpha1"
annotationProcessor "androidx.room:room-compiler:2.0.0-alpha1"
Incisor answered 28/6, 2018 at 11:5 Comment(1)
glad to hear @Po10cioIncisor
A
9

Migrate the dependencies to androidx dependencies. And in gradle.properties add the below lines (If not created already, create the file in root folder).

android.useAndroidX=true
android.enableJetifier=true

Hope this helps.

Aegeus answered 3/12, 2018 at 12:9 Comment(0)
S
3

This is what worked for me was Refactor -> Migrate to AndroidX option in Android Studio. This seemed to resolve any things I may have missed when trying to do the AndroidX migration one dependency at a time. https://developer.android.com/jetpack/androidx/migrate

Superaltar answered 31/10, 2018 at 1:9 Comment(0)
G
2

I had the same problem.

Do not mix dependencies styles(androidx and com.android.support) in your project.

In your code try to replace

implementation "androidx.appcompat:appcompat:$support_lib"

with

implementation "com.android.support:appcompat-v7:$version_of_support_library"

A full list of dependencies migration you can find here .

I should use old style dependency because I needed WorkManager and according to official documentation WorkManager currently without AndroidX dependencies.

WorkManager classes are already in the androidx.work package, but currently depend on Support Library 27.1, and associated Arch component versions. Version of WorkManager with AndroidX dependencies will be released in the future.

Guide answered 6/6, 2018 at 10:26 Comment(0)
S
2

What worked for me was Refactor -> Migrate to AndroidX option in Android Studio. This seemed to resolve any things I may have missed when trying to do the AndroidX migration one dependency at a time. https://developer.android.com/jetpack/androidx/migrate

Superaltar answered 31/10, 2018 at 1:7 Comment(0)
A
2

Check the package which clashes with the com.android.support and exclude it from that package. For me, I was using androidx packages and also FCM, where there was a clash. So, this fixed for me:

implementation ('com.google.firebase:firebase-core:16.0.4') {
    exclude group: 'com.android.support'
}
Abject answered 5/12, 2018 at 0:12 Comment(0)
O
2

Add Following plugins

ionic cordova plugin add cordova-plugin-androidx
ionic cordova plugin add cordova-plugin-androidx-adapter

Add these two lines in platforms/android/gradle.properties file

android.useAndroidX=true
android.enableJetifier=true

Here is a video as well: https://youtu.be/0RaJlGipYHc

Opsonize answered 15/5, 2020 at 21:47 Comment(0)
H
0

for my instance i had upgraded from implementation 'com.github.bumptech.glide:glide:4.0.0 to implementation 'com.github.bumptech.glide:glide:4.7.1'

Hames answered 31/5, 2018 at 9:31 Comment(2)
do you mean that glide 4.7.1 can be used with androidx? As far as I know it does not support androidx yetOdum
@Odum I guess it has the support libs it needs bundled in it. So using androidX will cause Mix.Transportation

© 2022 - 2024 — McMap. All rights reserved.