ReactNative:无法解析React Native CLI配置:groovy.json.JsonException:无法确定当前字符

问题描述 投票:0回答:1

开始一个新的本地反应项目,然后单击链接react native cli quickstart approach。即使我没有做任何代码更改,当我运行npx react-native run-android

时也会收到以下错误

版本信息:

    "react": "16.9.0",
    "react-native": "0.61.5"

错误信息:

: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 73
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 0

FAILURE: Build failed with an exception.

* Where:
Script 'D:\xp\feb2020xp\AwesomeProject\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 'D:\xp\feb2020xp\AwesomeProject' 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

我尝试过的内容:npm uninstall -g react-native react-native-clinpx.cmd --quiet --no-install react-native config

来自第二个命令的控制台输出:

{
  "root": "D:\\xp\\feb2020xp\\AwesomeProject",
  "reactNativePath": "D:\\xp\\feb2020xp\\AwesomeProject\\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."
        },
        {
          "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": "D:\\xp\\feb2020xp\\AwesomeProject\\ios",
      "folder": "D:\\xp\\feb2020xp\\AwesomeProject",
      "pbxprojPath": "D:\\xp\\feb2020xp\\AwesomeProject\\ios\\AwesomeProject.xcodeproj\\project.pbxproj",
      "podfile": "D:\\xp\\feb2020xp\\AwesomeProject\\ios\\Podfile",
      "podspecPath": null,
      "projectPath": "D:\\xp\\feb2020xp\\AwesomeProject\\ios\\AwesomeProject.xcodeproj",
      "projectName": "AwesomeProject.xcodeproj",
      "libraryFolder": "Libraries",
      "sharedLibraries": [],
      "plist": [],
      "scriptPhases": []
    },
    "android": {
      "sourceDir": "D:\\xp\\feb2020xp\\AwesomeProject\\android\\app",
      "isFlat": false,
      "folder": "D:\\xp\\feb2020xp\\AwesomeProject",
      "stringsPath": "D:\\xp\\feb2020xp\\AwesomeProject\\android\\app\\src\\main\\res\\values\\strings.xml",
      "manifestPath": "D:\\xp\\feb2020xp\\AwesomeProject\\android\\app\\src\\main\\AndroidManifest.xml",
      "buildGradlePath": "D:\\xp\\feb2020xp\\AwesomeProject\\android\\app\\build.gradle",
      "settingsGradlePath": "D:\\xp\\feb2020xp\\AwesomeProject\\android\\settings.gradle",
      "assetsPath": "D:\\xp\\feb2020xp\\AwesomeProject\\android\\app\\src\\main\\assets",
      "mainFilePath": "D:\\xp\\feb2020xp\\AwesomeProject\\android\\app\\src\\main\\java\\com\\awesomeproject\\MainApplication.java",
      "packageName": "com.awesomeproject"
    }
  }
}

我无法找出问题所在。请帮助我解决错误。谢谢。

react-native react-native-android build-error react-native-cli
1个回答
0
投票

我遇到了类似的问题。我的问题原来是文件android/app/src/main/AndroidManifest.xml中的语法错误。

具体来说,我有一个错误的部分,例如android:screenOrientation=portrait,而不是正确的android:screenOrientation="portrait"(请注意引号)。>>

尽管问题的具体原因可能与您不匹配,但它可能希望为您提供潜在解决方案的提示。

© www.soinside.com 2019 - 2024. All rights reserved.