109

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.

5
  • 2
    check if both modules has same package name Commented Mar 3, 2020 at 12:58
  • Please post your Gradle file Commented Mar 3, 2020 at 12:59
  • 23
    Well now I feel stupid. I had the same packages defined in both manifests. Commented Mar 3, 2020 at 13:03
  • 3
    No worries. It happens :D Commented Apr 29, 2020 at 14:57
  • I had the same packages defined in both build.gradle.kts Commented Sep 14, 2023 at 10:52

18 Answers 18

178

check if both modules have a same package name

Sign up to request clarification or add additional context in comments.

8 Comments

i have this issue in my case : Type com.BV.LinearGradient.BuildConfig is defined multiple times: /node_modules/react-native-linear-gradient/android/build/.transforms/aaad2255142356c3377f56df42cfb484/classes/classes.dex, /android/app/build/intermediates/external_libs_dex/release/out/classes.dex i don't know what's the solution
Build -> Rebuild Project might help
@Yacine i m also facing same issue . have you found any solution ?
i had to change the name of modules in node_modules
Check the package name in the AndroidManifest also!
|
26

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"> 

Comments

18

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

Comments

10

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.

Comments

7

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.

Comments

6

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 } } 

Comments

4

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

Comments

3

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.

1 Comment

thanks, somehow I had this exact same situation. I don't even know how it got there!
2

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

Comments

2

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

Comments

1

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.

Comments

1

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.

Comments

1

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).

Comments

1

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'

Comments

0

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' } 

Comments

0

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.

Comments

-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 } } } 

Comments

-3

Click on Build->Clean Project

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.