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)
I found a workaround for this:
@Esemesek since we call
npx
, it’s npm records we want to update, so runningseems more appropriate.
@Esemesek
I haven’t install
react-native-cli
any all. Create the app withnpx 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 rungradlew clean
i found it works better on a terminal with elevated privilegesafter it finishes run your app the normal way
I’ve solved like this on
native_modules.gradle
For other people that are affected, this in your package.json will fix it for you:
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 inreact-native
binary. Could you please remove globalreact-native-cli
by runningyarn global remove react-native-cli
and try again withyarn react-native run-android
?I did not install
react-native
andreact-native-cli
, and i also runnpm uninstall -g react-native react-native-cli
When remove the native_modules.gradle comment
/* dir */
to
it’s ok.
I believe there are several duplicate issues here:
They appear to be a result of this change: https://github.com/react-native-community/cli/pull/852
I’m too working in a monorepo. I just add line to
nohois
in rootpackage.json
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
And ensure your
distributionUrl
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 daemonthen 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:197React-native Info
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 packagenode_modules
.To fix this, I updated the paths
/android/settings.gradle : Line 2
/android/app/build.gradle : Line 225
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:mobile/
directory.cd mobile
. Instead it’s just firing offmobile/android/gradlew
from the rootdir
is commented out, I thinknpx
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
to0.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.Worked fine
can be found in
if you use yarn check @sibelius answer up here
You will need to clear gradle cache also