React-native-code-push: [Android] Not working with Android Studio 3.0 and Gradle 3.0.0

Created on 2 Nov 2017  路  14Comments  路  Source: microsoft/react-native-code-push

Thanks so much for filing an issue or feature request! Please fill out the following (wherever relevant):

Steps to Reproduce

  1. Upgrade project to react native 49
  2. Upgrade the android app to run on gradle 3.0
  3. Hit run

Expected Behavior

Should have run successfully

Actual Behavior

But run fails with these logs:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':mobile:recordFilesBeforeBundleCommandBuildDebug'.
> A problem occurred starting process 'command 'node''

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 11s

Environment

  • react-native-code-push version: 5.1.3-beta
  • react-native version:0.49.3
  • iOS/Android/Windows version: Android 26
  • Does this reproduce on a debug build or release build? : debug
  • Does this reproduce on a simulator, or only on a physical device? : both
android bug

Most helpful comment

It seems to be that something changed between versions of Gradle or Android Studio so now during the building in Android studio it cannot find node if it's absent on usr/local/bin/node path or any other default binary apps paths that can be observed by Android Studio. To fix this you can use several workarounds:

  • manually specify node executable path by settings nodeExecutableAndArgs in app/build.gradle (as said here):
project.ext.react = [
        nodeExecutableAndArgs : ["/usr/local/bin/node"]
];
  • create symbolic link to your node executable targetting /usr/local/bin/node:
ln -s /home/<YOUR_USER>/.nvm/versions/node/v6.11.3/bin/node /usr/local/bin/node
  • build your project in console instead of Android Studio

All 14 comments

Hi @mohitgoibibo and thanks for submitting the issue.

Try to reinstall node modules: rm -rf node_modules && npm install.
Please let us know if it helps or any updates.

Hi @ruslan-bikkinin , I executed the following steps:

  1. rm -rf node_modules
  2. nvm use 9.0.0
  3. npm install

Output

node_modules/react-native-code-push/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

:react-native-code-push:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug
:mobile:recordFilesBeforeBundleCommandBuildDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':mobile:recordFilesBeforeBundleCommandBuildDebug'.
> A problem occurred starting process 'command 'node''

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 33s

263 actionable tasks: 35 executed, 228 up-to-date

FYI: We have multiple flavours and build types.

@mohitgoibibo CodePush does not support Gradle 3 because it requires BuildTools 26. We are following React Native minimal BuildTools requirements which is 23.0.1 to be compatible with it.

So I am closing this for now, please feel free to ask if you have any questions.

@ruslan-bikkinin @sergey-akhalkov Is it in the roadmap to include support for Gradle 3 and BuildTools 26

@mohitgoibibo I've just tried to use Gradle 3 on RN 0.50 version and it works well. I believe we should investigate why it isn't working with codepush indeed.

Hi @mohitgoibibo, thanks for reaching us, could you please confirm if the issue does not reproduce for you in case you are using the previous version of the gradle?

From the issue details I can see A problem occurred starting process 'command 'node'', it means that codepush.gradle script cannot find nodejs.

Please also take a look at the similar issue here: https://github.com/facebook/react-native/issues/6875

@sergey-akhalkov Yes currently I have reverted to previous version of gradle and its working.

And yes the issue is similar as referenced in the link.

Hi @mohitgoibibo, please use this workaround for now https://github.com/facebook/react-native/issues/6875#issuecomment-293220175 that helped me to resolve the issue (able to build a apk via Android Studio)
We'll try investigate and fix it a little bit later, thanks for letting us know about this issue and thanks for the patience.

It seems to be that something changed between versions of Gradle or Android Studio so now during the building in Android studio it cannot find node if it's absent on usr/local/bin/node path or any other default binary apps paths that can be observed by Android Studio. To fix this you can use several workarounds:

  • manually specify node executable path by settings nodeExecutableAndArgs in app/build.gradle (as said here):
project.ext.react = [
        nodeExecutableAndArgs : ["/usr/local/bin/node"]
];
  • create symbolic link to your node executable targetting /usr/local/bin/node:
ln -s /home/<YOUR_USER>/.nvm/versions/node/v6.11.3/bin/node /usr/local/bin/node
  • build your project in console instead of Android Studio

Well, it seems to be that this issue affects only those users, who install node non-traditional way (for example via nvm) and location of node are identifying by PATH variable. Android Studio doesn't inherit PATH variable from the shell, so it's nothing from CodePush side can be done here to fix it. You could use workarounds mentioned above or run Android Studio from shell.

Update: this issue are producing on clean RN application too (without codepush) for release variant if you are building it via Android Studio: Build->Build APK (s).

+1

For me nodeModulesPath was causing this issue..

internal/modules/cjs/loader.js:596
    throw err;
    ^

Error: Cannot find module '/Users/deepaktiwari/drive/projects/node_modules/react-native-code-push/scripts/recordFilesBeforeBundleCommand.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
    at Function.Module._load (internal/modules/cjs/loader.js:520:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
    at startup (internal/bootstrap/node.js:238:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
:rb_android:recordFilesBeforeBundleCommandDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':rb_android:recordFilesBeforeBundleCommandDebug'.
> Process 'command 'node'' finished with non-zero exit value 1

As in codepush.gradle it takes "../../node_modules" because of that it was taking the path of node modules as parallel to the project structure instead of inside the project where my package.json was available.

as package.json was inside the project I have added this in grade.properties

nodeModulesPath=../node_modules

which now takes the path from inside the project and it worked as this nodeModulesPath is used by codepush.gradle to find the recordFilesBeforeBundleCommand.js file.

Thanks,

Complementing what @ruslan-bikkinin said:

ln -s $(which node) /usr/local/bin/node

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ninjz picture ninjz  路  4Comments

panarasi picture panarasi  路  4Comments

kevando picture kevando  路  4Comments

EdmundMai picture EdmundMai  路  4Comments

chrisjrex picture chrisjrex  路  4Comments