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

RN upgrade 0.56.1 -- app:generateBundledResourcesHashDebug can't find CodePushHash #1427

Closed
peacechen opened this issue Oct 11, 2018 · 12 comments

Comments

@peacechen
Copy link

Steps to Reproduce

I upgraded an existing project to RN 0.56.1. Previously the app built and ran on Android, but fails after the upgrade.
Are there any special steps needed for RN 0.56? I scanned through the documentation and the setup is correct (same as before).
Perhaps of note is that I had to upgrade to Gradle 4.6 and associated tools (Android SDK 28, etc).

Expected Behavior

Build & run on Android without errors

Actual Behavior

Result of react-native run-android. The file CodePushHash doesn't exist.

Task :app:generateBundledResourcesHashDebug FAILED
4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
fs.js:663
return binding.open(pathModule.toNamespacedPath(path),
^

Error: ENOENT: no such file or directory, open '/Users/me/myproject/android/app/build/intermediates/assets/debug/CodePushHash'
at Object.fs.openSync (fs.js:663:18)
at Object.fs.writeFileSync (fs.js:1314:33)
at /Users/me/myproject/node_modules/react-native-code-push/scripts/generateBundledResourcesHash.js:81:16
at addFileToManifest (/Users/me/myproject/node_modules/react-native-code-push/scripts/generateBundledResourcesHash.js:98:9)
at /Users/me/myproject/node_modules/react-native-code-push/scripts/generateBundledResourcesHash.js:72:9
at addFileToManifest (/Users/me/myproject/node_modules/react-native-code-push/scripts/generateBundledResourcesHash.js:98:9)
at addJsBundleAndMetaToManifest (/Users/me/myproject/node_modules/react-native-code-push/scripts/generateBundledResourcesHash.js:70:5)
at Object. (/Users/me/myproject/node_modules/react-native-code-push/scripts/generateBundledResourcesHash.js:66:5)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)

Reproducible Demo

Can't repro the complex environment of our app in the example project.

Environment

  • react-native-code-push version: 5.4.2
  • react-native version: 0.56.1
  • iOS/Android/Windows version: Android 6
  • Does this reproduce on a debug build or release build? Debug
  • Does this reproduce on a simulator, or only on a physical device? simulator
@peacechen
Copy link
Author

peacechen commented Oct 11, 2018

I searched the issues again (for the 10th time, with google too) and was able to dig this up:
#1401 (comment)

Workaround is to create the folder manually.

Manually creating the sub-folders .... /intermediates/assets/debug got past this error. That's kind of crazy to have to do that. Any insight as to why this is happening on upgrades?

Edit: yet another encounter on SO
https://stackoverflow.com/questions/52579414/codepushhash-not-found-working-with-code-push

@yuri-kulikov
Copy link
Contributor

Hi @peacechen!
I've tried to reproduce the issue, but everything works as intended.

react-native 0.56.1
react-native-code-push 5.4.2
gradlew 4.6
gradle plugin 3.1.4

Here is a part of my react-native run-android log:

...
> Task :app:bundleDebugJsAndAssets
Scanning folders for symlinks in {project_path}/node_modules (12ms)
Scanning folders for symlinks in {project_path}/node_modules (24ms)
warning: the transform cache was reset.
Loading dependency graph, done.
bundle: Writing bundle output to: {project_path}/android/app/build/intermediates/assets/debug/index.android.bundle
bundle: Done writing bundle output

> Task :app:generateBundledResourcesHashDebug
1733b7f420d2355475737097662875c680040ddc9a7898a8b583a6eb2b0c0fa0
...

So when generateBundledResourcesHashDebug task is performed, the /build/intermediates/assets/debug/ already created.
But in your case /build/intermediates/assets/debug/ doesn't exist for some reason.
Can you share this part of your react-native run-android log please?

And if can provide us with a simple reproducible demo it would be very helpful!

@peacechen
Copy link
Author

peacechen commented Oct 15, 2018

Hello yuri, and thanks for looking into this.

That stage is being skipped:

:app:bundleDebugJsAndAssets SKIPPED

I don't recall turning that off. Any idea how to enable it?

Edit: some information here may be applicable --
https://proandroiddev.com/bundling-react-native-during-android-release-builds-ec52c24e200d

However enabling bundleInDebug slows down debug builds. Any way to avoid that?
Since the debug bundle isn't necessary to run the debug build, it would be helpful if CodePush creates that path, or puts it directly in the intermediates directory.

@yuri-kulikov
Copy link
Contributor

yuri-kulikov commented Oct 16, 2018

Hey @peacechen, you are right, :app:bundleDebugJsAndAssets should be skipped by default in debug. I've just missed this moment because I've used a specific app which is configured differently.

I've created a new react-native 0.56.1 (gradle plugin 3.1.4) app and that stage was also skipped: :app:bundleDebugJsAndAssets SKIPPED,
but the /build/intermediates/assets/debug/ folder was still created properly, so I guess it's now the reason.

Then I've tried gradle plugin 3.2.1 and finally reproduced the issue. (It's because Gradle Plugin 3.2 uses a new intermediates/merged_assets directory instead of intermediates/assets)

So if you are using gradle plugin 3.2+ it's also better to use react native 0.57.2+ for better compability.

There is a workaround for this:
In {project_dir}/node_modules/react-native-code-push/android/codepush.gradle (~86-90) just add this three lines:

generateBundledResourcesHash = tasks.create(
        name: "generateBundledResourcesHash${targetName}",
        type: Exec) {
+   doFirst {
+       jsBundleDir.mkdirs()
+   }
    commandLine (*nodeExecutableAndArgs, "${nodeModulesPath}/react-native-code-push/scripts/generateBundledResourcesHash.js", resourcesDir, jsBundleFile, jsBundleDir, resourcesMapTempFileName)
}

Can you tell me what version of gradle plugin you are using?
Please let me know if it helps. We'll continue investigating.

@peacechen
Copy link
Author

My environment is using Gradle plugin 3.2.0, so it looks like you've found the culprit. We're not ready to upgrade to RN 0.57 due to some of its breaking changes.

I could run a postinstall script to patch the codepush.gradle file until a new version is released. Will you be adding that to the repo? If not, I could create a PR. I just need a commit to reference for the patch file.

@yuri-kulikov
Copy link
Contributor

yuri-kulikov commented Oct 18, 2018

Hey @peacechen!

My environment is using Gradle plugin 3.2.0, so it looks like you've found the culprit. We're not ready to upgrade to RN 0.57 due to some of its breaking changes.

Unfortunately, the problem is that the react-native 0.56 (< 0.57.2) does not support Gradle 3.2, so if you try to run Release version of RN 0.56 (even without CodePush) it just will not work (bundle will not be packed in the application). So our workaround is kinda useless in this case.

I see two solutions:

  1. You can use gradle plugin 3.1.4.

    From react-native changelog [0.57.0]:

    Android tooling has been updated to match newer configuration requirements (SDK 27, gradle 4.4, and support library 27); building with Android plugin 3.2 doesn't work due to the gradle scripts, so please stay on Android Studio 3.1 for now

  2. Or you can implement this fix in react.gradle file.

P.S. and for the rest of those who are also looking for a solution:

  1. You can use react-native >= 0.57.2
  2. You can set the output directory manually in your project_path/android/app/build.gradle:
project.ext.react = [
    entryFile: "index.js",
    jsBundleDirDebug: "$buildDir/intermediates/merged_assets/debug/mergeDebugAssets/out",
    jsBundleDirRelease: "$buildDir/intermediates/merged_assets/release/mergeReleaseAssets/out"
]

@peacechen
Copy link
Author

Thanks @yuri-kulikov for digging up that obscure bug! I would've burned hours trying to figure out why the production build failed. I owe ya one. 🍺

@yuri-kulikov
Copy link
Contributor

You're welcome🍺 I'm happy to help!
Thanks for using code-push!
If you have any other questions, please feel free to ask.

eladgel pushed a commit to eladgel/react-native-code-push that referenced this issue Nov 7, 2018
@anmol-appzoy
Copy link

Hey @peacechen, you are right, :app:bundleDebugJsAndAssets should be skipped by default in debug. I've just missed this moment because I've used a specific app which is configured differently.

I've created a new react-native 0.56.1 (gradle plugin 3.1.4) app and that stage was also skipped: :app:bundleDebugJsAndAssets SKIPPED,
but the /build/intermediates/assets/debug/ folder was still created properly, so I guess it's now the reason.

Then I've tried gradle plugin 3.2.1 and finally reproduced the issue. (It's because Gradle Plugin 3.2 uses a new intermediates/merged_assets directory instead of intermediates/assets)

So if you are using gradle plugin 3.2+ it's also better to use react native 0.57.2+ for better compability.

There is a workaround for this:
In {project_dir}/node_modules/react-native-code-push/android/codepush.gradle (~86-90) just add this three lines:

generateBundledResourcesHash = tasks.create(
        name: "generateBundledResourcesHash${targetName}",
        type: Exec) {
+   doFirst {
+       jsBundleDir.mkdirs()
+   }
    commandLine (*nodeExecutableAndArgs, "${nodeModulesPath}/react-native-code-push/scripts/generateBundledResourcesHash.js", resourcesDir, jsBundleFile, jsBundleDir, resourcesMapTempFileName)
}

Can you tell me what version of gradle plugin you are using?
Please let me know if it helps. We'll continue investigating.

Hi @yuri-kulikov, the solution that you mentioned here is not working for my react native project. The React native version is 0.58.6 and Gradle version is 4.7. Can you please help me out in this.

@peacechen
Copy link
Author

@anmol-appzoy
We're using Gradle 3.2.1 and RN 0.56, so it sounds like you've found the cutoff for the broken combination of versions. Thanks for looking into this.

@Ancy1
Copy link

Ancy1 commented Jan 24, 2020

Task :app:generateBundledResourcesHashRelease FAILED no such file or directory, scandir /react-native-code-push/scripts/getFilesInFolder.js jenkins #1771

Had same issue

react-native": "0.60.5"
android gradle plugin version "3.4.1"

local its working fine but jenkins build failed with this issue ..need help.here . is the log

Task :app:generateBundledResourcesHashRelease FAILED
fs.js:122
throw err;
^

Error: ENOENT: no such file or directory, scandir '/home/jenkins/workspace///android/app/build/generated/res/react/release'
at Object.readdirSync (fs.js:809:3)
at getFilesInFolder (/home/jenkins/workspace/
//node_modules/react-native-code-push/scripts/getFilesInFolder.js:7:26)
at Object. (/home/jenkins/workspace/
/*/node_modules/react-native-code-push/scripts/generateBundledResourcesHash.js:38:1)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:775:12)
at startup (internal/bootstrap/node.js:300:19)
FAILURE: Build failed with an exception.

@jessamp
Copy link

jessamp commented Nov 17, 2020

Hi!

I'm getting a similar problem, but with my release builds.

`

Task :app:generateBundledResourcesHashRelease FAILED
fs.js:114
throw err;
^
Error: ENOENT: no such file or directory, scandir '../android/app/build/generated/res/react/release'
`

In my android/app/build.gradle file, I added this line in the config block:
project.ext.react = [ bundleInRelease: false ]

I tried the solutions above, but nothing seemed to fix it.

I'm also curious why with the debug builds this task is skipped, but for release builds it's not?

We're using:
Gradle: 6.2
Gradle Plugin: 3.5.3
React Native: 63.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants