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

Code Push 8.0.0/RN 0.71.6 - StackOverflowError CodePushHash: Resource and asset merger: Duplicate resources #2497

Closed
arunshankart2s opened this issue Apr 19, 2023 · 31 comments · Fixed by #2697

Comments

@arunshankart2s
Copy link

arunshankart2s commented Apr 19, 2023

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

  1. Do any change in android native and run the app using react-native run android
  2. 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!)

@arunshankart2s arunshankart2s changed the title RN 0.71 - StackOverflowError CodePushHash: Resource and asset merger: Duplicate resources Code Push 8.0.0/RN 0.71.6 - StackOverflowError CodePushHash: Resource and asset merger: Duplicate resources Apr 19, 2023
@phatmovista
Copy link

Having the same issue after upgrading from 7.0.4 to 8.0.1 as well on RN 71

@alcidesbsilvaneto
Copy link

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).

@RalissonMattias
Copy link

I had the same problem, but this resolved it for me:

  1. Open Android Studio
  2. Open your app android folder
  3. Click on File > Invalidate Caches
  4. Select all options in Invalidate Caches then click on Invalidate and Restart button
  5. Wait Android Studio to load all informations
  6. Run react-native run android again

@jpaas
Copy link

jpaas commented May 18, 2023

I only ran into this issue when I tried to assemble a release build. rm -rf ~/.gradle/caches did not fix it.

@OsaedYahyaCoretava
Copy link

having same issue, tried everything suggested here it's not working

@account-mhj
Copy link

account-mhj commented Jun 7, 2023

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.

@sagar-tomar-groww
Copy link

Any update regarding the fix by react-native-code-push team ?

@wogno
Copy link

wogno commented Jun 16, 2023

I am the same issue, there still not have the solution

@dulu93
Copy link

dulu93 commented Jun 20, 2023

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

@Grohden
Copy link

Grohden commented Jun 22, 2023

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

@Jlexyc
Copy link

Jlexyc commented Jun 26, 2023

Have the same problem. It works for me if I run ./gradlew clean before each build.

@jobinabraham
Copy link

jobinabraham commented Jun 28, 2023

What is the solution to this? @geof90

@Neha-Housing
Copy link

Any solution for this issue?

@Dror-Bar
Copy link

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.

@sanduluca
Copy link

sanduluca commented Aug 25, 2023

Created a PR for this issue. Waiting for some maintainers to code review, approve, merge and release.

@XantreDev
Copy link

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

@Danushka96
Copy link

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.

This trick worked for me.

@sagar-tomar-groww
Copy link

Any update on this team ?

@cam-shaw
Copy link

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

@howg0924
Copy link

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:

#2574 (comment)

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.

@Grohden
Copy link

Grohden commented Feb 1, 2024

@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?

image

@DmitriyKirakosyan
Copy link
Contributor

@howg0924 , you mentioned the comment with a workaround. Can you confirm the workaround works for you?

@rifad4u
Copy link

rifad4u commented Feb 19, 2024

Facing the same issue

@rezaarifian
Copy link

same issue I am using

  • RN 0.73.5
  • "react-native-code-push": "^8.2.1",

@Jonnboy91
Copy link

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",

@DmitriyKirakosyan
Copy link
Contributor

@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.

@mmmoussa
Copy link

We patched that PR into our project last year and have not had any issues since.

@brianlenz
Copy link

@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?

@fergusean
Copy link

fergusean commented Mar 28, 2024

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.

@Jonnboy91
Copy link

Jonnboy91 commented Mar 28, 2024

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.

bestander added a commit to bestander/react-native-code-push that referenced this issue May 7, 2024
@bestander
Copy link
Contributor

bestander commented May 7, 2024

This change fixed this issue in my project, does not require calling gradle clean anymore.

DmitriyKirakosyan pushed a commit that referenced this issue Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.