android - 多次定义BuildConfig,Gradle Test Build报错

标签 android gradle build.gradle dex

 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 版本和降级版本,但似乎没有任何效果。我还删除了一些依赖项,但这也无济于事。我使缓存和类似的常见修复程序无效,但没有成功。

我尝试从 App 模块中删除依赖项并仅实现 Library(NsdKelper),但它并不像我认为的那样工作。我的思路是

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

最佳答案

他们有相同的包 ID,重命名其中一个模块上的包解决了这个问题。

关于android - 多次定义BuildConfig,Gradle Test Build报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62972135/

相关文章:

android - 如何从 SimpleCursorAdapter 的选定项中获取字符串?

android - 如何从我包含在 Android 上的第三方库中删除未使用的资源?

android - 根据构建类型通过 Gradle 设置 Android.mk 标志

gradle - 应用编写为Groovy的自定义插件

android - 导入到另一个项目的 Gradle 模块中的 `rootProject`

android - 如何用 Activity 结果 API 替换 startActivityForResult?

android - 弹出窗口中的ListView

android - 如何从 Android Google Maps API V2 获取 MapView 的位图

java - 通过 gradle 编写 xlsx

java - 更新的信息没有反射(reflect)在mysql数据库中