React-native: [Android] Unable to use files with the same name as resources in release builds

Created on 21 Nov 2017  路  4Comments  路  Source: facebook/react-native

Is this a bug report?

(write your answer here)

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment:
OS: macOS Sierra 10.12.6
Node: 7.9.0
Yarn: Not Found
npm: 4.5.0
Watchman: 4.7.0
Xcode: Xcode 9.0.1 Build version 9A1004
Android Studio: 2.3 AI-162.3871768

Packages: (wanted => installed)
react: 16.0.0-beta.5 => 16.0.0-beta.5
react-native: 0.49.3 => 0.49.3

Steps to Reproduce

  1. Create a new React Native project via react-native init
  2. Copy 2 assets to your project with the same name but different extensions (in our case, it was male_02.obj and male_02.mtl). The easiest is to find a png and a jpg and name them the same.
  3. From the JS file, require both files (ie. require("./test_image.png") and require("./test_image.jpg")
  4. Perform a release build for Android

Expected Behavior

Both files are loaded into the app bundle and accessible by the application

Actual Behavior

Get an error complaining that the resource entry is already defined:

res/drawable-mdpi-v4/js_res_male02.obj:0: error: Resource entry js_res_male02 is already defined.
res/drawable-mdpi-v4/js_res_male02.mtl:0: Originally defined here.

This is because React Native copies resources into Android's res directory vs assets and it seems like the res directory ignores file extensions. Seems to me there are two ways around this, encode file extensions into the resource name or (ie. js_res_male_obj) or move to assets.

iOS release builds do not have this issue. Also if I rename male02.obj to male02_model.obj then it works just fine. However this presents a more annoying issue when my obj/fbx model has multiple materials/textures with the same name (but different extensions).

Full gradle output:

~/third-workspace/TestPackage/android$ ./gradlew assembleGvrRelease
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preGvrReleaseBuild UP-TO-DATE
:app:checkGvrReleaseManifest
:app:preGvrDebugBuild UP-TO-DATE
:app:preOvrDebugBuild UP-TO-DATE
:app:preOvrReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2500Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72500Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCompat2500Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCoreUi2500Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCoreUtils2500Library UP-TO-DATE
:app:prepareComAndroidSupportSupportFragment2500Library UP-TO-DATE
:app:prepareComAndroidSupportSupportMediaCompat2500Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42500Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2500Library UP-TO-DATE
:app:prepareComFacebookFbuiTextlayoutbuilderTextlayoutbuilder100Library UP-TO-DATE
:app:prepareComFacebookFrescoDrawee130Library UP-TO-DATE
:app:prepareComFacebookFrescoFbcore130Library UP-TO-DATE
:app:prepareComFacebookFrescoFresco130Library UP-TO-DATE
:app:prepareComFacebookFrescoImagepipeline130Library UP-TO-DATE
:app:prepareComFacebookFrescoImagepipelineBase130Library UP-TO-DATE
:app:prepareComFacebookFrescoImagepipelineOkhttp3130Library UP-TO-DATE
:app:prepareComFacebookReactReactNative0493Library UP-TO-DATE
:app:prepareComFacebookSoloaderSoloader010Library UP-TO-DATE
:app:prepareComGoogleAndroidExoplayerExoplayerR220Library UP-TO-DATE
:app:prepareOrgWebkitAndroidJscR174650Library UP-TO-DATE
:app:prepareTestPackageArcore_clientUnspecifiedLibrary UP-TO-DATE
:app:prepareTestPackageGvr_commonUnspecifiedLibrary UP-TO-DATE
:app:prepareTestPackageReact_viroUnspecifiedLibrary UP-TO-DATE
:app:prepareTestPackageViro_rendererUnspecifiedLibrary UP-TO-DATE
:app:prepareGvrReleaseDependencies
:app:compileGvrReleaseAidl
:app:compileGvrReleaseRenderscript UP-TO-DATE
:app:generateGvrReleaseBuildConfig
:app:mergeGvrReleaseShaders UP-TO-DATE
:app:compileGvrReleaseShaders UP-TO-DATE
:app:generateGvrReleaseAssets UP-TO-DATE
:app:mergeGvrReleaseAssets UP-TO-DATE
:app:generateGvrReleaseResValues UP-TO-DATE
:app:generateGvrReleaseResources UP-TO-DATE
:app:mergeGvrReleaseResources UP-TO-DATE
:app:bundleGvrReleaseJsAndAssets
Loading dependency graph, done.
warning: the transform cache was reset.
bundle: start
bundle: finish
bundle: Writing bundle output to: /Users/andychu/third-workspace/TestPackage/android/app/build/intermediates/assets/gvr/release/index.android.bundle
bundle: Done writing bundle output
bundle: Copying 8 asset files
bundle: Done copying assets
:app:processGvrReleaseManifest
:app:processGvrReleaseResources
res/drawable-mdpi-v4/js_res_male02.obj:0: error: Resource entry js_res_male02 is already defined.
res/drawable-mdpi-v4/js_res_male02.mtl:0: Originally defined here.


:app:processGvrReleaseResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processGvrReleaseResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

* 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: 27.808 secs

Reproducible Demo

If need be, I can provide one, but the repro instructions above are pretty simple.

Stale

Most helpful comment

What I did to fix it is:
1.- Rename the files with different names
2.- Clean your android project running:

cd android && ./gradlew clean

All 4 comments

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

same error here !.
With png and jpg images with the same name.

What I did to fix it is:
1.- Rename the files with different names
2.- Clean your android project running:

cd android && ./gradlew clean

@sejas I did the same thing because i was tired of having this issue and not a single command line to solve it automaticly

Was this page helpful?
0 / 5 - 0 ratings

Related issues

grabbou picture grabbou  路  3Comments

TrakBit picture TrakBit  路  3Comments

jlongster picture jlongster  路  3Comments

janmonschke picture janmonschke  路  3Comments

josev55 picture josev55  路  3Comments