我有一个项目A和一个项目B。项目A是其他项目也使用的核心项目。这是他的build.gradle依赖项:

dependencies {
    compile 'com.android.support:support-v4:22.0.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile('org.simpleframework:simple-xml:2.7.1') {
        //http://stackoverflow.com/a/19455878/1423773
        exclude module: 'stax'
        exclude module: 'stax-api'
        exclude module: 'xpp3'
    }

    compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'org.apache.httpcomponents:httpmime:4.5'
}


由于这是一个具有最新依赖项版本的核心项目,因此很有意义。项目B使用的依赖项使用httpcore-4.2.4.jar,如果我不将核心项目build.gradle修改为以下内容,它将抛出重复的依赖项错误:

dependencies {
    ...
//    compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'org.apache.httpcomponents:httpcore:4.2.4'
    compile('org.apache.httpcomponents:httpmime:4.5') {
        exclude module: 'httpcore'
    }
}


这是我要避免的事情,因为我不想更改我的核心项目build.gradle
对于这种情况最好的解决方案是什么?如果我将.jar从其他依赖项中删除/排除会起作用吗?如果是这样,我如何将其删除?我试过exclude module/group但没有任何运气。我当时想的是Chapter 56. Multi-project Builds(我还没有读过),但我想避免在每个非核心项目的核心项目中使用不同的gradle.build文件。

我的项目B冲突依赖性:co.realtime:messaging-android:2.1.40

谢谢。

最佳答案

我发现了,它一直在我面前...

因此,在项目B中,我只需要遵循与核心项目中相同的方法即可:

compile (project(':submodules:MyCoreProject')){
        exclude module: 'httpcore'
        //co.realtime:messaging-android:2.1.40
        //uses 'org.apache.httpcomponents:httpcore:4.2.4'
}


现在是我的核心项目:

dependencies {
    compile 'com.android.support:support-v4:22.0.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile('org.simpleframework:simple-xml:2.7.1') {
        //http://stackoverflow.com/a/19455878/1423773
        exclude module: 'stax'
        exclude module: 'stax-api'
        exclude module: 'xpp3'
    }

    compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'org.apache.httpcomponents:httpmime:4.5'
}

关于android - Gradle依赖排除,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31009965/

10-11 22:27
查看更多