0

我的模块依赖项:

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文件:</p>

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:无法合并dex

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

我怎样才能解决这个问题?

4

1 回答 1

0

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

如果你跑

./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'

        }

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

于 2018-06-21T09:38:58.400 回答