Intellij:避免 'Multiple Dex Files Defined'
Intellij: Avoiding 'Multiple Dex Files Defined'
问题:
到目前为止,我一直在使用 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')
}
当导入外部 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
}
问题:
到目前为止,我一直在使用 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')
}
当导入外部 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
}