正如标题所说,正在定义多个dex文件,我一直在四处寻找如何解决这个问题,所以我决定联系社区,让故事简短,我和#39;我将这个遗留项目的gradle构建系统从gradle 0+更新为gradle 3+,我设法重构了常见配置,例如调味,依赖(从编译到api /实现),(你把它命名为..) ,直到我偶然发现这个dex问题,我想到的第一件事是在Using gradle to find dependency tree的帮助下打破依赖关系,但遗憾的是它在gradlew命令上花费了太多时间并且仍然以gradlew结束问题(无法执行AndroidSdk的东西),所以我退了一步(尽量减少我需要的时间)并做了这个......(玩赔率)
dependencies {
api (project(':<omitted project name>')) {
exclude group: 'org.apache.commons', module: 'logging'
}
api (project(':<omitted project name>')) {
exclude group: 'org.apache.commons', module: 'logging'
}
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.android.support:support-v4:25.4.0'
implementation 'com.android.support:design:23.1.0'
implementation ('com.google.code.gson:gson:2.3'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.squareup.picasso:picasso:2.5.2'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.squareup.okhttp:okhttp:2.4.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('org.bitbucket.b_c:jose4j:0.5.2'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'commons-io',name:'commons-io',version: '2.0.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'com.jcraft', name: 'jsch', version: '0.1.44-1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.android.support:design:23.1.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.android.support:appcompat-v7:24.2.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.facebook.android:facebook-android-sdk:4.10.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-gcm:9.0.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-auth:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.github.PhilJay:MPAndroidChart:v3.0.2'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'org.apache.commons', name: 'commons-compress', version: '1.3') {
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'org.apache.commons', name: 'commons-vfs2', version: '2.2') {
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('io.socket:socket.io-client:1.0.0') {
// excluding org.json which is provided by Android
exclude group: 'org.json', module: 'json'
exclude group: 'org.apache.commons', module: 'logging'
}
api fileTree(dir: 'libs', include: ['*.jar'])
api files('libs/nfc7003.jar')
api files('libs/minilcd7003.jar')
api files('libs/Scan7003.jar')
api files('libs/UserInterface.jar')
api files('libs/printer7003.jar')
}
我无法弄清楚上面列表中的依赖关系是否存在日志框架的这个传递问题,我对它们进行了排除,但仍然没有运气..
只是提到背后的原因:我需要Android Studio 3的高级分析,并且必须使用最新的gradle(4 +)/构建工具(3+)来引导我。
请提前帮助我,谢谢...
[编辑]构建消息:
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define
Lorg/apache/commons/logging/impl/LogFactoryImpl$2;
Error:com.android.dex.DexException: Multiple dex files define
Lorg/apache/commons/logging/impl/LogFactoryImpl$2;
Error: at
com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
Error: at
com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
Error: at
com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
Error: at
com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Error: at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
Error: at
com.android.builder.dexing.
DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
Error: at
com.android.builder.dexing.
DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
Error: at java.util.concurrent.
ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
Error: at
java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error: at
java.util.concurrent.
ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
Error: at
java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
Error: at
java.util.concurrent.
ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task '
:<omitted project name>:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException:
com.android.dex.DexException: Multiple dex files define
Lorg/apache/commons/logging/impl/LogFactoryImpl$2;
答案 0 :(得分:0)
试
// https://mvnrepository.com/artifact/commons-io/commons-io
compile group: 'commons-io', name: 'commons-io', version: '2.6'
删除所有排除选项和commons-io。 上面的依赖可能只是工作正常
答案 1 :(得分:0)
问题是因为您在build.gradle中使用了重复的库。
首先,对于支持库,您需要使用相同的版本。请勿使用以下内容:
implementation 'com.android.support:support-v4:25.4.0'
implementation 'com.android.support:design:23.1.0'
implementation ('com.android.support:design:23.1.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.android.support:appcompat-v7:24.2.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
改为使用以下内容:
implementation 'com.android.support:support-v4:25.4.0'
implementation 'com.android.support:design:25.4.0'
// appcompat is implicitly include within support design.
第二,对于Google Play服务,请使用相同的版本。请勿使用以下内容:
implementation ('com.google.android.gms:play-services:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-gcm:9.0.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-auth:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
改为使用:
// Dont use the whole play service library
//implementation 'com.google.android.gms:play-services:9.8.0'
implementation 'com.google.android.gms:play-services-gcm:9.8.0'
implementation 'com.google.android.gms:play-services-auth:9.8.0'
第三次,要排除常见日志记录,您需要使用以下内容:
compile(group: 'org.apache.commons', name: 'commons-compress', version: '1.3'){
exclude group: 'commons-logging', module: 'commons-logging'
}
或使用以下内容:
configurations.all {
exclude group: "commons-logging", module: "commons-logging"
}
您不需要为每个库添加排除项,因为某些库没有任何公共空间记录。