Thanks for submitting your issue. Can you take another look at your description and make sure the issue template has been filled in its entirety?
👉 Click here if you want to take another look at the Bug Report issue template.
Go to your android/app/src/res/ ===> delete all drawable-hdpi,mdpi,xhdpi,xxhdpi,xxxhdpi and raw folders.
then run the below amd
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
sorry, I was wrong about another step,thanks
hey @zhanglong11 ,
m facing the same issue can you tell me how to fix it.
I just upgraded RN from 0.51.0 to 0.60.5.
Even i got same issue my problem was i had two images with same name background.png and background.jpg, the app was running fine in development, but throwing error while generating signed APK, once i deleted once of the duplicate image my issue got resolved.
I keep getting this error while trying to generate a signed apk release
[raw/app] /home/lenssd/Desktop/TestApp/test/android/app/src/main/res/raw/app.json [raw/app] /home/lenssd/Desktop/TestApp/test/android/app/build/generated/res/react/release/raw/app.json: Error: Duplicate resources
I tried all the steps described above still no luck
@AnilKumarSamal Please try to delete all drawable-hdpi,mdpi,xhdpi,xxhdpi,xxxhdpi and raw folders also do a gradlew clean
@SridharAlagirisamy Thank you for your reply I tried as suggested but I got a new error
Given final block not properly padded
This is how i solved this issue.
It was due to release build because it generate new assets whenever you run your app in release mode
so i made npm pre-androidBuild command which is
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/ && sh ./scripts/clear-android-assets.sh
and here is my script
which clear run time generated assets of previous build
`#!/bin/sh
resPath='./android/app/src/main/res/'
ls $resPath | grep "drawable-" | while read -r folder ; do
path="$resPath$folder"
echo "Processing $folder"
ls $path | grep -E "node_modules_|assets_" | xargs -d "\n" -I % sh -c "rm $path/%;"
done
`
Same error here
[drawable-xhdpi-v4/node_modules_reactnavigationstack_lib_module_views_assets_backicon] /Users/albert/Projects/mobile-app/android/app/src/main/res/drawable-xhdpi/node_modules_reactnavigationstack_lib_module_views_assets_backicon.png [drawable-xhdpi-v4/node_modules_reactnavigationstack_lib_module_views_assets_backicon] /Users/albert/Projects/mobile-app/android/app/build/generated/res/react/release/drawable-xhdpi/node_modules_reactnavigationstack_lib_module_views_assets_backicon.png: Error: Duplicate resources
tried all @SridharAlagirisamy said but the errror persists
some solutions are provided here
You can add code in node_modules/react-native/react.gradle. After doFirst
doLast {
def moveFunc = { resSuffix ->
File originalDir = file("$buildDir/generated/res/react/release/${resSuffix}");
if (originalDir.exists()) {
File destDir = file("$buildDir/../src/main/res/${resSuffix}");
ant.move(file: originalDir, tofile: destDir);
}
}
moveFunc.curry("drawable-ldpi").call()
moveFunc.curry("drawable-mdpi").call()
moveFunc.curry("drawable-hdpi").call()
moveFunc.curry("drawable-xhdpi").call()
moveFunc.curry("drawable-xxhdpi").call()
moveFunc.curry("drawable-xxxhdpi").call()
moveFunc.curry("raw").call()
}
Why would be the fix to modify a react-native file within node_modules???? i can't believe all the fixes i've seen so far, suggests doing this instead of facebook pushing a real fix for this :S
This is how i solved this issue.
It was due to release build because it generate new assets whenever you run your app in release mode
so i made npm pre-androidBuild command which is
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/ && sh ./scripts/clear-android-assets.sh
and here is my script
which clear run time generated assets of previous build
`#!/bin/sh
resPath='./android/app/src/main/res/'ls $resPath | grep "drawable-" | while read -r folder ; do
path="$resPath$folder"
echo "Processing $folder"
ls $path | grep -E "node_modules_|assets_" | xargs -d "\n" -I % sh -c "rm $path/%;"
done`
Bro im having issues with your script, it says that xargs -d isn't a valid param, what would i use? im on macos. Please help
My solution:
Delete all files in /your_project/android/app/src/main/raw/res.
It 's work for me !
@thaiphamvan that works thanks.
after that no problem occurs
watch out to your key and alias and ...
Closing after several months without followup from the author. Please make sure to fill in the issue template if you decide to file a new issue.
Anyone find a solution to this? Still having this issue...
Same errors for me.
```> Task :app:mergeReleaseResources FAILED
[drawable-hdpi-v4/node_modules_reactnavigationstack_lib_module_vendor_views_assets_backicon] F:\testapp\android\app\src\main\res\drawable-hdpi\node_modules_reactnavigationstack_lib_module_vendor_views_assets_backicon.png [drawable-hdpi-v4/node_modules_reactnavigationstack_lib_module_vendor_views_assets_backicon] F:\testapp\android\app\build\generated\res\react\release\drawable-hdpi\node_modules_reactnavigationstack_lib_module_vendor_views_assets_backicon.png: Error: Duplicate resources
```
If this is still an issue in 0.61, please open a new issue and fill out the template.
This solved my problem (0.61) https://github.com/facebook/react-native/issues/26245#issuecomment-541490177
This solved my problem (0.61) #26245 (comment)
where the code is written specifically ?
@SridharAlagirisamy by doing: => Go to your android/app/src/res/ ===> delete all drawable-hdpi,mdpi,xhdpi,xxhdpi,xxxhdpi and raw folders. - works!
By running: then run the below amd
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
generates those files and folder again and release build fails with duplicate resource again.
Version RN 61.5
Version RN 61.5
did you solved it???
Yeah, after removing drawable* folders and “raw” folder, don’t run ‘react-native bundle’ command when you want release, just create the signed bundle or apk directly from the Android studio. When it’s time to create a debug build, run the react-native bundle command. That will recreate drawable* and “raw” folders and debug build after that should succeed.
If you are getting this error at the time of making release apk you can use this command to generate the signed apk and the error will not occur
./gradlew assembleRelease -x bundleReleaseJsAndAssets
This command should be executed in android folder of your app
@mohit-brainizen , appreciate that it helped a lot!!
@thaiphamvan im getting same error rn v 0.60.5 and using hermes.
where to add your code?
You can add code in node_modules/react-native/react.gradle. After doFirst
doLast {
def moveFunc = { resSuffix ->
File originalDir = file("$buildDir/generated/res/react/release/${resSuffix}");
if (originalDir.exists()) {
File destDir = file("$buildDir/../src/main/res/${resSuffix}");
ant.move(file: originalDir, tofile: destDir);
}
}
moveFunc.curry("drawable-ldpi").call()
moveFunc.curry("drawable-mdpi").call()
moveFunc.curry("drawable-hdpi").call()
moveFunc.curry("drawable-xhdpi").call()
moveFunc.curry("drawable-xxhdpi").call()
moveFunc.curry("drawable-xxxhdpi").call()
moveFunc.curry("raw").call()
}
my do last code is
doLast {
def hermesFlags;
exec {
if (targetName.toLowerCase().contains("release")) {
// Can't use ?: since that will also substitute valid empty lists
hermesFlags = config.hermesFlagsRelease
if (hermesFlags == null) hermesFlags = ["-O", "-output-source-map"]
} else {
hermesFlags = config.hermesFlagsDebug
if (hermesFlags == null) hermesFlags = []
}
commandLine(getHermesCommand(), "-emit-binary", "-out", jsBundleFile, jsBundleFile, *hermesFlags)
}
if (hermesFlags.contains("-output-source-map")) {
ant.move(
// Hermes will generate a source map with this exact name
// NOTE: name coincides with jsOutputSourceMapFile
file: "${jsBundleFile}.map",
tofile: jsCompilerSourceMapFile
);
exec {
// TODO: set task dependencies for caching
// Set up the call to the compose-source-maps script
workingDir(reactRoot)
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine("cmd", "/c", *nodeExecutableAndArgs, composeSourceMapsPath, jsPackagerSourceMapFile, jsCompilerSourceMapFile, "-o", jsOutputSourceMapFile)
} else {
commandLine(*nodeExecutableAndArgs, composeSourceMapsPath, jsPackagerSourceMapFile, jsCompilerSourceMapFile, "-o", jsOutputSourceMapFile)
}
}
}
}
My solution:
Delete all files in /your_project/android/app/src/main/raw/res.
It 's work for me !
Worked for me too.
@masmai But don't we need these files there? These are the icons.
@thaiphamvan that was working for me, thank you very much
This is how i solved this issue.
It was due to release build because it generate new assets whenever you run your app in release mode
so i made npm pre-androidBuild command which is
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/ && sh ./scripts/clear-android-assets.sh
and here is my script
which clear run time generated assets of previous build
#!/bin/sh resPath='./android/app/src/main/res/' ls $resPath | grep "drawable-" | while read -r folder ; do path="$resPath$folder" echo "Processing $folder" ls $path | grep -E "node_modules_|assets_" | xargs -d "\n" -I % sh -c "rm $path/%;" done
Bro im having issues with your script, it says that xargs -d isn't a valid param, what would i use? im on macos. Please help
xargs isn't valid in mac. You can try some alternative like suggested here.
https://superuser.com/questions/467176/replacement-for-xargs-d-in-osx
@SridharAlagirisamy by doing: => Go to your android/app/src/res/ ===> delete all drawable-hdpi,mdpi,xhdpi,xxhdpi,xxxhdpi and raw folders. - works!
By running: then run the below amd
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/resgenerates those files and folder again and release build fails with duplicate resource again.
Version RN 61.5
@SridharAlagirisamy by doing: => Go to your android/app/src/res/ ===> delete all drawable-hdpi,mdpi,xhdpi,xxhdpi,xxxhdpi and raw folders. - works!
By running: then run the below amd
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/resgenerates those files and folder again and release build fails with duplicate resource again.
Version RN 61.5
It's worked for me
You can add code in node_modules/react-native/react.gradle. After doFirst
doLast {
def moveFunc = { resSuffix ->
File originalDir = file("$buildDir/generated/res/react/release/${resSuffix}");
if (originalDir.exists()) {
File destDir = file("$buildDir/../src/main/res/${resSuffix}");
ant.move(file: originalDir, tofile: destDir);
}
}
moveFunc.curry("drawable-ldpi").call()
moveFunc.curry("drawable-mdpi").call()
moveFunc.curry("drawable-hdpi").call()
moveFunc.curry("drawable-xhdpi").call()
moveFunc.curry("drawable-xxhdpi").call()
moveFunc.curry("drawable-xxxhdpi").call()
moveFunc.curry("raw").call()
}
thank
why this hasn't been fixed without involving people's coding?
My problem was solved by following the bellow @thaiphamvan approach
You can add code in node_modules/react-native/react.gradle. After doFirst
doLast {
def moveFunc = { resSuffix ->
File originalDir = file("$buildDir/generated/res/react/release/${resSuffix}");
if (originalDir.exists()) {
File destDir = file("$buildDir/../src/main/res/${resSuffix}");
ant.move(file: originalDir, tofile: destDir);
}
}
moveFunc.curry("drawable-ldpi").call()
moveFunc.curry("drawable-mdpi").call()
moveFunc.curry("drawable-hdpi").call()
moveFunc.curry("drawable-xhdpi").call()
moveFunc.curry("drawable-xxhdpi").call()
moveFunc.curry("drawable-xxxhdpi").call()
moveFunc.curry("raw").call()
}
Any solution for this? Without changing react-native
core node-modules
???
I have assets in raw
which I need to use in some native ui components I have in my projects (so deleting raw
is not a solution for me)
Most helpful comment
You can add code in node_modules/react-native/react.gradle. After doFirst
doLast {
def moveFunc = { resSuffix ->
File originalDir = file("$buildDir/generated/res/react/release/${resSuffix}");
if (originalDir.exists()) {
File destDir = file("$buildDir/../src/main/res/${resSuffix}");
ant.move(file: originalDir, tofile: destDir);
}
}
moveFunc.curry("drawable-ldpi").call()
moveFunc.curry("drawable-mdpi").call()
moveFunc.curry("drawable-hdpi").call()
moveFunc.curry("drawable-xhdpi").call()
moveFunc.curry("drawable-xxhdpi").call()
moveFunc.curry("drawable-xxxhdpi").call()
moveFunc.curry("raw").call()
}