27

We have a React Native app where after upgrading to Android Studio 3.6.1 and Gradle plugin 3.6.1 we are seeing this compilation error:

Type androidx.appcompat.resources.R$dimen is defined multiple times: /Users/andrew/Software/project/android/app/build/intermediates/project_dex_archive/productionRelease/out/androidx/appcompat/resources/R$dimen.dex, /Users/andrew/Software/project/android/app/build/intermediates/project_dex_archive/productionRelease/out/15bdf8225afad69777cd7f9bd328ab094900c8289014e0107b56c5c62099dfea_3.jar:classes.dex

Here are our dependencies:

"dependencies": {
    "@dblackker/cameraroll": "^1.3.4",
    "@react-native-community/async-storage": "^1.7.1",
    "@react-native-community/geolocation": "^2.0.2",
    "@react-native-community/netinfo": "^4.4.0",
    "@react-native-community/push-notification-ios": "^1.0.6",
    "@react-native-firebase/analytics": "^6.2.0",
    "@react-native-firebase/app": "^6.2.0",
    "@react-native-firebase/crashlytics": "^6.2.0",
    "@react-native-firebase/perf": "^6.2.0",
    "appcenter": "^2.6.1",
    "appcenter-analytics": "^2.6.1",
    "appcenter-crashes": "^2.6.1",
    "axios": "^0.18.0",
    "clone": "^2.1.2",
    "immutability-helper": "^2.8.1",
    "lodash": "^4.17.14",
    "memoize-one": "^5.1.1",
    "moment": "^2.22.2",
    "prop-types": "^15.7.2",
    "react": "16.9.0",
    "react-custom-validation": "^0.5.7",
    "react-native": "0.61.5",
    "react-native-add-calendar-event": "^3.0.0",
    "react-native-app-intro-slider": "^3.0.0",
    "react-native-appearance": "^0.3.1",
    "react-native-camera": "^3.8.0",
    "react-native-contacts": "^5.0.6",
    "react-native-device-info": "^4.0.1",
    "react-native-gesture-handler": "^1.4.1",
    "react-native-heic-converter": "^1.3.0",
    "react-native-image-crop-picker": "^0.26.1",
    "react-native-image-resizer": "^1.0.1",
    "react-native-inappbrowser-reborn": "^3.1.0",
    "react-native-iphone-x-helper": "^1.2.1",
    "react-native-keyboard-aware-scroll-view": "^0.7.4",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-maps": "0.26.1",
    "react-native-modal": "^7.0.2",
    "react-native-modal-datetime-picker": "^7.6.1",
    "react-native-parsed-text": "^0.0.21",
    "react-native-permissions": "^2.0.9",
    "react-native-push-notification": "^3.1.9",
    "react-native-reanimated": "^1.3.0",
    "react-native-section-list-get-item-layout": "^2.2.3",
    "react-native-shadow": "^1.2.2",
    "react-native-share": "^2.0.0",
    "react-native-svg": "^9.12.0",
    "react-native-svg-uri": "^1.2.3",
    "react-native-tab-view": "^2.3.0",
    "react-native-version-number": "^0.3.6",
    "react-navigation": "3.12.0",
    "react-navigation-tabs": "^2.1.2",
    "react-redux": "^5.0.7",
    "redux": "^4.0.4",
    "redux-thunk": "^2.3.0",
    "rn-fetch-blob": "^0.11.2",
    "validator": "^10.8.0"
  }

Can anyone help figure out what the issue is, and how could we debug this type of issue in the future? Thank you!

Andrew Aarestad
  • 1,120
  • 2
  • 11
  • 15
  • I'm having the same error after upgrading to 3.6.1! If you find anything please let me know. I'm stuck :( – carlos21 Mar 05 '20 at 03:45
  • 4
    Solved by downgrading Android Gradle Plugin to 3.5.0 and Gradle Version to 5.5! – Igor Montella Mar 07 '20 at 04:11
  • Same issue, but downgrading to 3.5.0 brings other issues. This appeared literally out of nowhere. After downgrading, upgrading again worked for me. Perhaps something to do with caches... – slhck Apr 06 '20 at 16:38

16 Answers16

37

Got the same problem, just clean project and rebuild again.

Franklin Paula
  • 481
  • 3
  • 2
10

I deleted android/app/build folder, because my duplicates were exactly there.

Wito Divaro
  • 129
  • 1
  • 6
8

I had same issue after updating gradle version to 3.6.3 from 3.5.2 in Android Studio.

I have multiple Build Variants.

I fixed the issue by first deleting .gradle folder from the project and did Clean Project and Rebuild Project.

If you have multiple build variant you may have to do same thing for each one when you change build variants from one to another.

Nikunj Patel
  • 303
  • 2
  • 11
7

Igor Montella's comment to my question fixed the problem - downgrade to gradle plugin 3.5.0.

Andrew Aarestad
  • 1,120
  • 2
  • 11
  • 15
  • 2
    Downgrading vital tools for the IDE should never be a permanent solution. This only covers up the real problem. – Nikos Hidalgo Jul 10 '20 at 15:02
  • 2
    Of course I would prefer to not downgrade. However when using a framework like React Native that is so heavily dependent on third party libraries, I often have little choice if I want to continue development. – Andrew Aarestad Jul 10 '20 at 20:18
3

I just run following built in routine in Android Studio:

  • File > Sync Project with Gradle Files

And then it worked again :-)

AZOM
  • 265
  • 5
  • 15
3

While I was coding on the android studio on native android.Got the same problem

Type androidx.appcompat.resources.R$dimen is defined multiple times:

The problem is because of the Duplication of the BuildConfig which is present inside the JAVA (Generated) Directory

Here is the solution to fix the problem.

You have to delete the duplicate BuildConfig from the android studio by this process

  1. Click on java(generated) on the Left side

enter image description here

  1. The problem is extra Build Config Created

enter image description here

  1. When you click any of the BuildConfig, it will show the same error display in the picture

enter image description here

  1. Delete the extra BuildConfig and keep the original BuildConfig.

Problem Solved

enter image description here

Aditya Anand
  • 367
  • 3
  • 9
2

My errors were similar, with a "is defined multiple times" message.

I solved it by downgrading the Gradle plugin to 3.5.0, running the app — or at least trying to — then upgrading to Gradle plugin 3.6.2 again.

I am not sure why, but this seemed to have cleared some caches or dependencies I was not aware of.

Removing ~/.gradle or android/.gradle did not help.

slhck
  • 36,575
  • 28
  • 148
  • 201
  • I did not get my Android project running again by downgrading to 3.5.0 and than back to 3.6.2. But I got it running by just downgrading to 3.6.1 – Rik van Velzen Apr 15 '20 at 07:44
2

For Googlers:
In my case, I've created a benchmark module (with plugin "com.android.library") and made it depend on the app module (with plugin "com.android.application").
But library module can not depend on the application module, as Gradle does not support it.
Here some info: https://www.reddit.com/r/androiddev/comments/boi4xg/modularization_help_android_library_module/

Evgenii Vorobei
  • 1,457
  • 18
  • 20
1

Steps to follow

  1. Sync gradle files
  2. go to build section --> clean Project
  3. go to build section --> rebuild Project
  4. Again Sync the gradle files

Note: Make sure your PC/ Laptop connect with internet and updated android studio

0

File->Invalidate Caches / Restart

HalZhang
  • 206
  • 1
  • 6
0

I deleted ~/.gradle/caches

seems to work good. I did this because I saw ~/.gradle/caches in my error.

Type androidx.legacy.app.ActionBarDrawerToggle$Delegate is defined multiple times:
/Users/me/.gradle/caches/transforms-3/08344aeb2253f0dce062ee9436d14235/transformed/legacy-support-core-ui-1.0.0-runtime/classes.dex,
/Users/me/.gradle/caches/transforms-3/bde9e50d97f78024fdfcb4b5869842c8/transformed/legacy-support-core-ui-1.0.0-runtime/classes.dex
Andrew G
  • 2,596
  • 2
  • 19
  • 26
0

These answers are all outdated. I used 4.1.2. If you look at the path given in AS, it should point to \app\build\intermediates\project_dex_archive\debug\out. Go to this path, delete all the *.jar files, leaving the most recent one. I tried this and my project worked perfectly.

Don't bother with invalidates caches / restart as it won't work.

0

I have also the same issue in my case simply You have upgrade dependency it also works for me

0

@Wito Divaro, his answer helped me. If you are bothered by "R is defined multiple times.", just try to get rid of 'android/app/build'. Furthermore, I added this below line to app/build.gradle. If you want to try, try this.

defaultConfig {
   ..............
   multiDexEnabled true
}

dependencies {
    ..............
    implementation 'androidx.multidex:multidex:2.0.1'
}

public class MyApplication extends MultiDexApplication {
    ..............
}
Nico Burns
  • 16,639
  • 10
  • 40
  • 54
Hyeonmin
  • 135
  • 1
  • 4
0

For me, that fixed it.

step 1: I deleted the file BuildConfig in: app->java(generated)->BuildConfig

step 2: Clean Project: Build->Clean Project

step 3: Build->Rebuild Project

-1

I faced the same problem and solved it simply follow the above path and delete all files

  • 1
    Please add further details to expand on your answer, such as working code or documentation citations. – Community Aug 27 '21 at 06:08
  • @husseinkhalaf your answer is incomplete, you forgot to add the **path**, which is supposed to be deleted! – Manifest Man Aug 28 '21 at 21:37
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). – Manifest Man Aug 28 '21 at 21:42
  • You have to delete all files in a folder release and then clean project – Hussein khalaf Nov 18 '21 at 03:01