Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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. [Android] [Fixed] - Fix duplicate resource error in Android build Pull Request resolved: #24518 Differential Revision: D15276981 Pulled By: cpojer fbshipit-source-id: 3fe8c8556e4dcdac5f96a2d4658ac9b5d9b67379
- Loading branch information
962437f
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.
@mikehardy I have RN 0.63.2 but can't see this change. not merged yet? cause I am still seeing the duplicate resource errors.
962437f
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.
@co-de you are missing some context!
:app:mergeReleaseResources
in 0.60.0-rc.1 #25325962437f
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.
@mikehardy oh.. thanks for pointing this out. And thanks for lightning fast reply.
I came here directly from your comment in this SO post: https://stackoverflow.com/questions/53239705/react-native-error-duplicate-resources-android/53260522
That is why I was missing all the discussions around the fix. Sorry about that..
I added the lines below to my build.gradle (app)
Then ran this command:
ORG_GRADLE_PROJECT_bundleInDevDebug=false npx react-native run-android --variant=release
But unfortunately, I am still getting the duplicate resources errors.
Am I missing something obvious & easy :( ?
962437f
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.
All I can say is look very critically at the commands and variables proposed, they are not one size fits all, you'll need to understand what each is doing and why, and what it should be in your project
You may also need to flush everything out first
npx react-native-clean-project
962437f
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.
Thanks, Mike. So from your comments, I understand that contrary to what most people are trying to do (copying the drawable* folders from under "generated" to under "src" with a doLast method inside react.gradle) drawable* folders should not exist under "src/main/res" in the first place. Is that correct?
962437f
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.
everything should be in src, including drawables if you have them (your icons, perhaps, but not things from other modules)
nothing should be manually copied
gradle can do all the work needed if called correctly
I recognize all that is oblique / vague / etc - but the main point is that manual copying is a "smell" - if you are doing that something is wrong. It might work for a while, it might get you moving for now, but something is wrong
962437f
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.
@co-de Did you find any fix for this? I am into same problem
962437f
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.
Why cannot push these code to the repo? the react team didn't fix the bug, let the bug exist in today?
962437f
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.
@VesperHan First check whether the problem occurs while running in debug also, if that happens there might be a chance that somebody mistakenly pushed some generated assets and since its is getting generated again while building so throwing the error.
If this happens in only release not debug just check whether you are bundling separately and then then doing assemblerelease with the bundleInRelease flag set to true in your build.gradle. If that's the case just don't bundle because the bundling task is automatically done by react.gradle file.
962437f
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.
@VesperHan - your comment is unfortunately full of assumptions, all wrong:
There was code pushed to the repo. It turned out to be the wrong solution. It was reverted. Pushing code to a repo is not the issue here
There is no bug. Your project is doing something wrong. I learned this the very hard way (this was my commit, and it was the wrong solution), you can follow the comments above. You have a project-specific thing to fix, there is no bug and there will be no "fix" here I don't think
962437f
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.
@mikehardy Right dude, I had the exact same problem but after a long troubleshooting and digging the old PRs I came to know that this problem occured the last time also when RN Upgrade was done and somebody wrote a script to patch react.gradle to copy assets at one place. What they failed to realise that new react native version introduced react.gradle which will automatically bundle and generate assets based on flag bundleInRelease in build.gradle which was set to true. So I stopped bundling separately and just did assembleRelease and the build worked like charm.
Also I was getting the same issue in debug mode before facing in release build so I just noted down the duplicate assets and deleted them from the project.