swimmingtomars swimmingtomars - 1 year ago 202
Android Question

Android Studio Gradle Error: Multiple dex files define

I'm getting this error when trying to build my project in Android Studio (I'm trying to migrate from Eclipse):


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

gradle -q dependencies

+--- 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

Answer Source

In your build.gradle file try adding the following block inside your android block.

dexOptions {
    preDexLibraries = false
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download