Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple dex files define Landroid/support/design/widget/CoordinatorLayout$LayoutParams

I'm getting Multiple dex files define error in my project.

I'm using these two tags in build.gradle as well

dexOptions {
    preDexLibraries = false
}
defaultConfig {
    multiDexEnabled true

}

but still getting this error.

   Information:Gradle tasks [:app:assembleDebug]
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/design/widget/CoordinatorLayout$LayoutParams;
Error:com.android.dex.DexException: Multiple dex files define Landroid/support/design/widget/CoordinatorLayout$LayoutParams;
Error:  at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
Error:  at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
Error:  at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
Error:  at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Error:  at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
Error:  at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
Error:  at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
Error:  at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
Error:  at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error:  at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
Error:  at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
Error:  at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Landroid/support/design/widget/CoordinatorLayout$LayoutParams;
like image 675
Nisar Ahmad Avatar asked Feb 28 '18 11:02

Nisar Ahmad


2 Answers

Update the library versions to 27.1.0 solve the isssue for me.

compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:mediarouter-v7:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:support-v13:26.1.0'
compile 'com.android.support:support-v4:26.1.0'

To:

compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.android.support:design:27.1.0'
compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.android.support:mediarouter-v7:27.1.0'
compile 'com.android.support:recyclerview-v7:27.1.0'
compile 'com.android.support:cardview-v7:27.1.0'
compile 'com.android.support:support-v13:27.1.0'
compile 'com.android.support:support-v4:27.1.0'
like image 127
Rafa0809 Avatar answered Nov 13 '22 16:11

Rafa0809


in build.gradle file enable multidex and add the multidex library as a dependency,as shown:

android {
defaultConfig {
    ...
    minSdkVersion 15 
    targetSdkVersion 26
    multiDexEnabled true
}
...
}

dependencies {
  compile 'com.android.support:multidex:1.0.3'
}

By default on the new support library versions when you add "multiDexEnabled = true" , its dependency is being added automatically , but for some reason if you want to support older support versions you have to include the dependency manually for it to compile.

This will remove Multiple dex files define Landroid/support/v13/view/DragAndDropPermissionsCompat error and other 16 errors along with it.

Consider the link : https://developer.android.com/studio/build/multidex for detailed information.

like image 2
MGupt Avatar answered Nov 13 '22 15:11

MGupt