BuildConfig 定义了多次,Gradle 测试构建错误

3
 Type com.nikolam.nsdkelper.BuildConfig is defined multiple times: /storage/Users/Volks/Desktop/Android-2020/NsdKelper/app/build/intermediates/project_dex_archive/release/out/com/nikolam/nsdkelper/BuildConfig.dex, /storage/Users/Volks/Desktop/Android-2020/NsdKelper/nsdkelper/build/.transforms/6fff326acaa87110e65737aff5d0e0cd/classes/classes.dex

./gradlew test build 输出以下结果。

我有一个应用程序模块实现了我的 LibraryModule,仅此而已。

以下是建议的修复方法。

This error typically occurs due to one of the following circumstances:
A binary dependency includes a library that your app also includes as a direct dependency. For example, your app declares a direct dependency on Library A and Library B, but Library A already includes Library B in its binary.
        To resolve this issue, remove Library B as a direct dependency.
    Your app has a local binary dependency and a remote binary dependency on the same library.
        To resolve this issue, remove one of the binary dependencies.

这些是库和应用程序的两个构建gradle的依赖关系。

dependencies {
///LIBRARY
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.3.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

///APP
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation project(":nsdkelper")

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'


}

整个应用程序build.gradle文件:https://hastebin.com/dehedobica.php
整个库的build.gradle文件:https://hastebin.com/omahuqutuc.nginx

我可以移除直接依赖并使用JITPACK.io,但我希望在开发过程中保持本地依赖。我尝试更新依赖项、gradle版本和降低版本,但似乎没有什么作用。我还删除了一些依赖项,但也没有帮助。我已经尝试了清除缓存等常见解决方法,但没有运气。

我尝试从应用程序模块中移除依赖项,并只实现库(NsdKelper),但它不像我想象的那样工作。我的思考方式是:

A实现项目B,这意味着A将检查B的依赖项并使用它们。但在这里似乎并非如此。从我的应用程序模块中删除依赖项会导致找不到库的错误。或者我误解了什么吗?

2个回答

3
他们的Package ID相同,将其中一个模块的包重命名即可解决。

0

在 android/build.gradle 中添加以下内容解决了我的问题:

project.ext {
    excludeAppGlideModule = true
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接