React Native Android - gradlew assembleRelease command unable to generate apk output - android

I am currently using React Native for my android app. The version of RN is 0.46.1 and the CLI is 2.0.1. Gradle as according to my Android Studio is version 3.3.
I managed to install my app into Android Emulator using "react-native run-android" without much issue. It works fine, but when I tried to generate apk, I got some errors. I am running on Windows 10.
Commands executed:
react-native bundle --platform android --dev false --entry-file index.android.js \ --bundle-output android/app/src/main/assets/index.android.bundle \ --assets-dest android/app/src/main/res/
cd android && gradlew assembleRelease
Right after 2nd command above, I got some errors:
:app:mergeReleaseResources
[drawable-mdpi-v4/node_modules_reactnativecheckbox_cb_disabled] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\node_modules_reactnativecheckbox_cb_disabled.png [drawable-mdpi-v4/node_modules_reactnativecheckbox_cb_disabled] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\node_modules_reactnativecheckbox_cb_disabled.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_travel022] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_travel022.jpg [drawable-mdpi-v4/assets_travel022] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_travel022.jpg: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white.png [drawable-mdpi-v4/node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_up128] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_up128.png [drawable-mdpi-v4/assets_up128] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_up128.png: Error: Duplicate resources
[drawable-xxxhdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-xxxhdpi\node_modules_reactnativeexperimentalnavigation_assets_back.png [drawable-xxxhdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-xxxhdpi-v4\node_modules_reactnativeexperimentalnavigation_assets_back.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_openenvelopewithletter_31832670] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_openenvelopewithletter_31832670.jpg [drawable-mdpi-v4/assets_openenvelopewithletter_31832670] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_openenvelopewithletter_31832670.jpg: Error: Duplicate resources
[drawable-xhdpi-v4/node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white] D:\travelogue\FE27\android\app\src\main\res\drawable-xhdpi\node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white.png [drawable-xhdpi-v4/node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white] D:\travelogue\FE27\android\app\src\main\res\drawable-xhdpi-v4\node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_down128] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_down128.png [drawable-mdpi-v4/assets_down128] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_down128.png: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnativecheckbox_cb_enabled] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\node_modules_reactnativecheckbox_cb_enabled.png [drawable-mdpi-v4/node_modules_reactnativecheckbox_cb_enabled] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\node_modules_reactnativecheckbox_cb_enabled.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_weather1gif] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_weather1gif.png [drawable-mdpi-v4/assets_weather1gif] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_weather1gif.png: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnativerouterflux_src_back_chevron] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\node_modules_reactnativerouterflux_src_back_chevron.png [drawable-mdpi-v4/node_modules_reactnativerouterflux_src_back_chevron] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\node_modules_reactnativerouterflux_src_back_chevron.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_accommodation_icon1] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_accommodation_icon1.png [drawable-mdpi-v4/assets_accommodation_icon1] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_accommodation_icon1.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_noimage] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_noimage.gif [drawable-mdpi-v4/assets_noimage] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_noimage.gif: Error: Duplicate resources
[drawable-xhdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-xhdpi\node_modules_reactnativeexperimentalnavigation_assets_back.png [drawable-xhdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-xhdpi-v4\node_modules_reactnativeexperimentalnavigation_assets_back.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_itineraryicon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_itineraryicon.png [drawable-mdpi-v4/assets_itineraryicon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_itineraryicon.png: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnativedatepicker_date_icon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\node_modules_reactnativedatepicker_date_icon.png [drawable-mdpi-v4/node_modules_reactnativedatepicker_date_icon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\node_modules_reactnativedatepicker_date_icon.png: Error: Duplicate resources
[drawable-xxhdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-xxhdpi\node_modules_reactnativeexperimentalnavigation_assets_back.png [drawable-xxhdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-xxhdpi-v4\node_modules_reactnativeexperimentalnavigation_assets_back.png: Error: Duplicate resources
[drawable-xxhdpi-v4/node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white] D:\travelogue\FE27\android\app\src\main\res\drawable-xxhdpi\node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white.png [drawable-xxhdpi-v4/node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white] D:\travelogue\FE27\android\app\src\main\res\drawable-xxhdpi-v4\node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white.png: Error: Duplicate resources
[drawable-hdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-hdpi\node_modules_reactnativeexperimentalnavigation_assets_back.png [drawable-hdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-hdpi-v4\node_modules_reactnativeexperimentalnavigation_assets_back.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_travelguide] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_travelguide.jpg [drawable-mdpi-v4/assets_travelguide] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_travelguide.jpg: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\node_modules_reactnativeexperimentalnavigation_assets_back.png [drawable-mdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\node_modules_reactnativeexperimentalnavigation_assets_back.png: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnativerouterflux_src_menu_burger] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\node_modules_reactnativerouterflux_src_menu_burger.png [drawable-mdpi-v4/node_modules_reactnativerouterflux_src_menu_burger] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\node_modules_reactnativerouterflux_src_menu_burger.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_embedplacesicon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_embedplacesicon.png [drawable-mdpi-v4/assets_embedplacesicon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_embedplacesicon.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_diningicon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_diningicon.png [drawable-mdpi-v4/assets_diningicon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_diningicon.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/node_modules_reactnativecheckbox_cb_disabled] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\node_modules_reactnativecheckbox_cb_disabled.png [drawable-mdpi-v4/node_modules_reactnativecheckbox_cb_disabled] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\node_modules_reactnativecheckbox_cb_disabled.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_travel022] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_travel022.jpg [drawable-mdpi-v4/assets_travel022] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_travel022.jpg: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white.png [drawable-mdpi-v4/node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_up128] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_up128.png [drawable-mdpi-v4/assets_up128] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_up128.png: Error: Duplicate resources
[drawable-xxxhdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-xxxhdpi\node_modules_reactnativeexperimentalnavigation_assets_back.png [drawable-xxxhdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-xxxhdpi-v4\node_modules_reactnativeexperimentalnavigation_assets_back.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_openenvelopewithletter_31832670] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_openenvelopewithletter_31832670.jpg [drawable-mdpi-v4/assets_openenvelopewithletter_31832670] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_openenvelopewithletter_31832670.jpg: Error: Duplicate resources
[drawable-xhdpi-v4/node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white] D:\travelogue\FE27\android\app\src\main\res\drawable-xhdpi\node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white.png [drawable-xhdpi-v4/node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white] D:\travelogue\FE27\android\app\src\main\res\drawable-xhdpi-v4\node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_down128] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_down128.png [drawable-mdpi-v4/assets_down128] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_down128.png: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnativecheckbox_cb_enabled] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\node_modules_reactnativecheckbox_cb_enabled.png [drawable-mdpi-v4/node_modules_reactnativecheckbox_cb_enabled] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\node_modules_reactnativecheckbox_cb_enabled.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_weather1gif] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_weather1gif.png [drawable-mdpi-v4/assets_weather1gif] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_weather1gif.png: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnativerouterflux_src_back_chevron] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\node_modules_reactnativerouterflux_src_back_chevron.png [drawable-mdpi-v4/node_modules_reactnativerouterflux_src_back_chevron] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\node_modules_reactnativerouterflux_src_back_chevron.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_accommodation_icon1] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_accommodation_icon1.png [drawable-mdpi-v4/assets_accommodation_icon1] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_accommodation_icon1.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_noimage] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_noimage.gif [drawable-mdpi-v4/assets_noimage] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_noimage.gif: Error: Duplicate resources
[drawable-xhdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-xhdpi\node_modules_reactnativeexperimentalnavigation_assets_back.png [drawable-xhdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-xhdpi-v4\node_modules_reactnativeexperimentalnavigation_assets_back.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_itineraryicon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_itineraryicon.png [drawable-mdpi-v4/assets_itineraryicon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_itineraryicon.png: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnativedatepicker_date_icon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\node_modules_reactnativedatepicker_date_icon.png [drawable-mdpi-v4/node_modules_reactnativedatepicker_date_icon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\node_modules_reactnativedatepicker_date_icon.png: Error: Duplicate resources
[drawable-xxhdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-xxhdpi\node_modules_reactnativeexperimentalnavigation_assets_back.png [drawable-xxhdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-xxhdpi-v4\node_modules_reactnativeexperimentalnavigation_assets_back.png: Error: Duplicate resources
[drawable-xxhdpi-v4/node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white] D:\travelogue\FE27\android\app\src\main\res\drawable-xxhdpi\node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white.png [drawable-xxhdpi-v4/node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white] D:\travelogue\FE27\android\app\src\main\res\drawable-xxhdpi-v4\node_modules_reactnativegoogleplacesautocomplete_images_powered_by_google_on_white.png: Error: Duplicate resources
[drawable-hdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-hdpi\node_modules_reactnativeexperimentalnavigation_assets_back.png [drawable-hdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-hdpi-v4\node_modules_reactnativeexperimentalnavigation_assets_back.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_travelguide] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_travelguide.jpg [drawable-mdpi-v4/assets_travelguide] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_travelguide.jpg: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\node_modules_reactnativeexperimentalnavigation_assets_back.png [drawable-mdpi-v4/node_modules_reactnativeexperimentalnavigation_assets_back] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\node_modules_reactnativeexperimentalnavigation_assets_back.png: Error: Duplicate resources
[drawable-mdpi-v4/node_modules_reactnativerouterflux_src_menu_burger] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\node_modules_reactnativerouterflux_src_menu_burger.png [drawable-mdpi-v4/node_modules_reactnativerouterflux_src_menu_burger] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\node_modules_reactnativerouterflux_src_menu_burger.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_embedplacesicon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_embedplacesicon.png [drawable-mdpi-v4/assets_embedplacesicon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_embedplacesicon.png: Error: Duplicate resources
[drawable-mdpi-v4/assets_diningicon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi\assets_diningicon.png [drawable-mdpi-v4/assets_diningicon] D:\travelogue\FE27\android\app\src\main\res\drawable-mdpi-v4\assets_diningicon.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.
BUILD FAILED
Total time: 1 mins 20.5 secs
I found some forums discussing similar problems https://github.com/facebook/react-native/issues/5787 but it doesn't really solve the problem (tried removing generated output files, even trie snippet code as suggested in the forum).

I ran into this problem as well. Here is how I fixed it. This is the most complex and robust way - see the end for easier options.
Renamed all my android/app/src/main/res/drawable-* folders, adding a -v4 to them all. (After this they look like: drawable-xhdpi-v4, drawable-ldpi-v4, etc.) Note: don't change the drawable folder itself.
Add a post-install hook to package.json that fixes the node_modules/react-native/local-cli/bundle/assetPathUtils.js file by adding -v4 to all of the switch statement's return values. The resulting switch statement in the assetPathUtils.js file should look like this:
switch (scale) {
case 0.75: return 'ldpi-v4';
case 1: return 'mdpi-v4';
case 1.5: return 'hdpi-v4';
case 2: return 'xhdpi-v4';
case 3: return 'xxhdpi-v4';
case 4: return 'xxxhdpi-v4';
}
This is one way to write that post-install hook:
const sh = require('shelljs');
const fileToFix =
'node_modules/react-native/local-cli/bundle/assetPathUtils.js';
const replacements = [
["case 0.75: return 'ldpi';", "case 0.75: return 'ldpi-v4';"],
["case 1: return 'mdpi';", "case 1: return 'mdpi-v4';"],
["case 1.5: return 'hdpi';", "case 1.5: return 'hdpi-v4';"],
["case 2: return 'xhdpi';", "case 2: return 'xhdpi-v4';"],
["case 3: return 'xxhdpi';", "case 3: return 'xxhdpi-v4';"],
["case 4: return 'xxxhdpi';", "case 4: return 'xxxhdpi-v4';"],
];
const content = sh.cat(fileToFix).stdout;
const fixedContent = replacements.reduce(
(accumulator, [oldStr, newStr]) => accumulator.replace(oldStr, newStr),
content
);
sh.ShellString(fixedContent).to(fileToFix);
And registering it in your package.json
...
"scripts": {
"postinstall": "node ./postinstall.js",
...
Other fixes from the 5787 issue:
If you don't have any custom icons in your drawable-* folders then you should be able to delete them all and have things work that way. (this is one I haven't personally confirmed)
If you don't need to use gradle v3+, then downgrading back to gradle v2.* will resolve the issue - although Android studio will continually prompt you to upgrade gradle.

Related

Jenkins - Execution failed for task ':app:mergeDebugResources'

I am trying to work with Jenkins however I cannot build the apk with it as I am having issue with AAPT2 and Gradle.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Multiple task action failures occurred:
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable
> Android resource compilation failed
ERROR:C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-3\b478eb984dbbd1317dab9bfd9689b3aa\transformed\appcompat-1.3.0\res\drawable-hdpi-v4\abc_list_divider_mtrl_alpha.9.png: AAPT: error: file not found.
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable
> Android resource compilation failed
ERROR:C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-3\b478eb984dbbd1317dab9bfd9689b3aa\transformed\appcompat-1.3.0\res\drawable-xhdpi-v4\abc_list_divider_mtrl_alpha.9.png: AAPT: error: file not found.
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable
> Android resource compilation failed
ERROR:C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-3\b478eb984dbbd1317dab9bfd9689b3aa\transformed\appcompat-1.3.0\res\drawable-mdpi-v4\abc_list_divider_mtrl_alpha.9.png: AAPT: error: file not found.
I already read tons of SO question that may share same issue to my case saying that it has something to do with the file path being too long but I still cannot find any solution.
UPDATE
I tried to change Android Studio Gradle home similar to what Jenkins is using and received similar error which indicates that it may really have something to do with long file path.
I think the final question will be how to change Jenkins Gradle Home?
You need to replace \ with \\ if you are giving path with jenkins in Windows.
May be if file path is too huge or that is the root cause you can try mounting the directory to a short path
EDIT : Based on your modified question :
Open Jenkins dashboard. Navigate to Manage Jenkins-> Configure System. Under the Global properties section add another environment variable named GRADLE_USER_HOME as shown below.
I ran into this exact issue, but unfortunately changing the GRADLE_USER_HOME environment variable did not help, as aapt2 appeared to ignore the change and still used Windows/system32/... for the cache location.
The problem was how I was running Jenkins as a service. In the service.msc settings, it was set to Log On as a Local System account, which set the USER_HOME variables to C:\Windows\System32. Because of this, the reason the error said that the file did not exist was because Jenkins/gradle did not have access to the System32 folder.
My fix was to change the log on method to 'This account', then enter a user account so Jenkins wasn't logged on as system anymore.

Building apk duplicate giving resources error

I am trying to build an apk file using android studio, and facing duplicated resources error
I have tried to delete some of duplicates but with no luck
[drawable-xhdpi-v4/assets_images_ic_share] /Users/hadi/Desktop/lancer/beonews/android/app/src/main/res/drawable-xhdpi/assets_images_ic_share.png [drawable-xhdpi-v4/assets_images_ic_share] /Users/hadi/Desktop/lancer/beonews/android/app/build/generated/res/react/release/drawable-xhdpi/assets_images_ic_share.png: Error: Duplicate resources
[drawable-xhdpi-v4/node_modules_reactnativedropdownalert_assets_error] /Users/hadi/Desktop/lancer/beonews/android/app/src/main/res/drawable-xhdpi/node_modules_reactnativedropdownalert_assets_error.png [drawable-xhdpi-v4/node_modules_reactnativedropdownalert_assets_error] /Users/hadi/Desktop/lancer/beonews/android/app/build/generated/res/react/release/drawable-xhdpi/node_modules_reactnativedropdownalert_assets_error.png: Error: Duplicate resources
[drawable-xhdpi-v4/assets_images_ic_favorite] /Users/hadi/Desktop/lancer/beonews/android/app/src/main/res/drawable-xhdpi/assets_images_ic_favorite.png [drawable-xhdpi-v4/assets_images_ic_favorite] /Users/hadi/Desktop/lancer/beonews/android/app/build/generated/res/react/release/drawable-xhdpi/assets_images_ic_favorite.png: Error: Duplicate resources
[drawable-xhdpi-v4/assets_images_ic_favorited] /Users/hadi/Desktop/lancer/beonews/android/app/src/main/res/drawable-xhdpi/assets_images_ic_favorited.png [drawable-xhdpi-v4/assets_images_ic_favorited] /Users/hadi/Desktop/lancer/beonews/android/app/build/generated/res/react/release/drawable-xhdpi/assets_images_ic_favorited.png: Error: Duplicate resources
[drawable-xhdpi-v4/assets_images_ic_success] /Users/hadi/Desktop/lancer/beonews/android/app/src/main/res/drawable-xhdpi/assets_images_ic_success.png [drawable-xhdpi-v4/assets_images_ic_success] /Users/hadi/Desktop/lancer/beonews/android/app/build/generated/res/react/release/drawable-xhdpi/assets_images_ic_success.png: Error: Duplicate resources
[drawable-xhdpi-v4/assets_images_ic_comment] /Users/hadi/Desktop/lancer/beonews/android/app/src/main/res/drawable-xhdpi/assets_images_ic_comment.png [drawable-xhdpi-v4/assets_images_ic_comment] /Users/hadi/Desktop/lancer/beonews/android/app/build/generated/res/react/release/drawable-xhdpi/assets_images_ic_comment.png: Error: Duplicate resources
[drawable-xhdpi-v4/node_modules_reactnativedropdownalert_assets_info] /Users/hadi/Desktop/lancer/beonews/android/app/src/main/res/drawable-xhdpi/node_modules_reactnativedropdownalert_assets_info.png [drawable-xhdpi-v4/node_modules_reactnativedropdownalert_assets_info] /Users/hadi/Desktop/lancer/beonews/android/app/build/generated/res/react/release/drawable-xhdpi/node_modules_reactnativedropdownalert_assets_info.png: Error: Duplicate resources
[drawable-xhdpi-v4/assets_images_ic_add_comment] /Users/hadi/Desktop/lancer/beonews/android/app/src/main/res/drawable-xhdpi/assets_images_ic_add_comment.png [drawable-xhdpi-v4/assets_images_ic_add_comment] /Users/hadi/Desktop/lancer/beonews/android/app/build/generated/res/react/release/drawable-xhdpi/assets_images_ic_add_comment.png: Error: Duplicate resources
[drawable-xhdpi-v4/assets_images_ic_white_more] /Users/hadi/Desktop/lancer/beonews/android/app/src/main/res/drawable-xhdpi/assets_images_ic_white_more.png [drawable-xhdpi-v4/assets_images_ic_white_more] /Users/hadi/Desktop/lancer/beonews/android/app/build/generated/res/react/release/drawable-xhdpi/assets_images_ic_white_more.png: Error: Duplicate resources

Error:(246, 5) error: duplicate value for resource 'attr/font' with config ''

I've tried all the techniques which were provided on stack overflow but I am still getting the same error. Even after modifying the name, when I am try rebuilding the gradle, again the same is being updated to the previous value and the error is being arose.
The error is :
Error:(246, 5) error: duplicate value for resource 'attr/font' with config ''

Android duplicate resources error

My project was compiling fine until I deleted some png drawables and replaced them with vector drawables by navigating to New > Vector Asset. I am now getting a duplicate resources error.
Here is my res folder:
Here is the error message in the Gradle console:
Execution failed for task ':app:mergeDebugResources'.
> [drawable/ic_menu_manage] /Users/tomfinet/AndroidStudioProjects/Birthpay/app/src/main/res/drawable/ic_menu_manage.xml [drawable/ic_menu_manage] /Users/tomfinet/AndroidStudioProjects/Birthpay/app/src/main/res/values/drawables.xml: Error: Duplicate resources
[drawable/ic_menu_share] /Users/tomfinet/AndroidStudioProjects/Birthpay/app/src/main/res/drawable/ic_menu_share.xml [drawable/ic_menu_share] /Users/tomfinet/AndroidStudioProjects/Birthpay/app/src/main/res/values/drawables.xml: Error: Duplicate resources
[drawable/ic_menu_slideshow] /Users/tomfinet/AndroidStudioProjects/Birthpay/app/src/main/res/drawable/ic_menu_slideshow.xml [drawable/ic_menu_slideshow] /Users/tomfinet/AndroidStudioProjects/Birthpay/app/src/main/res/values/drawables.xml: Error: Duplicate resources
[drawable/ic_menu_send] /Users/tomfinet/AndroidStudioProjects/Birthpay/app/src/main/res/drawable/ic_menu_send.xml [drawable/ic_menu_send] /Users/tomfinet/AndroidStudioProjects/Birthpay/app/src/main/res/values/drawables.xml: Error: Duplicate resources
[drawable/ic_menu_gallery] /Users/tomfinet/AndroidStudioProjects/Birthpay/app/src/main/res/drawable/ic_menu_gallery.xml [drawable/ic_menu_gallery] /Users/tomfinet/AndroidStudioProjects/Birthpay/app/src/main/res/values/drawables.xml: Error: Duplicate resources
[drawable/ic_menu_camera] /Users/tomfinet/AndroidStudioProjects/Birthpay/app/src/main/res/drawable/ic_menu_camera.xml [drawable/ic_menu_camera] /Users/tomfinet/AndroidStudioProjects/Birthpay/app/src/main/res/values/drawables.xml: Error: Duplicate resources
How do I fix this and why is it happening?
The error suggests that the drawable.xml file is responsible for the error. So I opened it and commented out the xml code and the app ran fine. I have no idea why this fixes it but this solved the problem.
when we add some new thing in out project, in that case some times resources might get duplicate that time it will give the error while run the app, in my case also get same issue I had face, while I had added the kotlin activity in java project, in it gives me error
Execution failed for task ':app:mergeDebugResources'. ...\themes.xml: Error: Duplicate resources
so in this case please check the local history and remove the duplicate resources from res folder, so simply revert that changes
To revert changes click on res folder and go to local history and check the duplicate file name and revert that changes which was not present in running code
in my case there was \themes.xml file is added newly so I reverted that changes and run code, it run successfully

Duplicate Resources

I am trying to build my Android app and am recieving this error:
Error:Error: Duplicate resources: /Users/Mike/Documents/beerPortfolio/beerportfoliov3/BeerPprtfolio/src/main/res/values/dimens_orange.xml:dimen/tab_host_default_height, /Users/Mike/Documents/beerPortfolio/beerportfoliov3/BeerPprtfolio/src/main/res/values/dimens_finalbeertheme.xml:dimen/tab_host_default_height
And also this error:
Error:Execution failed for task ':BeerPprtfolio:mergeDebugResources'.
> /Users/Mike/Documents/beerPortfolio/beerportfoliov3/BeerPprtfolio/src/main/res/values/dimens_orange.xml: Error: Duplicate resources: /Users/Mike/Documents/beerPortfolio/beerportfoliov3/BeerPprtfolio/src/main/res/values/dimens_orange.xml:dimen/tab_host_default_height, /Users/Mike/Documents/beerPortfolio/beerportfoliov3/BeerPprtfolio/src/main/res/values/dimens_finalbeertheme.xml:dimen/tab_host_default_height
This is after trying to import a custom theme from Android Holo Colors.
You must eliminate one of dimen/tab_host_default_height in your dimens_orange.xml or dimens_finalbeertheme.xml, because they are duplicate.
Check your error "Error: Duplicate resources:"

Categories

Resources