Nikola-Milovic
Nikola-Milovic

Reputation: 1795

BuildConfig is defined multiple times, Gradle Test Build error

 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 outputs this I have an App Module that implements my LibraryModule and thats it

These are the recommended fixes

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.

These are the dependencies for the two build gradles of the library and the app.

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'


}

Apps whole build.gradle https://hastebin.com/dehedobica.php
Libraries whole build.gradle https://hastebin.com/omahuqutuc.nginx

I can remove the direct dependency and use JITPACK.io but I'd like to keep it local for development, I tried updating the dependencies, gradle version and downgrading versions but nothing seemed to work. I also deleted some dependencies but that didn't help either. I invalidated cache and similar common fixes but no luck.

I tried removing the dependencies from the App module and just implementing the Library(NsdKelper) but it doesn't work like the way I think it does. My way of thinking is

A implements project B which means that A will check B's dependencies and use those. But that doesnt seem to be the case here. Removing the dependencies from my App Module gives me errors of missing libraries. Or I am I misunderstanding something

Upvotes: 3

Views: 11373

Answers (2)

Ahmed Adnan
Ahmed Adnan

Reputation: 1

Adding this in android/build.gradle solved the problem for me:

project.ext {
    excludeAppGlideModule = true
}

Upvotes: 0

Nikola-Milovic
Nikola-Milovic

Reputation: 1795

They had the same Package ID, renaming the package on one of the modules solved it.

Upvotes: 4

Related Questions