cli: @react-native-community/cli-platform-android Build failed with an exception

Environment

react-native info

yarn run v1.19.1
$ /Users/b1ng/rn/haokan/node_modules/.bin/react-native info
info Fetching system and libraries information...
System:
    OS: macOS 10.15.1
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Memory: 53.23 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.12.0 
    Yarn: 1.19.1 
    npm: 6.12.1 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5900203
    Xcode: /undefined - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0
    react-native: 0.61.4 => 0.61.4
✨  Done in 2.66s.

react-native --version

yarn run v1.19.1
$ /Users/b1ng/rn/haokan/node_modules/.bin/react-native --version
3.0.0-alpha.7
✨  Done in 0.32s.

Description

yarn android

yarn run v1.19.1
$ react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
info Installing the app...

FAILURE: Build failed with an exception.

* Where:
Script '/Users/b1ng/rn/haokan/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 182

* What went wrong:
A problem occurred evaluating script.
> Unable to determine the current character, it is not a string, number, array, or object

  The current character read is 'i' with an int value of 105
  Unable to determine the current character, it is not a string, number, array, or object
  line number 1
  index number 0
  info Run "react-native --help" to see a list of all available commands.
  ^

* 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 1s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* Where:
Script '/Users/b1ng/rn/haokan/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 182

* What went wrong:
A problem occurred evaluating script.
> Unable to determine the current character, it is not a string, number, array, or object

  The current character read is 'i' with an int value of 105
  Unable to determine the current character, it is not a string, number, array, or object
  line number 1
  index number 0
  info Run "react-native --help" to see a list of all available commands.
  ^

* 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 1s

    at checkExecSyncError (child_process.js:621:11)
    at execFileSync (child_process.js:639:15)
    at runOnAllDevices (/Users/b1ng/rn/haokan/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:39)
    at buildAndRun (/Users/b1ng/rn/haokan/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:158:41)
    at /Users/b1ng/rn/haokan/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:125:12
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Command.handleAction (/Users/b1ng/rn/haokan/node_modules/@react-native-community/cli/build/index.js:164:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Reproducible Demo

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 58 (11 by maintainers)

Most upvoted comments

I found a workaround for this:

yarn add @react-native-community/cli-platform-android@3.0.3
yarn add react-native@0.61.5
Removed "--quiet" from npx.cmd in native_modules.gradle
cd android && gradlew clean

@Esemesek since we call npx, it’s npm records we want to update, so running

npm uninstall -g react-native-cli

seems more appropriate.

@Esemesek

I haven’t install react-native-cli any all. Create the app with npx react-native init. And when i reinstall @react-native-community/cli-platform-android with @3.0.0-alpha.2 , it’s ok.

same issue still persists but i found a work around : cd into the android app of your app and run gradlew --stop then run gradlew clean i found it works better on a terminal with elevated privileges

after it finishes run your app the normal way

I’ve solved like this on native_modules.gradle

- def command = "${npx} --quiet --no-install react-native config"
+ def command = "yarn --silent react-native config"
` ``

For other people that are affected, this in your package.json will fix it for you:

  "resolutions": {
    "@react-native-community/cli-platform-android": "3.0.0-alpha.2"
  },

Try updating the Node to the version 10.17.0. It helped me.

It seems like you have global react-native-cli installed, which causes name conflicts in react-native binary. Could you please remove global react-native-cli by running yarn global remove react-native-cli and try again with yarn react-native run-android?

I did not install react-native and react-native-cli , and i also run npm uninstall -g react-native react-native-cli

When remove the native_modules.gradle comment /* dir */

def reactNativeConfigOutput = this.getCommandOutput(command, /* dir */) 

to

def reactNativeConfigOutput = this.getCommandOutput(command, dir)

it’s ok.

I’m working in a monorepo. The file exists, but it was in my project root’s node_modules/@react-native-community NOT the package node_modules.

To fix this, I updated the paths

/android/settings.gradle : Line 2

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

/android/app/build.gradle : Line 225

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

I’m too working in a monorepo. I just add line to nohois in root package.json

    "nohoist": [
+      "**/@react-native-community/**",
       "**react-native**",
       ...
    ]

I was getting this issue and nothing seemed to fix it. Until i noticed that i was using a gradle version higher than what the guide had suggested.

Go to

android/gradle/wrapper/gradle-wrapper.properties

And ensure yourdistributionUrl is the same as what your guide or upgrade helper suggests.

Edit: Also, there seemed to be some issue with with node that it would not install the correct packages, check your node_modules directory to check if the package was installed correctly or not (file with the script exists or not). I used yarn instead and it installed things correctly.

manually removed the caches and daemon folders in _%HOME%/user/.gradle/_ then navigate to android folder in your project i.e. /myproject/android/ run _gradlew --stop_ // this stops the running daemon

then run gradlew clean

might take a while to rebuild so b patient

** Happy Holidays and Happy Coding.**

Hello community

I’m facing an error in cli-platform-android\native_modules.gradle in line:197

> react-native run-android

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1083 file(s) to forward-jetify. Using 4 workers...
info JS server already running.
info Installing the app...

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\abdom\Documents\LoginID\react-native-plaid-link-sdk\example\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 197

* What went wrong:
A problem occurred evaluating project ':app'.
> Project with path ':react-native-community_clipboard' could not be found in project ':app'.

* 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

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.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\abdom\Documents\LoginID\react-native-plaid-link-sdk\example\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 197

* What went wrong:
A problem occurred evaluating project ':app'.
> Project with path ':react-native-community_clipboard' could not be found in project ':app'.

* 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

    at makeError (C:\Users\abdom\Documents\LoginID\react-native-plaid-link-sdk\example\node_modules\react-native\node_modules\execa\index.js:174:9)
    at C:\Users\abdom\Documents\LoginID\react-native-plaid-link-sdk\example\node_modules\react-native\node_modules\execa\index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (C:\Users\abdom\Documents\LoginID\react-native-plaid-link-sdk\example\node_modules\react-native\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
    at async Command.handleAction (C:\Users\abdom\Documents\LoginID\react-native-plaid-link-sdk\example\node_modules\@react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.

React-native Info

$ react-native info
info Fetching system and libraries information...
(node:5956) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
System:
    OS: Windows 10 10.0.19044
    CPU: (4) x64 Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz
    Memory: 1.77 GB / 7.89 GB
  Binaries:
    Node: 16.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 8.11.0 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: AI-212.5712.43.2112.8815526
    Visual Studio: 17.1.32210.238 (Visual Studio Community 2022)
  Languages:
    Java: 17.0.4 - /c/Program Files/Common Files/Oracle/Java/javapath/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2
    react-native: 0.66.4 => 0.66.4
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

React-native Version $ react-native -v react-native-cli: 2.0.1 react-native: 0.66.4

I tried to reinstall the package but nothing change I’d be thankful if there’s any additional details to share to solve this issue ,CodeSafe

I’m working in a monorepo. The file exists, but it was in my project root’s node_modules/@react-native-community NOT the package node_modules.

To fix this, I updated the paths

/android/settings.gradle : Line 2

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

/android/app/build.gradle : Line 225

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

Surprisingly, a lot of issues here were resolved by doing something totally irrelevant to the CLI.

I believe the title of this issue is misleading because many builds can “fail with an exception”. This is the standard Android failure that can happen on many occasions.

I am going to close this issue and encourage you to open other issues in the future with more verbose title/description to not confuse anyone.

Also, npx is going away in the next release - #886 - so many of these errors should be resolved as well.

Uncommenting /* dir */ also fixes the issue for me. Here are more specifics:

  • This is happening on Microsoft AppCenter
  • My React Native app does not live in the root of the repo. It’s in a mobile/ directory.
  • AppCenter doesn’t cd mobile. Instead it’s just firing off mobile/android/gradlew from the root
  • Because the second argument dir is commented out, I think npx is being run at the root of my repo, which isn’t going to work.

It stopped working when upgrading react-native from 0.61.4 to 0.61.5. But then after downgrading the problem is still happening so it could also have something to do with the global CI config (app center). Let me investigate this further.

I found a workaround for this:

yarn add @react-native-community/cli-platform-android@3.0.3
yarn add react-native@0.61.5
Removed "--quiet" from npx.cmd in native_modules.gradle
cd android && gradlew clean

Worked fine

native_modules.gradle

can be found in

${PROJECT_FOLDER}/node_modules/@react-native-community/cli-platform-android/native_modules.gradle

if you use yarn check @sibelius answer up here

You will need to clear gradle cache also