[Android] Error: Duplicate resources
Problem
- [x] Review the documentation: https://facebook.github.io/react-native - [x] Search for existing issues: https://github.com/facebook/react-native/issues - [x] Use the latest React Native release: https://github.com/facebook/react-native/releases Environment React Native Environment Info: System: OS: macOS 10.14 CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz Memory: 103.10 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 8.12.0 - /usr/local/bin/node Yarn: 1.0.1 - /usr/local/bin/yarn npm: 6.4.1 - /usr/local/bin/npm Watchman: 4.7.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1 Android SDK: API Levels: 16, 17, 19, 21, 23, 24, 25, 26, 27, 28 Build Tools: 19.1.0, 20.0.0, 23.0.1, 23.0.2, 23.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.1, 27.0.3, 28.0.0, 28.0.0, 28.0.2, 28.0.3 System Images: android-16 | ARM EABI v7a, android-16 | MIPS, android-16 | Intel x86 Atom, android-16 | Google APIs Intel x86 Atom, android-19 | Google APIs Intel x86 Atom, android-24 | Google Play Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom_64, android-26 | Google Play Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-P | Google APIs Intel x86 Atom, android-P | Google Play Intel x86 Atom IDE
Error Output
error I'm getting while generating the release build
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Resolve Duplicate Resources Error in React Native Android Build
The 'Duplicate resources' error occurs when two or more resources (like images, strings, or layouts) have the same name in the Android project. This can happen if libraries or modules included in the project contain overlapping resource names or if resources are mistakenly duplicated in the project's own directories.
Awaiting Verification
Be the first to verify this fix
- 1
Identify Duplicate Resources
Run the following command to identify duplicate resources in your Android project. This will help you pinpoint which resources are causing the conflict.
bash./gradlew app:processReleaseResources --info - 2
Remove or Rename Duplicates
Once you have identified the duplicate resources, navigate to the respective directories and either remove or rename the conflicting resources. Ensure that you update any references to these resources in your code.
bashmv android/app/src/main/res/drawable/duplicate_image.png android/app/src/main/res/drawable/duplicate_image_v2.png - 3
Clean and Rebuild the Project
After resolving the duplicates, clean the project to remove any cached build artifacts and then rebuild it. This ensures that the changes take effect.
bash./gradlew clean && ./gradlew assembleRelease - 4
Check for Library Conflicts
If duplicates persist, check your `package.json` and `android/app/build.gradle` for any libraries that may include conflicting resources. Consider updating or removing those libraries.
bashnpm outdated - 5
Update React Native and Dependencies
Ensure that you are using the latest version of React Native and all related dependencies. This can help avoid issues caused by outdated libraries.
bashnpm install --save react-native@latest
Validation
To confirm the fix worked, attempt to generate the release build again using './gradlew assembleRelease'. If the build completes without errors, the issue has been resolved.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep