cli icon indicating copy to clipboard operation
cli copied to clipboard

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

Open b1ngx opened this issue 7 years ago • 57 comments

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

b1ngx avatar Nov 07 '19 08:11 b1ngx

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?

Esemesek avatar Nov 07 '19 13:11 Esemesek

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

npm uninstall -g react-native-cli

seems more appropriate.

thymikee avatar Nov 07 '19 13:11 thymikee

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

b1ngx avatar Nov 08 '19 00:11 b1ngx

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.

grabbou avatar Nov 15 '19 12:11 grabbou

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.

b1ngx avatar Nov 19 '19 01:11 b1ngx

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

thymikee avatar Nov 19 '19 07:11 thymikee

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.

b1ngx avatar Nov 20 '19 01:11 b1ngx

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

bneigher avatar Nov 23 '19 21:11 bneigher

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.

grabbou avatar Nov 24 '19 19:11 grabbou

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"
` ``

sibelius avatar Nov 26 '19 02:11 sibelius

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

rvgroup avatar Nov 27 '19 22:11 rvgroup

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

grabbou avatar Nov 28 '19 09:11 grabbou

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

sibelius avatar Nov 28 '19 12:11 sibelius

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 avatar Dec 05 '19 06:12 sagargulati

I found a workaround for this:

yarn add @react-native-community/[email protected]
yarn add [email protected]
Removed "--quiet" from npx.cmd in native_modules.gradle
cd android && gradlew clean

sagargulati avatar Dec 05 '19 07:12 sagargulati

I found a workaround for this:

yarn add @react-native-community/[email protected]
yarn add [email protected]
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

Idimma avatar Dec 06 '19 10:12 Idimma

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

nonewcode avatar Dec 09 '19 19:12 nonewcode

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

pstanton avatar Dec 11 '19 21:12 pstanton

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

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

rvgroup avatar Dec 11 '19 21:12 rvgroup

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

jfrolich avatar Dec 18 '19 10:12 jfrolich