Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Duplicate resources

After upgrading to React Native 0.57 i am facing an issue when genrating APK in react-native-router-flux.when executing the .\gradlew assembleRelease i get below error :-

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> [drawable-mdpi-v4/node_modules_reactnativerouterflux_images_back_chevron] 
R:\Workings\lisecapps\androidrepo\test-react- 
native\venutest\android\app\src\main\res\drawable- 
mdpi\node_modules_reactnativerouterflux_images_back_chevron.png      
[drawable-mdpi-v4/node_modules_reactnativerouterflux_images_back_chevron] 
R:\Workings\lisecapps\androidrepo\test-react- 
emirnative\venutest\android\app\build\generated\res\react\release\drawable- 
mdpi-v4\node_modules_reactnativerouterflux_images_back_chevron.png: Error: 
Duplicate resources
[drawable-mdpi-v4/node_modules_reactnativerouterflux_images_menu_burger] 
R:\Workings\lisecapps\androidrepo\test-react-nat 
ive\venutest\android\app\src\main\res\drawable- 
mdpi\node_modules_reactnativerouterflux_images_menu_burger.png        
[drawable-mdpi-v4/node_modules_reactnativerouterflux_images_menu_burger] 
R:\Workings\lisecapps\androidrepo\test-react- 
native\venutest\android\app\build\generated\res\react\release\drawable-mdpi- 
v4\node_modules_reactnativerouterflux_images_menu_burger.png: Error: 
Duplicate resources

I tried the following to resolve but still same error :-

  • Tried to create script as said in the first answer here to avoid duplicate copying of asset images.
  • Deleted the whole app/build folder
like image 965
anbu selvan Avatar asked Sep 23 '18 09:09

anbu selvan


People also ask

What is duplicate resources error in Android Studio?

It seems like you have the same image resource in two files OR you added an additional, non-required file to the res folder. Rename or remove the other. You can check the required structure of the res folder and subfolders by downloading a fresh copy of WebViewGold from CodeCanyon.


2 Answers

You need remove generated resources/drawable and generate again.

rm -rf android/app/src/main/res/drawable-*
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/

And compile android again react-native run-android

like image 108
Tung Duong Avatar answered Oct 04 '22 12:10

Tung Duong


react.gradle automatically build your javascript and copy any resources imported inside your javascript to the build folder so make sure to NOT call react-native bundle manually and delete any files or folder as src/main/res/drawable-* and src/main/assets/*.bundle and have the following changes into your app/bundle.gradle

project.ext.react = [
  entryFile      : "index.js", // or index.android.js
  bundleInRelease: true,
  bundleInDebug: true
]

apply from: "../../node_modules/react-native/react.gradle"

Note: please notice that some react-native versions have a problem with the local cli.js please make sure to upgrade to a newer version or try adding the following config

 project.ext.react = [
    // ...
    cliPath: "node_modules/react-native/local-cli/cli.js"
 ]
like image 37
Fareed Alnamrouti Avatar answered Oct 04 '22 12:10

Fareed Alnamrouti