Execution failed for task':app:dexDebug'

2019-06-28 06:31发布

This is my build.gradle file.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

defaultConfig {
    applicationId "com.squad.run"
    minSdkVersion 10
    targetSdkVersion 19
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
}

dependencies {
    compile project(':facebookSDK')
    compile project(':library')
    compile project(':progressHUD_Squadrun')
    compile project(':pullToRefreshLibrary_Squadrun')
    compile project(':slidingMenuLibrary_SquadRun')
    compile project(':viewPagerIndicator_Squadrun')
    compile 'com.android.support:support-v4:20.0.0'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.google.android.gms:play-services:+'
    compile ('com.android.support:appcompat-v7:+')
    compile 'com.squareup.retrofit:retrofit:1.6.1'
    compile 'com.squareup.picasso:picasso:2.3.4'
    compile 'org.apache.httpcomponents:httpmime:4.2.3'
    compile 'com.squareup.okhttp:okhttp:1.5.4'
    compile 'oauth.signpost:signpost-commonshttp4:1.2.1.2'
    compile 'org.twitter4j:twitter4j-core:4.0.1'
    compile files('libs/FlurryAnalytics-4.1.0.jar')
    compile files('libs/signpost-core-1.2.1.2.jar')
}
configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-v4:20.+'
        force 'com.android.support:appcompat-v7:20.+'

    }
}

The error i am getting is:

Error:Execution failed for task ':splashActivity:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:\Program Files (x86)\Android\android-studio\sdk\build-tools\android-4.4W\dx.bat --dex --num-threads=4 --output C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\dex\debug C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\classes\debug C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\dependency-cache\debug C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\bolts-a453c67e9fbcb8b2df66a807f07597b525fb5510.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\classes-0995d8d31789d692af9771bc79994535d0e9a11a.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\classes-82cb9af78535d442f7254cfacf8e5581ec7f198f.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\classes-89329bbc6b94e906573340292603af66cd64cb4e.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\classes-9ae85e5dda6ac87e5fea9eef10579046127f64ec.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\classes-9e0a0926f1bf743e60be55256fecd3044b3fb3a3.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\classes-db2d588e091d9f00bcf352380664bcea0550c2db.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\classes-e47e7de01366f4c982a9621611d5b51065b46b4c.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\classes-e5a017caf8243b588c7668187fffdb443d97efa3.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\classes-edb407f320a9d16ab253cdece9f7de0c9849dee4.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\commons-codec-1.3-744613167a0498e87bddefe11d9715a6a77d814c.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\FlurryAnalytics-4.1.0-3e22e246a0fe5113ab006ccb53afd17722686ba5.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\gson-2.2.4-09611e369a15fd5115f540570c544bb969143206.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\httpcore-4.2.2-6d4bd90cc9c601d0cb426d3b6f13e630051be2ab.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\httpmime-4.2.3-114981e5b1ca0603b19d0c173b834fb4f36dc7b3.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\internal_impl-20.0.0-4d4a1b5904ea596662a1d75090720f4a71528c3c.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\nineoldandroids-2.4.0-c15291f1a5d73b9ed06c48806c179c177c2c9326.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\okhttp-1.5.4-1d4d39f1325704b750ebee0aa6d60f57eca82163.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\picasso-2.3.4-825d3c0d5a3645c39e62902f73d0b2e5dbc2f221.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\retrofit-1.6.1-7a2bce6e9943b126155a7444b7c6abd4fb80e2cb.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\signpost-commonshttp4-1.2.1.2-457264617652896d5137504440ed9fd54533c9c3.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\signpost-core-1.2.1.2-114c53ef70d732d013001aa342ae8e81962fb26c.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\signpost-core-1.2.1.2-4824b5b475ceb675ff2174e6d7caf3756ba2af4a.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\support-annotations-20.0.0-79e42da7c2657068d681cf877be8b4cc06e3cb7a.jar C:\Users\Jonty\Documents\Studio\squadrunapp_duplicate\splashActivity\build\intermediates\pre-dexed\debug\twitter4j-core-4.0.1-1e2ff826eb1ee2df67db1f0634f99a7220b788a7.jar
Error Code:
    2
Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lcom/google/gdata/util/common/base/Escaper;
        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)

From what i read till now i get the error is due to conflict between V4 library and V7 library.But how can i resolve it.I also tried excluding the V4 library but still no luck. The projects i am importing are also using the V4 library and have V4 library in their dependency.

dependencies {
     compile 'com.android.support:support-v4:20.0.0'
}

Any help will be appreciated. Thanks.

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-06-28 07:22

It's not a clash between v4-support and v7-appcompat, though it's true that if you have the latter you don't need the former. The duplicate class it's complaining about doesn't come from there anyway. You should be able to find out if in Android Studio you go to Navigate > Class and type in Escaper, you should be able to see the multiple libraries that define it.

I made a sample project where I included just the includes from your project that referenced downloadable dependencies from jcenter, and I can see that this library pulls in a copy of it:

compile 'oauth.signpost:signpost-commonshttp4:1.2.1.2'

though it's coming in via a signpost-core-1.2.1.2.jar file. If I look at the pom file for that library (http://search.maven.org/remotecontent?filepath=oauth/signpost/signpost-commonshttp4/1.2.1.2/signpost-commonshttp4-1.2.1.2.pom) I can see that it's already pulling in signpost-core as a transitive dependency:

<dependencies>
    <dependency>
        <groupId>oauth.signpost</groupId>
        <artifactId>signpost-core</artifactId>
        <version>${project.version}</version>
        <scope>compile</scope>
    </dependency>

Later on in your build file, you include this as an explicit jar file, which is where the redundancy is coming from. By including signpost-commonshttp, it should be unnecessary to include signpost-core.

signpost shouldn't be redistributing these files at all, by the way -- this looks like a packaging error in the library.

Note that the build system is often able to avoid problems with redundant files if everything uses downloadable libraries instead of explicit jar files. Had you included signpost-core via this:

compile 'oauth.signpost:signpost-core:1.2.1.2'

instead of including its jar file directly, you wouldn't have seen this problem.

Once you clear up this problem you'll run into other issues. httpmime clashes with versions of those files provided by Android, and this library may be redundant, but you can cross that bridge next.

查看更多
登录 后发表回答