Skip to content
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

Conversation

mikehardy
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

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!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 18, 2019
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@mikehardy
Copy link
Contributor Author

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.

Copy link
Contributor

@cpojer cpojer left a 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.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label May 9, 2019
@facebook-github-bot
Copy link
Contributor

@cpojer merged this pull request in 962437f.

facebook-github-bot pushed a commit that referenced this pull request May 9, 2019
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
@turnrye
Copy link
Contributor

turnrye commented Jun 2, 2019

Thank you for this fix @mikehardy !

facebook-github-bot pushed a commit that referenced this pull request Jun 24, 2019
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
kelset pushed a commit that referenced this pull request Jun 28, 2019
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
M-i-k-e-l pushed a commit to M-i-k-e-l/react-native that referenced this pull request Mar 10, 2020
…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
@mikehardy mikehardy deleted the issue-22234/android-release-duplicate-resources branch April 27, 2020 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Sony Partner: Sony Partner Platform: Android Android applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants