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

A project with custom root fails at: cli-platform-android/native_modules.gradle' line: 191 #591

Closed
vladp opened this issue Jul 25, 2019 · 17 comments
Labels
question Further information is requested

Comments

@vladp
Copy link

vladp commented Jul 25, 2019

I am trying to upgrade to 60.4, and introduced the 'autolinking' capability by modifying my settings.gradle and app/build.gradle.
Platform is Linux, RN platform is android only, cli is 2.8.0.

With that change, however I cannot run any gradle commands (not even gradlew clean):

bash gradlew clean


FAILURE: Build failed with an exception.

* Where:
Script '/home/v/myproj/mob/rn.common/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 191

* What went wrong:
A problem occurred evaluating settings 'myapp1b'.
> Cannot get property 'packageName' on null object

The cli version is latest, 2.8.0
The line where it is failing, trying to parse json output from running react-native-config
Line 191:
this.packageName = json["project"]["android"]["packageName"]

When I run
PATH=$(npm bin):$PATH react-native config

I can see that in its output ["project"]["android" is indeed null.

...
"platforms": {
    "ios": {},
    "android": {}
  },
  "haste": {
    "providesModuleNodeModules": [
      "react-native"
    ],
    "platforms": [
      "ios",
      "android"
    ]
  },
  "project": {
    "ios": null,
    "android": null
  }

But why, and what do I need to do to fix it?
It seems that applyNativeModulesSettingsGradle relies on it, and that's why my build completely stopped at the moment.

Additional info:

cat react-native.config.js <-- this is root of my RN code. this dir also has index.android.js

module.exports = {
  project: {
    ios: {},
    android: {},
  },
  assets: ['./src/js.app/img'],
};

cat settings.gradle

//do  npm install @react-native-community/cli@2.8.0 --save-dev
//in case this component is not installed directly by RN

rootProject.name = 'myapp1b' //this rootProjectName used by community cli. so I am setting to be what my gradle defined as project.name (which is directory name of my proj, or equal to rootProject.name that can only be set in this file) https://discuss.gradle.org/t/rootproject-name-in-settings-gradle-vs-projectname-in-build-gradle/5704

//this whole machinery (plus a change in app/build.gradle) is used to auto generate rn-community module names so that they can, indirectly be included in to app/build.gradle so that those modules can be used

apply from:file("${rootDir}/../../rn.common/node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings,"../../rn.common/") //note second arg, this is a must because I do not have a default location of node_modules (see custom root section at: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md )

include ':app', ':lint'
include ':react-native-vector-icons'

project(':react-native-vector-icons').projectDir = file("${rootDir}/../../../mob/rn.common/node_modules/react-native-vector-icons/android")

I did not even have, initially, the react-native.config.js (because it was not noted as needed in rn-diff utility) , but even after adding it -- it did not help.

appreciate in advance any guidance.

@vladp vladp added the question Further information is requested label Jul 25, 2019
@vladp
Copy link
Author

vladp commented Jul 26, 2019

I fixed the problem.
Because of custom paths (I have essentially a form of mono-repo with many sub projects)
PATH=$(npm bin):$PATH react-native config
could not find where my root android part of the project was (it was not in standard directory relative to the JS part of the project)

I am not sure if this nuance is covered in
https://github.com/react-native-community/cli/blob/master/docs/autolinking.md
It talks about how to tell cli, in 'custom root' configuration , about the location of JS part of the project, but does not tell how to tell the cli tools about the the location of android side of the project

So all I had to do, to fix this specific problem, is to specify sourceDir and packageName in the react-native.config.js


module.exports = {
  project: {
    ios: {},
    android: {
    "sourceDir": "../a/myapp1b/app/src",
    "packageName":"com.myapp1b.myapp"
    
    },
  },
  assets: ['./src/js.app/img'],
};


@vladp vladp closed this as completed Jul 26, 2019
@ldco2016
Copy link

can anyone assist on how this would relate to a build in Azure DevOps, this is where I get the error:

FAILURE: Build failed with an exception.
 
* Where:
Script 'D:\a\1\s\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 191
 
* What went wrong:
A problem occurred evaluating settings 'NFIBEngage'.
> Text must not be null or empty
 
* 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 1m 42s
Error: The process 'D:\a\1\s\android\gradlew.bat' failed with exit code 1
 at ExecState._setResult (D:\a\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.155.0\node_modules\azure-pipelines-task-lib\toolrunner.js:816:25)
 at ExecState.CheckComplete (D:\a\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.155.0\node_modules\azure-pipelines-task-lib\toolrunner.js:799:18)
 at ChildProcess.<anonymous> (D:\a\_tasks\Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4\2.155.0\node_modules\azure-pipelines-task-lib\toolrunner.js:721:19)
 at emitTwo (events.js:106:13)
 at ChildProcess.emit (events.js:191:7)
 at maybeClose (internal/child_process.js:886:16)
 at Socket.<anonymous> (internal/child_process.js:342:11)
 at emitOne (events.js:96:13)
 at Socket.emit (events.js:188:7)

@cmcaboy
Copy link

cmcaboy commented Oct 1, 2019

@ldco2016 I am receiving the same error on App Center (should be same as Azure). Were you able to find a solution?

@vitalyiegorov
Copy link

vitalyiegorov commented Oct 2, 2019

If anyone still facing this problem when using the monorepo approach please pay attention to android/settings.gradle:

apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings, "../../..")
include ':app'

and android/app/build.gradle:

apply from: file("../../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project, "../../..")
include ':app'

applyNativeModulesSettingsGradle and applyNativeModulesAppBuildGradle has second parameter root (relative path to folder with settings) which is passed to gradle to find react-native.config.js

@ridvanaltun
Copy link

Cleaning gradle cache works for me

Stop gradlew on Windows:
gradlew --stop

Stop gradlew on Mac or Linux:
./gradlew --stop

Clean cache on Windows:
gradle cleanBuildCache

Clean cache on Mac or Linux:
./gradlew cleanBuildCache

@bkleef
Copy link

bkleef commented Oct 12, 2019

In my case bash was not installed in the Docker (build) container.

@tarunvella
Copy link

tarunvella commented Oct 17, 2019

I fixed the problem.
Because of custom paths (I have essentially a form of mono-repo with many sub projects)
PATH=$(npm bin):$PATH react-native config
could not find where my root android part of the project was (it was not in standard directory relative to the JS part of the project)

I am not sure if this nuance is covered in
https://github.com/react-native-community/cli/blob/master/docs/autolinking.md
It talks about how to tell cli, in 'custom root' configuration , about the location of JS part of the project, but does not tell how to tell the cli tools about the the location of android side of the project

So all I had to do, to fix this specific problem, is to specify sourceDir and packageName in the react-native.config.js


module.exports = {
  project: {
    ios: {},
    android: {
    "sourceDir": "../a/myapp1b/app/src",
    "packageName":"com.myapp1b.myapp"
    
    },
  },
  assets: ['./src/js.app/img'],
};

@vladp How do i perform PATH=$(npm bin):$PATH react-native config in windows, and where can i keep react-native.config.js in my project.

and which library can add a react-native.config.js

@bkraeling
Copy link

@cmcaboy I'm also seeing this same error in AppCenter. Did you find a solution that worked?

@vladp vladp reopened this Oct 29, 2019
@vladp
Copy link
Author

vladp commented Oct 29, 2019

Please note, that
react-native-community/cli in RN 0.61 had remove the functionality where we can specify the custom RN root using app/build.gradle root: directive in project.ext.react

project.ext.react = [

        entryFile: "index.android.js",
        // whether to bundle JS and assets in debug mode
        bundleInDebug: false,
        // whether to bundle JS and assets in release mode
        bundleInRelease: true,
        // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
        bundleCommand: "ram-bundle",
        enableHermes: false,  // clean and rebuild if changing

        // the root of your RN project, i.e. where "package.json" lives
        root: "${myRnAppRootDir_abs}"
]

So starting from RN 0.61 if you have RN root folder located as a sibling or underneath of a sibling of your Android app directory, the CLI will not find it and Autolinking will fail

See my bug report at
#804


@tarunvella

how do I perform PATH=$(npm bin):$PATH react-native config

on windows, just
cd < your react native root, where node_modules in installed>

and do
node_modules/.bin/react-native config

You do not need to this manually, as CLI's autolinking code does that.
The code knows where to go, because you had to specify your RN root in
in app/buid.gradle project.ext.react
variable.

The best guide for this, unfortutely, is just to carefull follow diff report between your current version
and RN 0.60
https://github.com/react-native-community/rn-diff-purge

@vladp vladp closed this as completed Oct 29, 2019
@Alcionei
Copy link

I deleted my build folder and it worked.

@Cuadros99
Copy link

Cleaning gradle cache works for me

Stop gradlew on Windows:
gradlew --stop

Stop gradlew on Mac or Linux:
./gradlew --stop

Clean cache on Windows:
gradle cleanBuildCache

Clean cache on Mac or Linux:
./gradlew cleanBuildCache

FAILURE: Build failed with an exception.

  • Where:
    Script 'C:\Users\danie\OneDrive\┴rea de Trabalho\IME\Iniciativas\IME Jr\BECOMP\CapacitaþÒo\React Native\Curso_React_Native\final_chance\node_modules@react-native-community\cli-platform-android\native_modules.gradle' line: 195

  • What went wrong:
    A problem occurred evaluating script.

internal/modules/cjs/loader.js:1032 throw err; ^Error: Cannot find module 'C:\Users\danie\OneDrive\├â´┐¢rea de Trabalho\IME\Iniciativas\IME Jr\BECOMP\Capacita├â┬º├â┬úo\React Native\Curso_React_Native\final_chance\node_modules@react-native-community\cli\build\bin.js' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1029:15) at Function.Module._load (internal/modules/cjs/loader.js:898:27) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) at internal/main/run_main_module.js:17:47 { code: 'MODULE_NOT_FOUND', requireStack: []}

  • 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 7s

This was the error that appear to me when I wrote this commands.

@mohpezeshki
Copy link

@Cuadros99 i got this error too but in linux when i init new react-native project in react-native-cli i've faced with this error every time

Could not load compiled classes for script '.../node_modules/@react-native-community/cli-platform-android/native_modules.gradle' from cache.

@kuldeep-IT
Copy link

@Cuadros99 i got this error too but in linux when i init new react-native project in react-native-cli i've faced with this error every time

Could not load compiled classes for script '.../node_modules/@react-native-community/cli-platform-android/native_modules.gradle' from cache.

@mohpezeshki, I'm also facing the same issue in RN 0.72.4

@Cuadros99
Copy link

@Cuadros99 i got this error too but in linux when i init new react-native project in react-native-cli i've faced with this error every time

Could not load compiled classes for script '.../node_modules/@react-native-community/cli-platform-android/native_modules.gradle' from cache.

@mohpezeshki, I'm also facing the same issue in RN 0.72.4

What worked for me at the time was put the project directory in a place where it didnt have any blank space in its path. Like in my case the path has "/┴rea de Trabalho/".

@runamodev
Copy link

A simple npm prune worked for me.

@Sushmanighthack
Copy link

Can anyone suggest this how to resolve this error
Could not read script 'C:\code\ViveRN\node_modules@react-native-community\cli-platform-android\native_modules.gradle' as it does not exist.

@szymonrybczak
Copy link
Collaborator

@Sushmanighthack please make sure thatn you have node_modules installed and than in android/ project is pointing to correct node_modules path 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests