添加StikkyHeader android项目后,多个dex文件定义了Landroid / support / annotation / AnimRes

时间:2015-03-13 12:55:52

标签: android gradle

在我的gradle文件中添加'com.github.carlonzo.stikkyheader:core:0.0.2-SNAPSHOT'库后,我在构建时遇到错误:

com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
        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)

这是我的gradle.build文件:

buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://repo1.maven.org/maven2' }
        maven { url 'http://download.crashlytics.com/maven' }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'

    }
}
apply plugin: "eclipse"
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
repositories {
    mavenCentral()
    maven { url 'http://repo1.maven.org/maven2' }
    maven { url 'http://download.crashlytics.com/maven' }
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
android {

    compileSdkVersion 21
    buildToolsVersion "19.1.0"

    dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
        compile project(":libraries:google-play-services-lib")
        compile project(":libraries:pager-indicator-lib")
        compile project(":libraries:apphance-library-1.9.11")
        compile project(":libraries:dialog-manager-lib")
        compile 'com.crashlytics.android:crashlytics:1.+'

    }

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
    }

    signingConfigs {
        release {
            storeFile file(RELEASE_KEYSTORE_FILE)
            storePassword System.getenv("PASSWORD_KEYSTORE")
            keyAlias System.getenv("ALIAS_KEYSTORE_JB")
            keyPassword System.getenv("PASSWORD_KEYSTORE")
        }

        debug {
            storeFile file(DEBUG_KEYSTORE_FILE_LOCAL)
        }

        beta {
            storeFile file(DEBUG_KEYSTORE_FILE_LOCAL)
        }

    }

    buildTypes {
        debug {
            debuggable true
            signingConfig android.signingConfigs.debug
            applicationIdSuffix ".debug"
        }
        release {
            signingConfig signingConfigs.release
        }

        beta {
            debuggable true
            signingConfig android.signingConfigs.debug
            applicationIdSuffix ".beta"
        }
    }

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

        release {
            res.srcDirs = ['res_release']
        }

        beta {
            res.srcDirs = ['res_beta']
        }

        instrumentTest.setRoot('test')
        instrumentTest {
            java.srcDirs = ['test']
        }
    }

    lintOptions {
        abortOnError false
    }
}
task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}
dependencies {
//    compile 'com.android.support:support-annotations:20.0.0'
    compile 'com.mixpanel.android:mixpanel-android:4.5.2'
    compile 'com.android.support:multidex:1.0.0'
    compile ('com.facebook.android:facebook-android-sdk:3.22.0')
            {
                    exclude module: 'support-v4'
            }

    compile ('com.github.carlonzo.stikkyheader:core:0.0.2-SNAPSHOT')
            {
                exclude module: 'support-v4'
            }
}

有关如何修复它的任何想法?感谢

1 个答案:

答案 0 :(得分:1)

这是因为每个依赖项都有自己的依赖关系到支持库(或者你的情况下是support.annotation)。 我的建议是将exclude module: 'support-v4'替换为exclude group: 'com.android.support'。我建议你将组com.android.support排除在你添加的每个依赖项之外,并声明你自己对支持库的依赖