Reputation: 2829
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.
Upvotes: 109
Views: 101025
Reputation: 991
While creating new module with app's package name, namespace in build.gradle file of new module generates with app's package name, rename it or remove that namespace line based on requirement, and compile, would work.
Example
change
namespace 'com.cool.dude'
to
namespace 'com.cool.dude.libName'
Upvotes: 1
Reputation: 5847
This is how this happened to me when using React Native:
Following different tutorials, my package.json
file contained these two packages:
"dependencies": {
"@react-native-community/masked-view": "^0.1.11",
"@react-native-masked-view/masked-view": "^0.3.1",
...
}
One was added automatically, another one added manually, following a tutorial. The solution is to remove the "community"-marked package.
The solution is specific for React Native, but the takeaway could be, check mutually exclusive dependencies like this.
Upvotes: 3
Reputation: 178
if you have a multi-module project check build.gradle.kts file and If they both have same name space change one so that they do not match. Clean project then rebuild. (NB: This is Android related).
Upvotes: 1
Reputation: 57
The only solution that worked for me was to delete the ~/.gradle folder in my home folder (mac osx).
At first, I believed that this solution might resolve the issue. However, then, I discovered that I unintentionally added the same dependency twice in my build.gradle file, originating from two distinct repositories. After removing the redundant entry, I successfully resolved the problem.
Upvotes: 0
Reputation: 2927
My Android Manifest Had the same Package Name for two Diferent Modules.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.repeated.package">
Upvotes: 26
Reputation: 356
In my case I was sharing a build.gradle
file with a namespace declared in multiple modules. Removing the namespace declaration made it work again
Upvotes: 2
Reputation: 3598
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'
}
Upvotes: 0
Reputation: 235
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
Upvotes: 18
Reputation: 281
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!
Upvotes: 7
Reputation: 174
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.
Upvotes: 1
Reputation: 14612
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.
Upvotes: 1
Reputation: 1
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
}
}
}
Upvotes: -1
Reputation: 68
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
Worked for me
Upvotes: 2
Reputation: 134
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
}
}
Upvotes: 6
Reputation: 1233
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.
Upvotes: 10
Reputation: 1354
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
Upvotes: 4