-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix error: CodePushHash: Resource and asset merger: Duplicate resources #2574
Conversation
fixed: Duplicate resources on build release
When it will be reviewed? |
In my case adding this patch is not actually fixes subsequent builds. This workaround fixes the issue ./gradlew bundleRelease
rm -rf app/build/generated
gradlew assembleRelease |
Yeah, I have found the same thing. The Duplicate resources error still happens with this patch, but simply re-running the build will fix it when it happens. |
@XantreGodlike , am I right that the fix in this PR doesn't work for you? |
@DmitriyKirakosyan yep ./gradlew bundleRelease
rm -rf app/build/generated
./gradlew assembleRelease |
@DmitriyKirakosyan the changes here seem to improve things, but it doesn't fix the problem completely. To test, I just cleaned the Android project completely and rebuilt. It worked successfully. Then I did a subsequent build, which is incremental, and it failed with the usual So, I do think this change may improve things, but it definitely doesn't solve it definitively. |
What things does it improve ? It either fixes the problem or not. Tested once again on my: MacBook Pro M2 (macos Ventura 13.5) Guys how did you test this PR ? How do you know that it is now working ? |
I'm just applying this patch, but susequent builds is not working diff --git a/scripts/generateBundledResourcesHash.js b/scripts/generateBundledResourcesHash.js
index 01ab70ca51e274eeedc22a03d0b1416280d9b0ce..8bd21491020eae7c4d772925ee08cbc6098fb09f 100644
--- a/scripts/generateBundledResourcesHash.js
+++ b/scripts/generateBundledResourcesHash.js
@@ -78,6 +78,9 @@ function addJsBundleAndMetaToManifest() {
console.log(finalHash);
var savedResourcesManifestPath = assetsDir + "/" + CODE_PUSH_HASH_FILE_NAME;
+ if (fs.existsSync(savedResourcesManifestPath)) {
+ fs.unlinkSync(savedResourcesManifestPath);
+ }
fs.writeFileSync(savedResourcesManifestPath, finalHash);
// "CodePushHash.json" file name breaks flow type checking |
@XantreGodlike Also what version of
What are you doing with this script ? Its generates you a bundle ( .aab file ). After you delete the I executed ./gradlew bundleRelease
./gradlew assembleRelease
./gradlew bundleRelease
./gradlew assembleRelease |
@sanduluca I typically run a variation of I'm able to reproduce the exact same pattern if I run This is the error:
I tried removing this patch and confirmed the exact same behavior, so it does appear the patch here makes no difference for our case. |
Still an issue on 0.72.5 |
Can you guys paste here your error as you may have other Also anyone confirmed that this patch fixed the |
@sanduluca I did some more testing here. The issue seems to be caused purely by
I've also tested it with different flavors (
|
@brianlenz, thank you for delving into this issue. To ensure I'm following correctly:
For further clarity, have you tried replicating this issue in a freshly created project? This step could help pinpoint the root cause more precisely. |
I just test in a freshly created RN project, and I could not reproduce the "Duplicate resources" issue at all. This was a test without the changes from this PR. I simply used this to test:
So then I decided to enable Android flavors (which is what we use in our project). To do this, I simply did:
Once I did that, the behavior reproduces exactly as I've described above. Run Then, to test this patch, I ran:
Then, simply run:
And you'll get the exact same behavior and error. Here is the full log output:
Run |
@brianlenz, thanks for confirming and providing more details. @sanduluca, can you please review @brianlenz's case and see if it can be addressed in your PR? |
when are we planning to merge this |
I'm just applying this patch and it's working. |
Let's wait for @sanduluca to address all issues before reviewing/merging. |
I am currently working on the "react-native": "0.71.2" version of react native and I am having this same bug. It hasn't been solved yet, right? |
This patch doesn't work for me neither. My fix for now is to run a script before each android build that remove the concerned hash file I can't wait to get this fixed |
Ok, so I finally got some time for debuging. I will say first, I dont have a solution for now, but I will write what I noticed. As @brianlenz says, the strangest thing is that we get the error after the second run after a ./gradlew clean
./gradlew bundleDevRelease
./gradlew bundleDevRelease # <-- this will fail
./gradlew bundleDevRelease # <-- this and next runs will succeed
... Analyzing the commit history and the codepush.gradle file found out this PR #2204. I tried to revert the changes it introduced and found out that I fixed the error (at least for me 😅). If you wonder doesn't reverting this PR will reintroduce the issues it aimed to solve, the answer is : I don't know. But analyzing the issues activity (from that PR), it seems there are still developers that encounter problems Here is the patch-package for diff --git a/node_modules/react-native-code-push/android/codepush.gradle b/node_modules/react-native-code-push/android/codepush.gradle
index a0f9d27..f234206 100644
--- a/node_modules/react-native-code-push/android/codepush.gradle
+++ b/node_modules/react-native-code-push/android/codepush.gradle
@@ -68,9 +68,6 @@ gradle.projectsEvaluated {
enabled !debuggableVariants.contains(variant.name) ?: targetName.toLowerCase().contains("release")
}
-
- runBefore("merge${targetName}Resources", generateBundledResourcesHash)
- runBefore("merge${targetName}Assets", generateBundledResourcesHash)
} else {
def jsBundleDirConfigName = "jsBundleDir${targetName}"
jsBundleDir = elvisFile(config."$jsBundleDirConfigName").get() ?: |
@sanduluca sorry for the delay! I finally got around to testing this. The issue still exists (unsurprisingly) in
This change does seem to have affected the behavior, but it doesn't look like it fully fixes it. Now, running the bundle ./gradlew clean
./gradlew bundleDevDebug
./gradlew bundleDevDebug # <-- this breaks in 8.2.1, but NOT with the above patch
./gradlew bundleDevDebug # <-- still works. run multiple more times without issue. The scenario that doesn't work for me still is when running ./gradlew clean
yarn react-native run-android --mode=DevDebug --appIdSuffix dev
yarn react-native run-android --mode=DevDebug --appIdSuffix dev # <-- this fails still! Here's the error when run a second time in that way:
The difference is that it's running ./gradlew clean
./gradlew installDevDebug
./gradlew installDevDebug # <-- fails!
./gradlew installDevDebug # <-- succeeds! So, it seems that reverting #2204 doesn't solve the problem; it just modifies the behavior a bit. |
for hotfix: full cleaning will increase next build time significanlty. |
Does this issue affect not debug build? |
Any update on this? |
#2697 is merged. So closing this PR. |
Delete file before create & write
Solves #2497