react-native-code-push
react-native-code-push copied to clipboard
Code Push 8.0.0/RN 0.71.6 - StackOverflowError CodePushHash: Resource and asset merger: Duplicate resources
Thanks so much for filing an issue or feature request! Please fill out the following (wherever relevant): Recently we have changed react native version from 0.70 -> 0.71. Code push support for react native 0.71.6 is 8.0.0. Since then whenever changes we do in native code, we are getting below errors.
To fix this, for every native android code change we have to do ./gradlew clean and then use react-native run android to fix this issue. This is very very time consuming.
Steps to Reproduce
- Do any change in android native and run the app using react-native run android
- This issue we can reproduce
Expected Behavior
What you expected to happen?
Actual Behavior
What actually happens?
ERROR:/Users/dev/Documents/Projects/React Native/mytakeaway2.0/android/app/build/ASSETS/createBundleFusionDebugJsAndAssets/CodePushHash /Users/dev/Documents/Projects/React Native/mytakeaway2.0/android/app/build/ASSETS/createBundleFusionDebugJsAndAssets/CodePushHash: Resource and asset merger: Duplicate resources
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:mergeFusionDebugAssets'.
> /Users/dev/Documents/Projects/React Native/mytakeaway2.0/android/app/build/ASSETS/createBundleFusionDebugJsAndAssets/CodePushHash /Users/dev/Documents/Projects/React Native/mytakeaway2.0/android/app/build/ASSETS/createBundleFusionDebugJsAndAssets/CodePushHash: Error: Duplicate resources
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
java.lang.StackOverflowError (no error message)
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================
* Get more help at https://help.gradle.org
BUILD FAILED in 26s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installFusionDebug -PreactNativeDevServerPort=8081
ERROR:/Users/dev/Documents/Projects/React Native/mytakeaway2.0/android/app/build/ASSETS/createBundleFusionDebugJsAndAssets/CodePushHash /Users/dev/Documents/Projects/React Native/mytakeaway2.0/android/app/build/ASSETS/createBundleFusionDebugJsAndAssets/CodePushHash: Resource and asset merger: Duplicate resources
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:mergeFusionDebugAssets'.
> /Users/dev/Documents/Projects/React Native/mytakeaway2.0/android/app/build/ASSETS/createBundleFusionDebugJsAndAssets/CodePushHash /Users/dev/Documents/Projects/React Native/mytakeaway2.0/android/app/build/ASSETS/createBundleFusionDebugJsAndAssets/CodePushHash: Error: Duplicate resources
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
java.lang.StackOverflowError (no error message)
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================
* Get more help at https://help.gradle.org
BUILD FAILED in 26s
at makeError (/Users/dev/Documents/Projects/React Native/mytakeaway2.0/node_modules/execa/index.js:174:9)
at /Users/dev/Documents/Projects/React Native/mytakeaway2.0/node_modules/execa/index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async runOnAllDevices (/Users/dev/Documents/Projects/React Native/mytakeaway2.0/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:82:7)
at async Command.handleAction (/Users/dev/Documents/Projects/React Native/mytakeaway2.0/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:108:9)
info Run CLI with --verbose flag for more details.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] f: `ENVFILE=.env.Fusion react-native run-android --variant=fusionDebug`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] f script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/dev/.npm/_logs/2023-04-19T04_19_01_828Z-debug.log
Environment
- react-native-code-push version: 8.0.0
- react-native version: 0.71.6
- iOS/Android/Windows version: 11
- Does this reproduce on a debug build or release build? Debug build
- Does this reproduce on a simulator, or only on a physical device? Physical device
(The more info the faster we will be able to address it!)
Having the same issue after upgrading from 7.0.4 to 8.0.1 as well on RN 71
This problem is ocurring to me every time I trying to run react-native run-android --variant release. I have to run ./gradlew assembleRelease and install the APK with ADB.
No problem with the development command (react-native run-android).
I had the same problem, but this resolved it for me:
- Open Android Studio
- Open your app android folder
- Click on
File > Invalidate Caches
- Select all options in
Invalidate Caches
then click onInvalidate and Restart
button - Wait Android Studio to load all informations
- Run
react-native run android
again
I only ran into this issue when I tried to assemble a release build. rm -rf ~/.gradle/caches
did not fix it.
having same issue, tried everything suggested here it's not working
having same issue, tried everything suggested here it's not working
try react-native run-android --tasks clean,installDebug
or cd android && ./gradlew clean
.
But these are just workarounds, need react-native-code-push delete the Duplicate resources in new version.
Any update regarding the fix by react-native-code-push
team ?
I am the same issue, there still not have the solution
Updating to version 8.0.2 while running react native 0.71.11 seems to have fixed the issue for me.
edit:
it did not fix the duplicate resource issue
same here, also tried upgrading to latest release (8.0.2) but whenever I clean and build twice the second build breaks with the same log
CodePushHash: Resource and asset merger: Duplicate resources
Have the same problem. It works for me if I run ./gradlew clean
before each build.
What is the solution to this? @geof90
Any solution for this issue?
As others have mentioned, it works if you run ./gradlew clean
(in android folder) before each build.
So at least there's a temporary fix for this.
Created a PR for this issue. Waiting for some maintainers to code review, approve, merge and release.
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
having same issue, tried everything suggested here it's not working
try
react-native run-android --tasks clean,installDebug
orcd android && ./gradlew clean
. But these are just workarounds, need react-native-code-push delete the Duplicate resources in new version.
This trick worked for me.
Any update on this team ?
Hi everyone, I'd recommend not cleaning your gradle cache for each build if you're just developing as that'll increase your build time. You can simply delete the CodePushHash file and run the app again. The CodePushHash file will be generated again. Try this instead..
Important - Below is just my path to the file. You will need to update the part createBundleStgDebugJsAndAssets
depending on names of your flavours etc.. You can look at the path of the duplicated file and it'll tell you what to put here. In Android studio you can just copy the absolute file path of the offending file.
rm ./android/app/build/generated/assets/createBundleStgDebugJsAndAssets/CodePushHash
Hi everyone, I'd recommend not cleaning your gradle cache for each build if you're just developing as that'll increase your build time. You can simply delete the CodePushHash file and run the app again. The CodePushHash file will be generated again. Try this instead..
Important - Below is just my path to the file. You will need to update the part
createBundleStgDebugJsAndAssets
depending on names of your flavours etc.. You can look at the path of the duplicated file and it'll tell you what to put here. In Android studio you can just copy the absolute file path of the offending file.rm ./android/app/build/generated/assets/createBundleStgDebugJsAndAssets/CodePushHash
This doesn't work for me. My situation is the same as what described here:
https://github.com/microsoft/react-native-code-push/pull/2574#issuecomment-1900284369
After a gradlew clean, the second time we run a assemble/bundle command will fail with the error. And third and next runs become OK again.
And delete the CodePushHash file before the assemble/bundle does not prevent the error on second run.
@howg0924 I had to test a build with different settings a while ago, and from the history (and my memory) I can confirm that, at least on my side, deleting the hash works... it weird yours is passing on the third try, are you sure you're deleting the correct one for the flavor you're building?
@howg0924 , you mentioned the comment with a workaround. Can you confirm the workaround works for you?
Facing the same issue
same issue I am using
- RN 0.73.5
- "react-native-code-push": "^8.2.1",
Any idea if the fix @sanduluca created is still valid (PR has been open for ages) and if there will be fix for this. Right now doing ./gradlew clean before each build. There is also deleting just the CodePushHash file, but still needs manual work, so would be great if this would be fixed.
- "react-native": "0.73.4",
- "react-native-code-push": "^8.2.1",
@Jonnboy91, I'd like to ask the same of you. Could you please check if the PR functions correctly in your environment? According to the discussion within the PR, it seems to work selectively. I'm thinking of approving and merging it since it doesn't seem to cause any problems, even if it doesn't help everyone.
We patched that PR into our project last year and have not had any issues since.
@DmitriyKirakosyan I don't mean to be difficult, but I'd like to push back a little bit on the idea of merging the PR because it doesn't make anything worse. I provided a minimal reproduction with a brand new React Native app that shows the behavior is the same with and without the changes in the PR. I haven't seen evidence showing it actually fixes the problem, so I'm not sure why it should be merged? If someone can provide a minimal reproduction that shows improvement, at least it would give some evidence that there is any improvement (anecdotal evidence without a reproduction isn't very helpful in this case, unfortunately).
I've invested quite a bit of time into testing and providing the minimal reproduction, so I'd rather we wait for a proper fix rather than blindly merging changes that help minimally, if at all?
I've been following this thread for a while as this issue was impacting me. I work around it by using the gradlew clean
, but that's obviously not ideal for build times. All that to say I'm not just swooping in as a random with zero context when I make this comment:
In this case, I have to side with @brianlenz. I don't tend to like fixes unless I can understand why it's solving the problem, otherwise it's "mystery code". I just took a look at the PR and I don't see how it would resolve the issue: it deletes the resources file if it exists, prior to writing it. writeFileSync
automatically truncates the existing file when writing the new content. The only impact deletion prior to write would have is resetting the metadata and permissions of the file. Unless I missed something, the code only utilizes the content of the file, never its metadata, so that should be irrelevant. The fact that the patch has worked for some is likely coincidence.
I'm not currently able to check on my work computer, but for us the problem has actually stopped occuring for some reason 😅 So all good atm and we still have the same version that was release in January, so not exactly sure what has happened or if this is just some issue that happens in some situations (like running/building staging and production or something like that).
But yeah I would agree with @fergusean & @brianlenz that a fix that works selectively isn't really a fix and could just be unneccessary to do if it just seems to happen sometimes. Since I had this happening constantly at one point, but now for the last week or so it has worked without any issues.