"Unable to combine dex" when using room

I am trying to add a β€œroom” to my project.

When I try to create a project, I get an error message:

Error: execution completed for task ': app: transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: cannot dex merge

What I have already done:

  • Clean / Restore Project
  • I added "multiDexEnabled true" to defaultConfig {}. Then I get the error message:

    Error: execution completed for task ': app: transformClassesWithMultidexlistForDebug'. java.io.IOException: cannot write [C: \ Users \ user1 \ AndroidStudioProjects \ git \ mobile \ app \ build \ intermediates \ multi-dex \ debug \ componentClasses.jar] (Cannot read [C: \ Users \ user1. gradle \ caches \ transforms-1 \ files-1.1 \ support-core-utils-26.1.0.aar \ a6c34f6784b0b6bc5c2fc7a7815426da \ jars \ classes.jar (;;;;;; **. class)] (Duplicate zip entry [classes .jar: android / support / v4 / content / PermissionChecker $ PermissionResult.class]))

If I remove the β€œroom” from my project, it will be built without errors.

I am using Android Studio 3, gradle build tools 3.0.0.

This is my build.gradle:

apply plugin: 'com.android.application' apply plugin: 'me.tatarka.retrolambda' buildscript { repositories { mavenCentral() } dependencies { classpath 'me.tatarka:gradle-retrolambda:3.2.5' } } repositories { mavenCentral() } android { compileSdkVersion 23 buildToolsVersion '26.0.2' defaultConfig { applicationId "trsnet.gtp2.com" minSdkVersion 17 targetSdkVersion 23 multiDexEnabled true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { compile files('libs/commons-codec-1.9.jar') compile files('libs/ksoap2-android-assembly-3.0.0-jar-with- dependencies.jar') compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:cardview-v7:23.2.1' compile 'com.android.support:appcompat-v7:23.2.1' compile 'com.android.support:design:23.2.1' compile 'com.android.support.constraint:constraint-layout:+' compile 'io.reactivex:rxandroid:1.2.1' compile 'io.reactivex:rxjava:1.1.6' compile 'com.jakewharton.rxbinding:rxbinding:0.4.0' implementation 'android.arch.persistence.room:runtime:1.0.0' annotationProcessor 'android.arch.persistence.room:compiler:1.0.0' } 
+6
source share
2 answers

I had this problem too, and it took me a while to resolve, but I finally understood. ROOM uses some support libraries-v4, so you get an error that there are duplicate entries in zip. In my situation, ROOM uses components from an earlier version than what I need. So, what worked for me ( found here ) adds the following to the root level of the Gradle file:

 configurations { all*.exclude group: 'com.android.support', module: 'support-v4' } 

What I found is that it forbids libraries to include any support components-v4, but then you need to manually enable the necessary components for ROOM and all that you may need. If you need to determine exactly which libraries are duplicated, you can follow these instructions to view each library and its dependencies.

A bit unrelated note: Starting with Gradle 3.0 using the compile configuration is deprecated and needs to be replaced with implementation or api , you can find a nice explanation here .

+3
source

Change from this

 implementation 'android.arch.persistence.room:runtime:1.0.0-alpha1'; 

in

 implementation 'android.arch.persistence.room:runtime:1.0.0'; 
0
source

Source: https://habr.com/ru/post/1273216/


All Articles