-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix duplicate resource error in Android gradle build (#22234) #24518
Fix duplicate resource error in Android gradle build (#22234) #24518
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
The failed results on test_android do not seem to be related to the PR in any way? In fact I'm not sure gradle was used at any point so I'm not sure the CI was relevant unfortunately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's ship it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: If `$buildDir/generated/res/react/${flavorPathSegment}release/raw` contains files during `gradle assembleRelease` script will fail with `Error: Duplicate resources` error. This patch is based on this issue [22234](#22234) and pull request [24518](#24518). [Android] [Fixed] - Fix duplicate resource error for raw folder in Android build [CC from Mike Hardy PR] Reports of success on the linked issue via use of the patch + patch-package for a couple months, I personally use it full time with all gradle builds (./gradlew clean assembleRelease or if you have a 'staging' flavor, e.g. ./gradlew clean assembleStagingRelease) Related reading, also cross-links with the linked issue here: https://stackoverflow.com/questions/53239705/react-native-error-duplicate-resources-android Pull Request resolved: #24778 Differential Revision: D15277766 Pulled By: cpojer fbshipit-source-id: 0ccd76d2aa2e13f7c8bfac07d4ef23b74945807a
Thank you for this fix @mikehardy ! |
Summary: Pull requests #24518 #24778 make Gradle copy all **generated** assets and resources into `android/app/src/res`, which is a bad behavior, because `src/res` goes into version control and should hold only those **original** resource files. These changes in #24518 #24778 were merged into 0.60.0-rc release and cause regression. This pull request will: - Revert pull requests #24518 #24778 - Close #25325 ## Changelog [Android] [Fixed] - Fix regression of improper assets copy (revert #24518 #24778) Pull Request resolved: #25363 Test Plan: It is a revert pull request and the reverted script should work the same as it has in 0.59.x. Differential Revision: D15963329 Pulled By: cpojer fbshipit-source-id: 5619a318dbdb40e816e37b6e37d4fe32caa46e9e
Summary: Pull requests #24518 #24778 make Gradle copy all **generated** assets and resources into `android/app/src/res`, which is a bad behavior, because `src/res` goes into version control and should hold only those **original** resource files. These changes in #24518 #24778 were merged into 0.60.0-rc release and cause regression. This pull request will: - Revert pull requests #24518 #24778 - Close #25325 ## Changelog [Android] [Fixed] - Fix regression of improper assets copy (revert #24518 #24778) Pull Request resolved: #25363 Test Plan: It is a revert pull request and the reverted script should work the same as it has in 0.59.x. Differential Revision: D15963329 Pulled By: cpojer fbshipit-source-id: 5619a318dbdb40e816e37b6e37d4fe32caa46e9e
…k#24778) (facebook#25363) Summary: Pull requests facebook#24518 facebook#24778 make Gradle copy all **generated** assets and resources into `android/app/src/res`, which is a bad behavior, because `src/res` goes into version control and should hold only those **original** resource files. These changes in facebook#24518 facebook#24778 were merged into 0.60.0-rc release and cause regression. This pull request will: - Revert pull requests facebook#24518 facebook#24778 - Close facebook#25325 ## Changelog [Android] [Fixed] - Fix regression of improper assets copy (revert facebook#24518 facebook#24778) Pull Request resolved: facebook#25363 Test Plan: It is a revert pull request and the reverted script should work the same as it has in 0.59.x. Differential Revision: D15963329 Pulled By: cpojer fbshipit-source-id: 5619a318dbdb40e816e37b6e37d4fe32caa46e9e
Summary
Issue #22234 includes a number of people (myself included) suffering with duplicate resource errors while building in Android. We have been collectively using a patch there but I don't believe any attempt has been made to PR it upstream.
I am not excellent at gradle, so I may have approached this in completely the wrong way, but it works for me in the standard init templates, as well as my current work project which has a complicated 2 buildType + 4 productFlavor configuration. If there is a better way to achieve the result I am happy to learn
The approach here is to determine the generated path the resources land in, then move them into the main build output tree. If they remain in the generated path android merging fails with duplicate resource errors, so that move (vs copy) is important.
Changelog
[Android] [Fixed] - Fix duplicate resource error in Android build
Test Plan
Reports of success on the linked issue via use of the patch + patch-package for a couple months, I personally use it full time with all gradle builds (
./gradlew clean assembleRelease
or if you have a 'staging' flavor, e.g../gradlew clean assembleStagingRelease
)Related reading, also cross-links with the linked issue here:
https://stackoverflow.com/questions/53239705/react-native-error-duplicate-resources-android