繁体   English   中英

Intellij:避免“已定义多个Dex文件”

[英]Intellij: Avoiding 'Multiple Dex Files Defined'

问题:

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

题:

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

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

  2. 将所有外部依赖项包含在jar中,通过从项目build.gradle其删除,以消除重复build.gradle 注意:这似乎不可扩展,例如,如果罐子本身之间存在重复项。)

  3. 更好的东西(希望可以自动处理)

编辑: 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')
}

导入具有本地应用程序中也具有依赖性的外部jars ,您可以执行以下两项操作:

jar依赖项转换为Gradle依赖项,并排除依赖项

例如:

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

要么

在您的应用中删除本地依赖项,并依靠.jar依赖项

例如,对于您与Gson的情况:

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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM