I'm getting this error when trying to build my project in Android Studio (I'm trying to migrate from Eclipse):
Output:
UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
after googling and checking stackoverflow the most likely cause is duplicate library references.
I have a number of libraries in my project such as Facebook SDK, SlidingMenu, etc. that required android-support-v4.jar, so I copied that into my main project's /libs folder and subsequently removed it from all the other projects libs folder. Then I went to "Open Module Settings" and added the support-v4 as a library dependency for the libraries that needed it (e.g. Facebook SDK).
Then clean project -> run but I'm still getting this multiple dex files error
running gradle -q dependencies
shows:
+--- project :facebook-android-sdk-3.5.1:facebook
| \--- com.android.support:support-v4:+ -> 19.1.0
+--- project :SlidingMenu:library
| \--- com.android.support:support-v4:+ -> 19.1.0
Is that okay? If I remove this library dependency in the Module Settings then I will get even more errors while trying to compile my project
By adding this library, your app can manage the access of additional DEX files. In other words, if you are having more than 64K methods, then you will be having more than one DEX file and these DEX files will be managed by using this multidex support library. Then, modify the module-level build.
This number represents the total number of references that can be invoked by the code within a single Dalvik Executable (DEX) bytecode file. This page explains how to move past this limitation by enabling an app configuration known as multidex, which allows your app to build and read multiple DEX files.
dex file can have 65,536 methods(references) so if the number of references exceeds 65,536, you go with multidex.
Android applications by default have SingleDex support which limits your application to have only 65536 methods(references). So multidexEnabled = true simply means that now you can write more than 65536 methods(references) in your application.
In your build.gradle file try adding the following block inside your android block.
dexOptions {
preDexLibraries = false
}
Just a Clean Build worked for me , Just do this in Android Studio:
Got to Build > Clean Project
See image for reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With