Type BuildConfig is defined multiple times
AndroidGradleAndroid Problem Overview
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.
Android Solutions
Solution 1 - Android
> check if both modules have a same package name
Solution 2 - Android
My Android Manifest Had the same Package Name for two Diferent Modules.
Solution 3 - Android
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
Solution 4 - 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.
Solution 5 - Android
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
}
}
Solution 6 - Android
Rebuilding the app fixed the issue for me.
If rebuilding is not fixing the issue Check this out : https://developer.android.com/studio/build/dependencies#duplicate_classes
Solution 7 - Android
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.
Solution 8 - Android
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
- app/build/intermediates delete this folder
- invalidate the cache and restart
- after. restart - rebuild and run
Worked for me
Solution 9 - Android
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.
Solution 10 - Android
> 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.
Solution 11 - Android
I'm using Android Studio 4.1.2 and the following worked for me: Open Build -> Rebuild Project.
Solution 12 - Android
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
}
}
}
Solution 13 - Android
Click on Build->Clean Project