react-native-community / cli

The React Native Community CLI - command line tools to help you build RN apps
MIT License
2.34k stars 899 forks source link

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

Closed b1ngx closed 4 years ago

b1ngx commented 4 years ago

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

Esemesek commented 4 years ago

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?

thymikee commented 4 years ago

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

npm uninstall -g react-native-cli

seems more appropriate.

b1ngx commented 4 years ago

@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.

grabbou commented 4 years ago

Can you please run yarn react-native config and paste the output? It's interesting, because on master, line 182 contains nothing but a function declaration.

I would recommend upgrading to "just released" version 3.0.0 and pasting the output again. The line should be different and we can debug this further.

b1ngx commented 4 years ago

I create the project use command npx react-native init test

yarn react-native config

yarn run v1.19.1
$ /Users/b1ng/rn/test/node_modules/.bin/react-native config
{
  "root": "/Users/b1ng/rn/test",
  "reactNativePath": "/Users/b1ng/rn/test/node_modules/react-native",
  "dependencies": {},
  "commands": [
    {
      "name": "log-ios",
      "description": "starts iOS device syslog tail"
    },
    {
      "name": "run-ios",
      "description": "builds your app and starts it on iOS simulator",
      "examples": [
        {
          "desc": "Run on a different simulator, e.g. iPhone 5",
          "cmd": "react-native run-ios --simulator \"iPhone 5\""
        },
        {
          "desc": "Pass a non-standard location of iOS directory",
          "cmd": "react-native run-ios --project-path \"./app/ios\""
        },
        {
          "desc": "Run on a connected device, e.g. Max's iPhone",
          "cmd": "react-native run-ios --device \"Max's iPhone\""
        },
        {
          "desc": "Run on the AppleTV simulator",
          "cmd": "react-native run-ios --simulator \"Apple TV\"  --scheme \"helloworld-tvOS\""
        }
      ],
      "options": [
        {
          "name": "--simulator [string]",
          "description": "Explicitly set simulator to use. Optionally include iOS version betweenparenthesis at the end to match an exact version: \"iPhone 6 (10.0)\"",
          "default": "iPhone 11"
        },
        {
          "name": "--configuration [string]",
          "description": "Explicitly set the scheme configuration to use",
          "default": "Debug"
        },
        {
          "name": "--scheme [string]",
          "description": "Explicitly set Xcode scheme to use"
        },
        {
          "name": "--project-path [string]",
          "description": "Path relative to project root where the Xcode project (.xcodeproj) lives.",
          "default": "ios"
        },
        {
          "name": "--device [string]",
          "description": "Explicitly set device to use by name.  The value is not required if you have a single device connected."
        },
        {
          "name": "--udid [string]",
          "description": "Explicitly set device to use by udid"
        },
        {
          "name": "--no-packager",
          "description": "Do not launch packager while building"
        },
        {
          "name": "--verbose",
          "description": "Do not use xcpretty even if installed"
        },
        {
          "name": "--port [number]",
          "default": 8081
        },
        {
          "name": "--terminal [string]",
          "description": "Launches the Metro Bundler in a new window using the specified terminal path."
        }
      ]
    },
    {
      "name": "log-android",
      "description": "starts logkitty"
    },
    {
      "name": "run-android",
      "description": "builds your app and starts it on a connected Android emulator or device",
      "options": [
        {
          "name": "--root [string]",
          "description": "Override the root directory for the android build (which contains the android directory)",
          "default": ""
        },
        {
          "name": "--variant [string]",
          "description": "Specify your app's build variant",
          "default": "debug"
        },
        {
          "name": "--appFolder [string]",
          "description": "Specify a different application folder name for the android source. If not, we assume is \"app\"",
          "default": "app"
        },
        {
          "name": "--appId [string]",
          "description": "Specify an applicationId to launch after build.",
          "default": ""
        },
        {
          "name": "--appIdSuffix [string]",
          "description": "Specify an applicationIdSuffix to launch after build.",
          "default": ""
        },
        {
          "name": "--main-activity [string]",
          "description": "Name of the activity to start",
          "default": "MainActivity"
        },
        {
          "name": "--deviceId [string]",
          "description": "builds your app and starts it on a specific device/simulator with the given device id (listed by running \"adb devices\" on the command line)."
        },
        {
          "name": "--no-packager",
          "description": "Do not launch packager while building"
        },
        {
          "name": "--port [number]",
          "default": 8081
        },
        {
          "name": "--terminal [string]",
          "description": "Launches the Metro Bundler in a new window using the specified terminal path.",
          "default": "iTerm.app"
        },
        {
          "name": "--tasks [list]",
          "description": "Run custom Gradle tasks. By default it's \"installDebug\""
        },
        {
          "name": "--no-jetifier",
          "description": "Do not run \"jetifier\" – the AndroidX transition tool. By default it runs before Gradle to ease working with libraries that don't support AndroidX yet. See more at: https://www.npmjs.com/package/jetifier.",
          "default": false
        }
      ]
    }
  ],
  "assets": [],
  "platforms": {
    "ios": {},
    "android": {}
  },
  "haste": {
    "providesModuleNodeModules": [
      "react-native"
    ],
    "platforms": [
      "ios",
      "android"
    ]
  },
  "project": {
    "ios": {
      "sourceDir": "/Users/b1ng/rn/test/ios",
      "folder": "/Users/b1ng/rn/test",
      "pbxprojPath": "/Users/b1ng/rn/test/ios/test.xcodeproj/project.pbxproj",
      "podfile": "/Users/b1ng/rn/test/ios/Podfile",
      "podspecPath": null,
      "projectPath": "/Users/b1ng/rn/test/ios/test.xcodeproj",
      "projectName": "test.xcodeproj",
      "libraryFolder": "Libraries",
      "sharedLibraries": [],
      "plist": [],
      "scriptPhases": []
    },
    "android": {
      "sourceDir": "/Users/b1ng/rn/test/android/app",
      "isFlat": false,
      "folder": "/Users/b1ng/rn/test",
      "stringsPath": "/Users/b1ng/rn/test/android/app/src/main/res/values/strings.xml",
      "manifestPath": "/Users/b1ng/rn/test/android/app/src/main/AndroidManifest.xml",
      "buildGradlePath": "/Users/b1ng/rn/test/android/app/build.gradle",
      "settingsGradlePath": "/Users/b1ng/rn/test/android/settings.gradle",
      "assetsPath": "/Users/b1ng/rn/test/android/app/src/main/assets",
      "mainFilePath": "/Users/b1ng/rn/test/android/app/src/main/java/com/test/MainApplication.java",
      "packageName": "com.test"
    }
  }
}
✨  Done in 0.96s.

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...
Starting a Gradle Daemon (subsequent builds will be faster)
:ReactNative:Failed to parse React Native CLI configuration: groovy.json.JsonException: 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.
^

FAILURE: Build failed with an exception.

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

* What went wrong:
A problem occurred evaluating script.
> Failed to parse React Native CLI configuration. Expected running 'npx --quiet --no-install react-native config' command from '/Users/b1ng/rn/test' directory to output valid JSON, but it didn't. This may be caused by npx resolving to a legacy global react-native binary. Please make sure to uninstall any global 'react-native' binaries: 'npm uninstall -g react-native react-native-cli' and try again

* 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://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
:ReactNative:Failed to parse React Native CLI configuration: groovy.json.JsonException: 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.
^

FAILURE: Build failed with an exception.

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

* What went wrong:
A problem occurred evaluating script.
> Failed to parse React Native CLI configuration. Expected running 'npx --quiet --no-install react-native config' command from '/Users/b1ng/rn/test' directory to output valid JSON, but it didn't. This may be caused by npx resolving to a legacy global react-native binary. Please make sure to uninstall any global 'react-native' binaries: 'npm uninstall -g react-native react-native-cli' and try again

* 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 checkExecSyncError (child_process.js:603:11)
    at execFileSync (child_process.js:621:15)
    at runOnAllDevices (/Users/b1ng/rn/test/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:39)
    at buildAndRun (/Users/b1ng/rn/test/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:158:41)
    at /Users/b1ng/rn/test/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/test/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.
thymikee commented 4 years ago

Have you seen the error message?

Failed to parse React Native CLI configuration. Expected running 'npx --quiet --no-install react-native config' command from '/Users/b1ng/rn/test' directory to output valid JSON, but it didn't. This may be caused by npx resolving to a legacy global react-native binary. Please make sure to uninstall any global 'react-native' binaries: 'npm uninstall -g react-native react-native-cli' and try again

b1ngx commented 4 years ago

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.

bneigher commented 4 years ago

I am seeing this after upgrading to 0.61.4 react-native. I've never installed react-native or react-native-cli globally. Commenting back in the 2nd argument here didn't change it for me

grabbou commented 4 years ago

Looks like the JSON is invalid and react-native config works w/o issues here. So, to verify, could you run npx --quiet --no-install react-native config yourself and tell us what's the output? The CLI clearly has issues parsing the configuration.

sibelius commented 4 years ago

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"
` ``
rvgroup commented 4 years ago

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

grabbou commented 4 years ago

@sibelius thanks! I remember @thymikee was saying --quiet mode did have its issues while running with npx. I will look into it this week.

sibelius commented 4 years ago

another problem with npx that we can have mismatch version of react-native if you have many different projects in different react-native versions

sagargulati commented 4 years ago

Any fix for this?

C:\Users\Sagar\Apps\react\gameapp>npx react-native info
info Fetching system and libraries information...
System:
    OS: Windows 10 10.0.17134
    CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
    Memory: 4.37 GB / 11.88 GB
  Binaries:
    Node: 13.3.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.19.0 - C:\Users\Sagar\AppData\Roaming\npm\yarn.CMD
    npm: 6.13.1 - C:\Users\Sagar\AppData\Roaming\npm\npm.CMD
  SDKs:
    Android SDK:
      API Levels: 19, 21, 22, 23, 24, 25, 26, 27, 28, 29
      Build Tools: 25.0.3, 26.0.2, 27.0.3, 28.0.0, 28.0.3, 29.0.0
      System Images: android-21 | Intel x86 Atom, android-23 | Google APIs Intel x86 Atom_64, android-25 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-Q | Google Play Intel x86 Atom
  IDEs:
    Android Studio: Version  3.5.0.0 AI-191.8026.42.35.5977832
  npmPackages:
    react: 16.9.0 => 16.9.0
    react-native: 0.61.5 => 0.61.5
npx react-native --version
3.0.4
C:\Users\Sagar\Apps\react\gameapp>react-native --version
react-native-cli: 2.0.1
react-native: 0.61.5
sagargulati commented 4 years ago

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
Idimma commented 4 years ago

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

nonewcode commented 4 years ago

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.

This fixed the issue for me

pstanton commented 4 years ago

react native - 10% of time coding, 90% of time configuring

rvgroup commented 4 years ago

react native - 10% of time coding, 90% of time configuring

Wellcome to https://flutter.dev/ :)

jfrolich commented 4 years ago

Same issue here on CI. Locally it works. Perhaps it's because it is using npx and we use yarn?

thymikee commented 4 years ago

We use npx because it should be universally available along with Node.js. Using yarn to install deps shouldn't matter, but we've seen some reports of npx not behaving as advertised.

jfrolich commented 4 years ago

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.

jfrolich commented 4 years ago

It's definitely the npx command that not behaving well. The old version of cli-platform-android works perfectly fine. The working version is: "3.0.0-alpha.2"

jfrolich commented 4 years ago

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"
  },
rzane commented 4 years ago

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

rzane commented 4 years ago

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

jfrolich commented 4 years ago

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.

Ah! this is exactly the same situation as we have!

AlexandreLage commented 4 years ago

I indeed removed 'react-native-cli' and 'react-native' global packages with

yarn global remove react-native-cli react-native and npm uninstall -g react-native-cli react-native

But I guess I only really needed to enter android folder and run ./gradlew clean

Kinda of what @sagargulati pointed out. Except I did not edit the _nativemodules.gradle file.

I wish you all nice holidays

cahhvoy commented 4 years ago

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.

jfrolich commented 4 years ago

I indeed removed 'react-native-cli' and 'react-native' global packages with

yarn global remove react-native-cli react-native and npm uninstall -g react-native-cli react-native

But I guess I only really needed to enter android folder and run ./gradlew clean

Kinda of what @sagargulati pointed out. Except I did not edit the _nativemodules.gradle file.

I wish you all nice holidays

Do you also have a monorepo where the app resides in a subfolder when compiling on app center?

SaeedZhiany commented 4 years ago

None of the answers works,

I run npm uninstall -g react-native-cli react-native for being sure that the tools removed globally. but I just got up to date in 0.034s message in cmd. (I don't know it's normal or not) still doesn't fix.

here is my result of npx.cmd --quiet --no-install react-native config

{
  "root": "C:\\Users\\SAEED\\Desktop\\MyTSProject",
  "reactNativePath": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\node_modules\\react-native",
  "dependencies": {
    "react-native-svg": {
      "root": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\node_modules\\react-native-svg",
      "name": "react-native-svg",
      "platforms": {
        "ios": {
          "sourceDir": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\node_modules\\react-native-svg\\ios",
          "folder": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\node_modules\\react-native-svg",
          "pbxprojPath": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\node_modules\\react-native-svg\\ios\\RNSVG.xcodeproj\\project.pbxproj",
          "podfile": null,
          "podspecPath": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\node_modules\\react-native-svg\\RNSVG.podspec",
          "projectPath": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\node_modules\\react-native-svg\\ios\\RNSVG.xcodeproj",          "projectName": "RNSVG.xcodeproj",
          "libraryFolder": "Libraries",
          "sharedLibraries": [],
          "plist": [],
          "scriptPhases": []
        },
        "android": {
          "sourceDir": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\node_modules\\react-native-svg\\android",
          "folder": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\node_modules\\react-native-svg",
          "packageImportPath": "import com.horcrux.svg.SvgPackage;",
          "packageInstance": "new SvgPackage()"
        }
      },
      "assets": [],
      "hooks": {},
      "params": []
    }
  },
  "commands": [
    {
      "name": "log-ios",
      "description": "starts iOS device syslog tail"
    },
    {
      "name": "run-ios",
      "description": "builds your app and starts it on iOS simulator",
      "examples": [
        {
          "desc": "Run on a different simulator, e.g. iPhone 5",
          "cmd": "react-native run-ios --simulator \"iPhone 5\""
        },
        {
          "desc": "Pass a non-standard location of iOS directory",
          "cmd": "react-native run-ios --project-path \"./app/ios\""
        },
        {
          "desc": "Run on a connected device, e.g. Max's iPhone",
          "cmd": "react-native run-ios --device \"Max's iPhone\""
        },
        {
          "desc": "Run on the AppleTV simulator",
          "cmd": "react-native run-ios --simulator \"Apple TV\"  --scheme \"helloworld-tvOS\""
        }
      ],
      "options": [
        {
          "name": "--simulator [string]",
          "description": "Explicitly set simulator to use. Optionally include iOS version betweenparenthesis at the end to match an exact version: \"iPhone 6 (10.0)\"",
          "default": "iPhone 11"
        },
        {
          "name": "--configuration [string]",
          "description": "Explicitly set the scheme configuration to use",
          "default": "Debug"
        },
        {
          "name": "--scheme [string]",
          "description": "Explicitly set Xcode scheme to use"
        },
        {
          "name": "--project-path [string]",
          "description": "Path relative to project root where the Xcode project (.xcodeproj) lives.",
          "default": "ios"
        },
        {
          "name": "--device [string]",
          "description": "Explicitly set device to use by name.  The value is not required if you have a single device connected."
        },
        {
          "name": "--udid [string]",
          "description": "Explicitly set device to use by udid"
        },
        {
          "name": "--no-packager",
          "description": "Do not launch packager while building"
        },
        {
          "name": "--verbose",
          "description": "Do not use xcpretty even if installed"
        },
        {
          "name": "--port [number]",
          "default": 8081
        },
        {
          "name": "--terminal [string]",
          "description": "Launches the Metro Bundler in a new window using the specified terminal path."
        }
      ]
    },
    {
      "name": "log-android",
      "description": "starts logkitty"
    },
    {
      "name": "run-android",
      "description": "builds your app and starts it on a connected Android emulator or device",
      "options": [
        {
          "name": "--root [string]",
          "description": "Override the root directory for the android build (which contains the android directory)",
          "default": ""
        },
        {
          "name": "--variant [string]",
          "description": "Specify your app's build variant",
          "default": "debug"
        },
        {
          "name": "--appFolder [string]",
          "description": "Specify a different application folder name for the android source. If not, we assume is \"app\"",
          "default": "app"
        },
        {
          "name": "--appId [string]",
          "description": "Specify an applicationId to launch after build.",
          "default": ""
        },
        {
          "name": "--appIdSuffix [string]",
          "description": "Specify an applicationIdSuffix to launch after build.",
          "default": ""
        },
        {
          "name": "--main-activity [string]",
          "description": "Name of the activity to start",
          "default": "MainActivity"
        },
        {
          "name": "--deviceId [string]",
          "description": "builds your app and starts it on a specific device/simulator with the given device id (listed by running \"adb devices\" on the command line)."
        },
        {
          "name": "--no-packager",
          "description": "Do not launch packager while building"
        },
        {
          "name": "--port [number]",
          "default": 8081
        },
        {
          "name": "--terminal [string]",
          "description": "Launches the Metro Bundler in a new window using the specified terminal path."
        },
        {
          "name": "--tasks [list]",
          "description": "Run custom Gradle tasks. By default it's \"installDebug\""
        },
        {
          "name": "--no-jetifier",
          "description": "Do not run \"jetifier\" – the AndroidX transition tool. By default it runs before Gradle to ease working with libraries that don't support AndroidX yet. See more at: https://www.npmjs.com/package/jetifier.",
          "default": false
        }
      ]
    }
  ],
  "assets": [],
  "platforms": {
    "ios": {},
    "android": {}
  },
  "haste": {
    "providesModuleNodeModules": [
      "react-native"
    ],
    "platforms": [
      "ios",
      "android"
    ]
  },
  "project": {
    "ios": {
      "sourceDir": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\ios",
      "folder": "C:\\Users\\SAEED\\Desktop\\MyTSProject",
      "pbxprojPath": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\ios\\MyTSProject.xcodeproj\\project.pbxproj",
      "podfile": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\ios\\Podfile",
      "podspecPath": null,
      "projectPath": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\ios\\MyTSProject.xcodeproj",
      "projectName": "MyTSProject.xcodeproj",
      "libraryFolder": "Libraries",
      "sharedLibraries": [],
      "plist": [],
      "scriptPhases": []
    },
    "android": {
      "sourceDir": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\android\\app",
      "isFlat": false,
      "folder": "C:\\Users\\SAEED\\Desktop\\MyTSProject",
      "stringsPath": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\android\\app\\src\\main\\res\\values\\strings.xml",
      "manifestPath": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\android\\app\\src\\main\\AndroidManifest.xml",
      "buildGradlePath": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\android\\app\\build.gradle",
      "settingsGradlePath": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\android\\settings.gradle",
      "assetsPath": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\android\\app\\src\\main\\assets",
      "mainFilePath": "C:\\Users\\SAEED\\Desktop\\MyTSProject\\android\\app\\src\\main\\java\\com\\mytsproject\\MainApplication.java",
      "packageName": "com.mytsproject"
    }
  }
}
nabil-hamisa commented 4 years ago

check if your running react-native run-android twice in a separate terminal that could be causing the problem

SaeedZhiany commented 4 years ago

it's for a few days ago, so I can't remember exactly, but usually I start one react-native instance (using react-native start) to make sure all of next commands using same react-native instance process and then run react-native run-android instances. However, I'll check it again, Thanks

GoldenMaximo commented 4 years ago

it's for a few days ago, so I can't remember exactly, but usually I start one react-native instance (using react-native start) to make sure all of next commands using same react-native instance process and then run react-native run-android instances. However, I'll check it again, Thanks

Pretty much what worked for me. I wasn't running react-native start before react-native run-android. That and doing cd android then gradlew clean also helps.

grabbou commented 4 years ago

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.

cahhvoy commented 4 years ago

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

camilo86 commented 4 years ago

I was seeing the same issue. I did the following to fix it:

running npx react-native run-android now works again 😆

andriadze commented 4 years ago

Okay for me it was something different. I was using nvm with lower node(7.4.0) as a default version. I thought I specified nvm to use latest for this Project folder, but it did not work.

After setting latest node as global default in nvm it fixed the issue.

Also, funny thing is project was running fine with run-android but would not sync in Android Studio.

iamadityaaz commented 4 years ago

yarn add @react-native-community/cli-platform-android@3.0.3 yarn add react-native@0.61.5

Simply , below code solved for me :

yarn add @react-native-community/cli-platform-android@3.0.3
yarn add react-native@0.61.5
SaeedZhiany commented 4 years ago

@trrfrr

Sorry for late, I created a new project using

npx react-native init TestProject --template react-native-template-typescript

When I run react run-android it opens a new cmd to start nodejs (so I'm pretty sure always one run-android command is running) but when it tries to build android apk it gives me this error:

unlike to @b1ngx's log file, I have an error in line 200. I check the line in native_modules.gradle file, an exception thrown at the line that its message is already printed in the console log, so it does not help me to find what is wrong.

:ReactNative:Failed to parse React Native CLI configuration: java.lang.RuntimeException: Unable to load FastStringService

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\SAEED\workspace\TestProject\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 200

* What went wrong:
A problem occurred evaluating script.
> Failed to parse React Native CLI configuration. Expected running 'npx.cmd --quiet --no-install react-native config' command from 'C:\Users\SAEED\workspace\TestProject' directory to output valid JSON, but it didn't. This may be caused by npx resolving to a legacy global react-native binary. Please make sure to uninstall any global 'react-native' binaries: 'npm uninstall -g react-native react-native-cli' and try again

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

@iamadityaaz I checked cli-platform-android version, the init command install version 3.0.3 itself, so there is no need to installing it manually

image

Also, I have previously uninstalled the global react-native and react-native-cli packages

SaeedZhiany commented 4 years ago

I think I found what is wrong with my project, I'm using gradle wrapper version 5.6 which has a bug with new JsonSlurper().parseText(reactNativeConfigOutput) statement, you can see related issue here.

So upgrading to an upper version like 5.6.4 solved my problem.

@grabbou

is it possible to somehow check the Gradle wrapper version in the native_modules.gradle and show a better error message if the user Gradle wrapper version is 5.6, or at least document this in *Get start** page in RN website?

grabbou commented 4 years ago

is it possible to somehow check the Gradle wrapper version in the native_modules.gradle and show a better error message if the user Gradle wrapper version is 5.6, or at least document this in Get start* page in RN website?

This is a good idea. I would recommend sending a PR to the CLI that adds "Troubleshooting" section to the main readme.

iamadityaaz commented 4 years ago

@trrfrr

Sorry for late, I created a new project using

npx react-native init TestProject --template react-native-template-typescript

When I run react run-android it opens a new cmd to start nodejs (so I'm pretty sure always one run-android command is running) but when it tries to build android apk it gives me this error:

unlike to @b1ngx's log file, I have an error in line 200. I check the line in native_modules.gradle file, an exception thrown at the line that its message is already printed in the console log, so it does not help me to find what is wrong.

:ReactNative:Failed to parse React Native CLI configuration: java.lang.RuntimeException: Unable to load FastStringService

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\SAEED\workspace\TestProject\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 200

* What went wrong:
A problem occurred evaluating script.
> Failed to parse React Native CLI configuration. Expected running 'npx.cmd --quiet --no-install react-native config' command from 'C:\Users\SAEED\workspace\TestProject' directory to output valid JSON, but it didn't. This may be caused by npx resolving to a legacy global react-native binary. Please make sure to uninstall any global 'react-native' binaries: 'npm uninstall -g react-native react-native-cli' and try again

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

@iamadityaaz I checked cli-platform-android version, the init command install version 3.0.3 itself, so there is no need to installing it manually

image

Also, I have previously uninstalled the global react-native and react-native-cli packages

@SaeedZhiany What is the react-native version you are using ? And you don't need to uninstall react-native-cli globally.

SaeedZhiany commented 4 years ago

@iamadityaaz

I'm using RN v0.61.5

And you don't need to uninstall react-native-cli globally.

RN website says it's needed;

If you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues.

NightWarrior commented 4 years ago

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.

josebleles commented 4 years ago

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

THAT'S WORKING THANKS!!!!

MostafaMAbdellateif commented 4 years ago

I just deleted the build folder that's inside the android/app, i don't know what is the cause for this issue so my solution obviously may not work, but i will just leave it here in case someone has the same issue as me

MatteoAlberghini commented 4 years ago

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

This worked for me, thank you.

radihuq commented 4 years ago

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)
aaelephant commented 4 years ago

must gradel 6.2.all . it is work for me