microsoft / react-native-code-push

React Native module for CodePush
http://appcenter.ms
Other
8.99k stars 1.47k forks source link

Task :app:generateBundledResourcesHashRelease FAILED #2182

Closed yulunjiang closed 2 years ago

yulunjiang commented 2 years ago

Steps to Reproduce

  1. android/app/build.gradle set flag bundleInRelease: false make sure flag to add it before the apply from: "../../node_modules/react-native/react.gradle" apply from: "../../node_modules/react-native-code-push/android/codepush.gradle" line.
  2. run clean project
  3. run Release build

Expected Behavior

Build & run on Android without errors

Actual Behavior

What actually happens?

  > Task :app:generateBundledResourcesHashLifeStagingRelease FAILED
internal/fs/utils.js:314
    throw err;
    ^

Error: ENOENT: no such file or directory, scandir '/Users/user/work/git/my/android/app/build/generated/res/react/lifeStaging/release'
    at Object.readdirSync (fs.js:1043:3)
    at getFilesInFolder (/Users/user/work/git/my/node_modules/react-native-code-push/scripts/getFilesInFolder.js:7:26)
    at Object.<anonymous> (/Users/user/work/git/my/node_modules/react-native-code-push/scripts/generateBundledResourcesHash.js:38:1)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47 {
  errno: -2,
  syscall: 'scandir',
  code: 'ENOENT',
  path: '/Users/user/work/git/my/android/app/build/generated/res/react/lifeStaging/release'
ENOENT: no such file or directory, scandir '/Users/user/work/git/my/android/app/build/generated/res/react/lifeStaging/release'

}

Environment

yulunjiang commented 2 years ago

I hope this correction can be arranged into the plan . Thanks!

The root cause to fix this

There are some wrong code in the codepush.gradle cause the task generateBundledResourcesHash can not skipped.

 if (variant.hasProperty("bundleJsAndAssets")) {
            def reactBundleTask = variant.bundleJsAndAssets
            jsBundleDir = reactBundleTask.generatedAssetsFolders[0].absolutePath
            resourcesDir = reactBundleTask.generatedResFolders[0].absolutePath
            jsBundleFile = file("$jsBundleDir/$bundleAssetName")

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

              // wrong code : 
                enabled config."bundleIn${targetName}" ||
                config."bundleIn${variant.buildType.name.capitalize()}" ?:
                targetName.toLowerCase().contains("release")
            }   
        }

replace this:

              // correct code :
                enabled config."bundleIn${targetName}" != null
                                ? config."bundleIn${targetName}"
                                : config."bundleIn${variant.buildType.name.capitalize()}" != null
                                    ? config."bundleIn${variant.buildType.name.capitalize()}"
                                    : targetName.toLowerCase().contains("release")

then it's work well!

ghost commented 2 years ago

This issue has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs within 15 days of this comment.

ghost commented 2 years ago

This issue will now be closed because it hasn't had any activity for 15 days after stale. Please feel free to open a new issue if you still have a question/issue or suggestion.

lucianobracco-geojam commented 1 year ago

This is still hapenning! Can we reopen it?

DmitriyKirakosyan commented 1 year ago

Hi @lucianobracco-geojam , would you able to check if the fix in https://github.com/microsoft/react-native-code-push/issues/2182/#issuecomment-968716466 works for you?