Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 965
Anil Ugale Avatar asked May 17 '18 08:05

Anil Ugale


Video Answer


2 Answers

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.

like image 70
artnest Avatar answered Oct 02 '22 05:10

artnest


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" 
like image 42
amlwin Avatar answered Oct 02 '22 07:10

amlwin