Java Intellij:避免';定义了多个Dex文件';

Java Intellij:避免';定义了多个Dex文件';,java,android,intellij-idea,gradle,dependency-management,Java,Android,Intellij Idea,Gradle,Dependency Management,问题: 到目前为止,我一直在使用Gradle来处理我的所有依赖关系,它似乎可以处理其他Gradle模块之间的任何重复依赖关系。然而,当jar中存在重复依赖项时,情况似乎并非如此 问题: 考虑到我可以控制进入jar的内容,使用Gradle处理这些依赖冲突的最佳实践是什么: 不要在jar中包含任何外部依赖项,使用build.gradle将它们包含在项目本身中 在jar中包含所有外部依赖项,通过从项目build.gradle中删除重复项来删除重复项。(注意:这似乎不可扩展,例如,如果jar之间存在重复

问题:

到目前为止,我一直在使用Gradle来处理我的所有依赖关系,它似乎可以处理其他Gradle模块之间的任何重复依赖关系。然而,当jar中存在重复依赖项时,情况似乎并非如此

问题:

考虑到我可以控制进入jar的内容,使用Gradle处理这些依赖冲突的最佳实践是什么:

  • 不要在jar中包含任何外部依赖项,使用
    build.gradle将它们包含在项目本身中

  • 在jar中包含所有外部依赖项,通过从项目
    build.gradle
    中删除重复项来删除重复项。(注意:这似乎不可扩展,例如,如果jar之间存在重复项。)

  • 更好的(希望能自动处理)

  • 编辑:
    build.gradle
    文件:

    apply plugin: 'com.android.application'
    
    android {
        signingConfigs {
            release { ... }
            debug { ... }
        }
        compileSdkVersion 19
        buildToolsVersion '19.1.0'
        defaultConfig { ... }
        buildTypes {
            release { ... }
            debug { ... }
        } 
        sourceSets {
            instrumentTest.setRoot('tests')
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:support-v4:20.0.0'
        compile project(':jarModule')
    }
    

    导入与本地应用程序具有依赖关系的外部
    jar
    时,可以执行两项操作:

    将您的
    jar
    依赖项转换为渐变依赖项并排除该依赖项 例如:

    testCompile('org.robospock:robospock:0.5.0')  {
         exclude module: "groovy-all" // <-- excludes groovy from robo spock
    }
    

    你为什么用罐子?发布你的
    build.gradle
    @JaredBurrows基本上,我在Intellij中有一个Java项目,我将其构建到一个jar中,然后将jar作为模块导入Android Studio。该模块包含在build.gradle中,使用
    编译项目(':jarModule')
    发布您的所有
    build.gradle
    @JaredBurrows好的发布了。我们都需要查看您的“jarModule”
    build.gradle
    。我们还能如何帮助确定什么是冲突的?
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:support-v4:20.0.0'
        compile project(':jarModule')
        // compile 'com.google.code.gson:gson:2.3.1' // <-- removed
    }