Type BuildConfig is defined multiple times

Viewed 51704

I'm working on a multi module Android application and everything was working in a debug mode but now when I try to build a release package I'm receiving this error:

Type ***module1.BuildConfig is defined multiple times:
***/module1/build/intermediates/runtime_library_classes/release/classes.jar:***/module1/BuildConfig.class,
***/module2/build/intermediates/runtime_library_classes/release/classes.jar:***/module1/BuildConfig.class

It's the first time I'm seeing an error like this and I don't know how to fix this and what's even causing it. As far as I'm aware library modules shouldn't even be generating BuildConfig files in release mode.

14 Answers

check if both modules have a same package name

My Android Manifest Had the same Package Name for two Diferent Modules.

Most probably both shared AndroidManifest.xml and androidApp AndroidManifest.xml has the same packageId. They have to be different. For example, com.my.app.shared and com.my.app.android

I'm using Android Studio 4.0.1 on MacOS

On my network drive within the project app folder, I searched for BuildConfig

I noticed a BuildConfig 2.class file had been generated.

I deleted the BuildConfig 2.class file, rebuilt, re-ran and everything was fine.

UPDATE

I ran into a situation where a BuildConfig 3.class showed up, so now I search by Config (Config+space)

UPDATE 2

I have this issue continuously every time I run. Now rather than deleting the file, I use, menu item

"Build"->"Clean Project"

Then re-run the app.

For me adding the following line to android/app/build.gradle into the following section helped:

dependencies {
    ...
    implementation(project(':react-native-jitsi-meet')) {
        ...
        exclude group: 'com.facebook.react',module:'react-native-linear-gradient' // <<<---- this line was added
    }
}

In my case, I have a multi-module project, also got the same issue. I checked every manifest and package name, which contain duplicates of another. I found the duplicate and renamed a package and manifest package name and did a Build -> Clean Project now the issue is resolved!

  • Check Duplicate Package, Manifest entry
  • Try Invalidate cache, Clean Build, Rebuild a Project
  • Try to delete .gradle directory and rebuild the project.

I get the error after upgrading the firebase project level dependency on the android project

classpath 'com.google.firebase:perf-plugin:1.3.4'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'

to solve my error I am updated the above to

classpath ('com.google.firebase:perf-plugin:1.3.4') {
     exclude group: 'com.google.guava', module: 'guava-jdk5'
 }
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'

and go to the project folder and delete build/intermediates

  1. app/build/intermediates delete this folder
  2. invalidate the cache and restart
  3. after. restart - rebuild and run

Worked for me

The only solution that worked for me was to delete the ~/.gradle folder in my home folder (mac osx).

Edit: After a while it happened again - so I deleted the whole project and cloned it again from github. That fixed it completely without happen ever again.

Type com.e.pacakgename.MainActivity is defined multiple times.

I also faced this error, and in my case there was 2 MainActivity files in my project.

After removing one file the error is solved.

I'm using Android Studio 4.1.2 and the following worked for me: Open Build -> Rebuild Project.

For those searching like me :(, This worked. I had JitsiMeet and that is the reason, this happens. I found in Jitsimeet repo.

on app/build.gradle:

implementation(project(':react-native-jitsi-meet')) {
    exclude group: 'com.facebook.react',module:'react-native-google-signin'
}
 buildTypes {
    debug {
        buildConfigField "String", "BaseApi", "\"https://{apiUrlDebug}\""

    }
    release {
        signingConfig signingConfigs.release
        buildConfigField "String", "BaseApi", "\"https://{apiUrlRelease}\""
 
        zipAlignEnabled true
        minifyEnabled true
        shrinkResources true
        pseudoLocalesEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        lintOptions {

            checkReleaseBuilds false
            abortOnError false
        }
    }
}
Related