【问题标题】:Error:com.android.dex.DexException: Multiple dex files define Ledu/umd/cs/findbugs/annotations/NonNull;错误:com.android.dex.DexException:多个dex文件定义了Ledu/umd/cs/findbugs/annotations/NonNull;
【发布时间】:2018-02-12 05:10:26
【问题描述】:

我的模块依赖:

configurations.all {
    resolutionStrategy {
        force 'junit:junit:4.12'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-
core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-
annotations'
})

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'

provided 'org.projectlombok:lombok:1.16.16'
annotationProcessor "org.projectlombok:lombok:1.16.16"

// For DL4J
compile 'org.deeplearning4j:deeplearning4j-core:0.9.1'
compile 'org.deeplearning4j:deeplearning4j-zoo:0.9.1'
compile 'org.nd4j:nd4j-native:0.9.1'
compile 'org.nd4j:nd4j-native:0.9.1:android-arm'
compile 'org.bytedeco.javacpp-presets:openblas:0.2.19-1.3:android-arm'
compile project(':dlbenchmark')
}

dlbenchmark 依赖如下:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-
core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-
annotations'
    })
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}

整个项目的gradle文件:

buildscript {
    repositories {
        jcenter()
        google()
    }
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}
allprojects {
    repositories {
        jcenter()
        google()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

dependencies {
}

在 Android Studio 中构建 dl4j 模块时出现错误:

错误:java.lang.RuntimeException:java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException:无法合并 索引

错误:com.android.dex.DexException:多个 dex 文件定义 ledu/umd/cs/findbugs/annotations/NonNull;

我该如何解决这个问题?

【问题讨论】:

    标签: java android-studio dl4j


    【解决方案1】:

    正如错误消息所说,某些类有多个定义。 我遇到了同样的问题,并且能够通过查看依赖关系树来解决它。

    如果你运行

    ./gradlew app:dependencies
    

    在 Android Studio 终端中,您将获得一个依赖关系树。你会发现

    com.google.code.findbugs:annotations:2.0.1
    

    此库是测试所必需的,不需要与您的 apk 打包。您可以像这样从依赖项中排除它:

    compile('org.nd4j:nd4j-native:0.9.1') {
        exclude group: 'com.google.code.findbugs', module: 'annotations'
    
    }
    
    compile('org.nd4j:nd4j-native:0.9.1:android-x86')
            {
                exclude group: 'com.google.code.findbugs', module: 'annotations'
    
            }
    compile('org.nd4j:nd4j-native:0.9.1:android-arm')
            {
                exclude group: 'com.google.code.findbugs', module: 'annotations'
    
            }
    

    现在尝试构建并查看它是否有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多