这是我的build.gradle文件。

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

    }
}

我得到的错误是:
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)

从我读到现在,我得到的错误是由于v4库和v7库之间的冲突。但我如何解决它。我也尝试排除v4库,但仍然没有运气。
我正在导入的项目也在使用v4库,并且在它们的依赖项中有v4库。
dependencies {
     compile 'com.android.support:support-v4:20.0.0'
}

任何帮助都将不胜感激。
谢谢。

最佳答案

v4支持和v7 appcompat之间并不是冲突,但如果你有后者,你就不需要前者。它所抱怨的重复类无论如何也不是从那里来的。您应该能够发现在android studio中,如果您转到navigate>class并键入escaper,您应该能够看到定义它的多个库。
我制作了一个示例项目,其中只包括引用了jcenter可下载依赖项的项目中的includes,我可以看到这个库提取了它的一个副本:

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

尽管它是通过signpost-core-1.2.1.2.jar文件传入的。如果我查看该库的pom文件(http://search.maven.org/remotecontent?filepath=oauth/signpost/signpost-commonshttp4/1.2.1.2/signpost-commonshttp4-1.2.1.2.pom),我可以看到它已经将signpost core作为一个可传递的依赖项引入:
<dependencies>
    <dependency>
        <groupId>oauth.signpost</groupId>
        <artifactId>signpost-core</artifactId>
        <version>${project.version}</version>
        <scope>compile</scope>
    </dependency>

稍后在构建文件中,将其作为显式jar文件包含,这是冗余的来源。通过包含signpostcommonhttp,应该不必包含signpost core。
顺便说一下,signpost根本不应该重新分发这些文件——这看起来像是库中的打包错误。
注意,如果所有东西都使用可下载库而不是显式jar文件,那么构建系统通常能够避免冗余文件的问题。你有没有把路标核心放在这里:
compile 'oauth.signpost:signpost-core:1.2.1.2'

与其直接包含它的jar文件,您不会看到这个问题。
一旦你解决了这个问题,你就会遇到其他问题。httpime与android提供的那些文件的版本冲突,这个库可能是多余的,但是您可以下一步跨过那座桥。

08-26 02:58