2

So, I'm trying to migrate my Eclipse ADT project into Android Studio. I am using the appcompat_v7 project as a library project in eclipse. I followed the instructions on the Android Development site, but I am still receiving this error:

Error:Execution failed for task :PaWPal:dexDebug.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Users/godswood/Desktop/adt-bundle-mac-x86_64-20140321/sdk/build-tools/19.1.0/dx --dex --num-threads=4 --output /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/dex/debug /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/classes/debug /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/dependency-cache/debug /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/android-support-v13-7e8441dbe126e0c6ef27b0769fe1a7b51230f497.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/android-support-v4-435683bcc81493f96c2a6911d0f2132f9185a3c8.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/android-support-v7-appcompat-ce23957a305e187b582a49f3d7389771481d29a0.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/classes-0df1e7b55f7a1cf804d7c324e4d8e5350156c424.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/commons-lang3-3.3.2-414f8e20d93f4cd78deef61257feb20e410dc32e.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/joda-time-2.3-e2f8ddd39c18a5b5f810a870e98c34e25539e6e9.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/joda-time-2.3-javadoc-2b8389d156c40d0540abb1e521b4be4ba90b89b7.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/joda-time-2.3-sources-ee3d5e4a6e2aceeeee41f9ab558b6a1430285670.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/Parse-1.5.1-b7ce0ef98d2f79d618c5421f63a4845519bd4ced.jar
  Error Code:
    2
  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)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
        at com.android.dx.command.dexer.Main.run(Main.java:230)
        at com.android.dx.command.dexer.Main.main(Main.java:199)
        at com.android.dx.command.Main.main(Main.java:103)

And my Gradle File looks like this:

apply plugin: 'com.android.application'
configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':appcompat_v7')
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

If you have any ideas, I'd love to hear them. I know there are a lot of similar questions on here, but none of the solutions worked for me (sad face).

1
  • That dex error comes from referencing a jar/library multiple times. Probably an scenario like this: project A references project B and the support library, while project B also references the Support library. Haven't checked your question thoroughly but wanted to give my 2 cents Jul 15, 2014 at 21:58

1 Answer 1

1

In Android Studio, you don't need to include the appcompat library as a library project the way you do in Eclipse. Instead, add this to the dependencies block of your module's build file:

 compile 'com.android.support:appcompat-v7:XXXX.+'

where XXXX is your compileSdkVersion.

Also, I suspect you have a copy of the v4 support library jar in your libs folder (which where you're getting its classes multiple-defined). If you include the appcompat lib as you do above, you don't need to include support-v4 at all; appcompat depends on it, and the build system will do the right thing. So go ahead and remove that jar from your libs folder.

1
  • Maybe because I don't know what you mean by my module's build file, but this didn't quite seem to work. Deleting the jar caused a lot of errors, so I put it back. Jul 15, 2014 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.