Closed
Description
- Review the documentation: https://facebook.github.io/react-nativeSearch for existing issues: https://github.com/facebook/react-native/issuesUse 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
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5056338
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.6.0-alpha.8af6728 => 16.6.0-alpha.8af6728
react-native: 0.57.4 => 0.57.4
npmGlobalPackages:
babel-preset-react-native: 4.0.0
react-native-cli: 2.0.1
react-native-create-library: 3.1.2
react-native-git-upgrade: 0.2.7
Description
I'm not able to create a release apk with the PNG image in Android. But can able to create a release apk when there is no PNG image in it. Here is the error I'm getting while generating the release build
[drawable-mdpi-v4/assets_mario] /Users/jeffreyrajan/Tutorials/RN/errorCheck/android/app/src/main/res/drawable-mdpi/assets_mario.png [drawable-mdpi-v4/assets_mario] /Users/jeffreyrajan/Tutorials/RN/errorCheck/android/app/build/generated/res/react/release/drawable-mdpi-v4/assets_mario.png: Error: Duplicate resources
:app:mergeReleaseResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> [drawable-mdpi-v4/assets_mario] /Users/jeffreyrajan/Tutorials/RN/errorCheck/android/app/src/main/res/drawable-mdpi/assets_mario.png [drawable-mdpi-v4/assets_mario] /Users/jeffreyrajan/Tutorials/RN/errorCheck/android/app/build/generated/res/react/release/drawable-mdpi-v4/assets_mario.png: Error: Duplicate resources
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Reproducible Demo
- Create a app -
react-native init demo
- Create a
assets
folder in the project root folder. - Add a PNG image inside the assets folder.
- Now implement a
image
component with the above PNG image. - Now bundle it using the cmd
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
- Then generate release apk using
Generate Signed APK
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
ZeroCool00 commentedon Nov 11, 2018
check this #19239 (comment)
You need to remove drawable folder image if there is any?
jeffreyrajanofficial commentedon Nov 12, 2018
@ZeroCool00 wont that affect the images in Android?
echaritonidis commentedon Nov 12, 2018
Mapsy's answer should help https://stackoverflow.com/a/52750886
So basically you edit the /node_modules/react-native/react.gradle file
and add the doLast right after the doFirst block, manually.
jeffreyrajanofficial commentedon Nov 12, 2018
@ZeroCool00 @mkchx I checked with both of your answer, its working. Thanks a lot guys :)
vivek-walecha-657-zz commentedon Dec 21, 2018
Hi all how will we able to get this done with jenkins job. As it will do npm install always which override this change in react.gradle file. We can create build on android studio for android but not possible on jenkins.
jeffreyrajanofficial commentedon Dec 21, 2018
Hi @vivek-walecha-657 I haven't tried this but you can try this command for creating offline bundling
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle
vivek-walecha-657-zz commentedon Dec 24, 2018
@jeffreyrajanofficial Thanx for writing, the solution you have provided will help if we go and change react.gradle file. But I don't want to make the release by changing the react.gradle file every time i do npm install everywhere.
vivek-walecha-657-zz commentedon Dec 24, 2018
@jeffreyrajanofficial Can you please tell which version(latest lower than this or higher than this) is working fine, without this issue. Because release notes don't tell anything that this issue is resolved.
vivek-walecha-657-zz commentedon Jan 3, 2019
Things are sorted now in RN > 57 react.gradle file automatically creates the bundle.
for creating a release build you dont need to run the npm run build:android:release
abhishekgargx commentedon Jan 14, 2019
Using 55.4 react native version here is my sample project gist for build.gradle package.json with fixes.
https://gist.github.com/Abhishekgarg727/daf031fb9f94fdfd985e84db57dedbe1
mikehardy commentedon Jan 24, 2019
I was still seeing this, using macOS 10.14.3 + RN 0.57.8 + Android Studio 3.3 + Gradle 4.10.3. Maybe I'm not the only one? Or maybe someone here can confirm it works so I'll dig more and fix it for myself for real.
I'm currently working around it with the "patch-package" package in combination with the attached patch based on the above comment from @mkchx (with
.txt
suffix appended so github would accept the attachment) in order to automagically fix it on 'npm install' after addingpostinstall: patch-package
to my package.json scripts.Maybe this is useful to someone...
react-native+0.57.8.patch.txt
rahulkumar1409 commentedon Mar 1, 2019
Remove the files you might have on:
android/app/src/main/res/drawable-mdpi/
android/app/src/main/res/drawable-xhdpi/
android/app/src/main/res/drawable-xxhdpi/
Run Build again, This fixed the issue for me.
132 remaining items
andreiciceu commentedon Feb 17, 2023
The problem for my setup was this line in
app/build.gradle
leftover from older react-native versions:removed it and build works now
varadarajan-videoyantra commentedon Mar 12, 2023
Thank you @andreiciceu. This worked for me too.
jcmunoz200 commentedon Apr 24, 2023
Sorry for my english.
This works for me.
Add new scripts in package.json
yourerrorbro commentedon Jun 6, 2023
I hope this email finds you well. I wanted to share an informative blog post with you that I recently came across. Here i provide proper solution. In above example i check. Initially worked but when build upload that's time create issue.
https://medium.com/@yourerrorbro/handling-duplicate-resource-issue-in-android-released-builds-in-react-native-f63c67176bce
SteveLai524 commentedon Aug 8, 2023
I remove it, but it still exist...I upgrade my react-native to "0.72.3", and it have not the file, and command. but it still exist the problem, and no idea to fix it.
Chronostyle commentedon Aug 14, 2023
use @jcmunoz200 solution, then after you want to release it to playstore, do: cd android && ./gradlew bundleRelease
SteveLai524 commentedon Aug 21, 2023
It doesn't work. so i downgrade my react-native version.
linhvovan29546 commentedon Aug 24, 2023
Thank you, this is working for me.
Sourav-techlur commentedon Oct 4, 2023
@SteveLai524 i am also facing same issue could you please tell me to which version you downgraded?
yogendrajs commentedon Dec 4, 2023
I don't have
react.gradle
file in RN v0.72.6, what do I have to do for this?sharjeelhaider commentedon Dec 6, 2023
Same problem for me. Not able find solution for this. I am using RN v0.72.7
kaxi1993 commentedon Dec 12, 2023
It worked fine in my case
gigby commentedon Mar 27, 2024
Which RN version did you have?
I have 0.68 and this doesn't work
rafaelmaeuer commentedon Apr 5, 2024
After upgrading an old react-native project to v0.71.0 the problem is still valid (6 years!!!). None of the fixes earlier in use seem to work (
doLast
, clean res, etc.) Anyone else having this issue and found a solution already?Edit: After some hours of investigation I did found another solution. It seems that patching
node_modules/react-native/react.gradle
withdoLast
isn't executed anymore. However if we add the patch inapp/build.gradle
to adoLast
section for taskcreateBundleReleaseJsAndAssets
it works again:RohitMau commentedon May 16, 2024