react-native-code-push icon indicating copy to clipboard operation
react-native-code-push copied to clipboard

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

Open arunshankart2s opened this issue 1 year ago • 31 comments

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 avatar Apr 19 '23 04:04 arunshankart2s

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

phatmovista avatar May 03 '23 18:05 phatmovista

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

alcidesbsilvaneto avatar May 05 '23 14:05 alcidesbsilvaneto

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

RalissonMattias avatar May 06 '23 20:05 RalissonMattias

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

jpaas avatar May 18 '23 15:05 jpaas

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

OsaedYahyaCoretava avatar Jun 07 '23 06:06 OsaedYahyaCoretava

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.

account-mhj avatar Jun 07 '23 06:06 account-mhj

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

sagar-tomar-groww avatar Jun 15 '23 03:06 sagar-tomar-groww

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

wogno avatar Jun 16 '23 11:06 wogno

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

dulu93 avatar Jun 20 '23 11:06 dulu93

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

Grohden avatar Jun 22 '23 21:06 Grohden

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

Jlexyc avatar Jun 26 '23 10:06 Jlexyc

What is the solution to this? @geof90

jobinabraham avatar Jun 28 '23 08:06 jobinabraham

Any solution for this issue?

Neha-Housing avatar Jul 19 '23 09:07 Neha-Housing

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.

Dror-Bar avatar Aug 23 '23 18:08 Dror-Bar

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

sanduluca avatar Aug 25 '23 11:08 sanduluca

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

XantreDev avatar Sep 11 '23 08:09 XantreDev

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.

Danushka96 avatar Oct 12 '23 13:10 Danushka96

Any update on this team ?

sagar-tomar-groww avatar Jan 18 '24 16:01 sagar-tomar-groww

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

cam-shaw avatar Jan 18 '24 22:01 cam-shaw

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 avatar Jan 24 '24 13:01 howg0924

@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

Grohden avatar Feb 01 '24 12:02 Grohden

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

DmitriyKirakosyan avatar Feb 14 '24 13:02 DmitriyKirakosyan

Facing the same issue

rifad4u avatar Feb 19 '24 04:02 rifad4u

same issue I am using

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

rezaarifian avatar Mar 05 '24 11:03 rezaarifian

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 avatar Mar 11 '24 11:03 Jonnboy91

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

DmitriyKirakosyan avatar Mar 28 '24 11:03 DmitriyKirakosyan

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

mmmoussa avatar Mar 28 '24 14:03 mmmoussa

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

brianlenz avatar Mar 28 '24 15:03 brianlenz

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.

fergusean avatar Mar 28 '24 17:03 fergusean

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.

Jonnboy91 avatar Mar 28 '24 17:03 Jonnboy91