账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    react-native run-android运行报错
    42
    0

    电脑已安装环境 

    Python 2

    Node.js

    react-native命令行工具(react-native-cli) 

    jdk 

    android studio

    ANDROID_HOME 环境变量配置  

    android SDK的Tools目录添加到系统环境变量中去  

    Genymotion

    并且已经cmd测试安装成功。

    运行报错信息如下:

    C:\RN\rnapp>react-native run-android

    warn Package react has been ignored because it contains invalid configuration. Reason: Cannot find module 'react\package.j

    son'

    warn Package @react-native-community/eslint-config has been ignored because it contains invalid configuration. Reason: Can

    not find module '@react-native-community\eslint-config\package.json'

    warn Package babel-jest has been ignored because it contains invalid configuration. Reason: Cannot find module 'babel-jest

    \package.json'

    warn Package eslint has been ignored because it contains invalid configuration. Reason: Cannot find module 'eslint\package

    .json'

    warn Package jest has been ignored because it contains invalid configuration. Reason: Cannot find module 'jest\package.jso

    n'

    warn Package react-test-renderer has been ignored because it contains invalid configuration. Reason: Cannot find module 'r

    eact-test-renderer\package.json'

    info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.

    Jetifier found 862 file(s) to forward-jetify. Using 4 workers...

    info Starting JS server...

    'adb' ����������ڲ��������ⲿ������Ҳ������ǿ��������ееij������

    �����������������������

    info Launching emulator...

    error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.

    warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.

    info Installing the app...

    <-------------> 0% WAITING

    > IDLE

    :ReactNative:Failed to parse React Native CLI configuration: groovy.json.JsonException: Unable to determine the current ch

    aracter, it is not a string, number, array, or object

    The current character read is 'C' with an int value of 67

    Unable to determine the current character, it is not a string, number, array, or object

    line number 1

    index number 0

    C:\RN\rnapp\node_modules\react-native\cli.js{  "root": "C:\\RN\\rnapp",  "reactNativePath": "C:\\RN\\rnapp\\node_modules\\

    react-native",  "dependencies": {},  "commands": [    {      "name": "log-ios",      "description": "starts iOS device sys

    log tail"    },    {      "name": "run-ios",      "description": "builds your app and starts it on iOS simulator",      "e

    xamples": [        {          "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": "Explicitl

    y 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]",          "desc

    ription": "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"        },        {          "na

    me": "--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": "Lau

    nches the Metro Bundler in a new window using the specified terminal path."        }      ]    },    {      "name": "log-a

    ndroid",      "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 bui

    ld 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 too

    l. By default it runs before Gradle to ease working with libraries that don't support AndroidX yet. See more at: https://w

    ww.npmjs.com/package/jetifier.",          "default": false        }      ]    }  ],  "assets": [],  "platforms": {    "ios

    ": {},    "android": {}  },  "haste": {    "providesModuleNodeModules": [      "react-native"    ],    "platforms": [

     "ios",      "android"    ]  },  "project": {    "ios": {      "sourceDir": "C:\\RN\\rnapp\\ios",      "folder": "C:\\RN\\

    rnapp",      "pbxprojPath": "C:\\RN\\rnapp\\ios\\rnapp.xcodeproj\\project.pbxproj",      "podfile": "C:\\RN\\rnapp\\ios\\P

    odfile",      "podspecPath": null,      "projectPath": "C:\\RN\\rnapp\\ios\\rnapp.xcodeproj",      "projectName": "rnapp.x

    codeproj",      "libraryFolder": "Libraries",      "sharedLibraries": [],      "plist": [],      "scriptPhases": []    },

       "android": {      "sourceDir": "C:\\RN\\rnapp\\android\\app",      "isFlat": false,      "folder": "C:\\RN\\rnapp",

      "stringsPath": "C:\\RN\\rnapp\\android\\app\\src\\main\\res\\values\\strings.xml",      "manifestPath": "C:\\RN\\rnapp\\

    android\\app\\src\\main\\AndroidManifest.xml",      "buildGradlePath": "C:\\RN\\rnapp\\android\\app\\build.gradle",      "

    settingsGradlePath": "C:\\RN\\rnapp\\android\\settings.gradle",      "assetsPath": "C:\\RN\\rnapp\\android\\app\\src\\main

    \\assets",      "mainFilePath": "C:\\RN\\rnapp\\android\\app\\src\\main\\java\\com\\rnapp\\MainApplication.java",      "pa

    ckageName": "com.rnapp"    }  }}

    ^

    FAILURE: Build failed with an exception.

    * Where:

    Script 'C:\RN\rnapp\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' comm

    and from 'C:\RN\rnapp' directory to output valid JSON, but it didn't. This may be caused by npx resolving to a legacy glob

    al react-native binary. Please make sure to uninstall any global 'react-native' binaries: 'npm uninstall -g react-native r

    eact-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 24s

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

    :ReactNative:Failed to parse React Native CLI configuration: groovy.json.JsonException: Unable to determine the current ch

    aracter, it is not a string, number, array, or object
    The current character read is 'C' with an int value of 67

    Unable to determine the current character, it is not a string, number, array, or object

    line number 1

    index number 0

    C:\RN\rnapp\node_modules\react-native\cli.js{  "root": "C:\\RN\\rnapp",  "reactNativePath": "C:\\RN\\rnapp\\node_modules\\

    react-native",  "dependencies": {},  "commands": [    {      "name": "log-ios",      "description": "starts iOS device sys

    log tail"    },    {      "name": "run-ios",      "description": "builds your app and starts it on iOS simulator",      "e

    xamples": [        {          "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": "Explicitl

    y 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]",          "desc

    ription": "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"        },        {          "na

    me": "--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": "Lau

    nches the Metro Bundler in a new window using the specified terminal path."        }      ]    },    {      "name": "log-a

    ndroid",      "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 bui

    ld 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 too

    l. By default it runs before Gradle to ease working with libraries that don't support AndroidX yet. See more at: https://w

    ww.npmjs.com/package/jetifier.",          "default": false        }      ]    }  ],  "assets": [],  "platforms": {    "ios

    ": {},    "android": {}  },  "haste": {    "providesModuleNodeModules": [      "react-native"    ],    "platforms": [

     "ios",      "android"    ]  },  "project": {    "ios": {      "sourceDir": "C:\\RN\\rnapp\\ios",      "folder": "C:\\RN\\

    rnapp",      "pbxprojPath": "C:\\RN\\rnapp\\ios\\rnapp.xcodeproj\\project.pbxproj",      "podfile": "C:\\RN\\rnapp\\ios\\P

    odfile",      "podspecPath": null,      "projectPath": "C:\\RN\\rnapp\\ios\\rnapp.xcodeproj",      "projectName": "rnapp.x

    codeproj",      "libraryFolder": "Libraries",      "sharedLibraries": [],      "plist": [],      "scriptPhases": []    },

       "android": {      "sourceDir": "C:\\RN\\rnapp\\android\\app",      "isFlat": false,      "folder": "C:\\RN\\rnapp",

      "stringsPath": "C:\\RN\\rnapp\\android\\app\\src\\main\\res\\values\\strings.xml",      "manifestPath": "C:\\RN\\rnapp\\

    android\\app\\src\\main\\AndroidManifest.xml",      "buildGradlePath": "C:\\RN\\rnapp\\android\\app\\build.gradle",      "

    settingsGradlePath": "C:\\RN\\rnapp\\android\\settings.gradle",      "assetsPath": "C:\\RN\\rnapp\\android\\app\\src\\main

    \\assets",      "mainFilePath": "C:\\RN\\rnapp\\android\\app\\src\\main\\java\\com\\rnapp\\MainApplication.java",      "pa

    ckageName": "com.rnapp"    }  }}

    ^

    FAILURE: Build failed with an exception.

    * Where:

    Script 'C:\RN\rnapp\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' comm

    and from 'C:\RN\rnapp' directory to output valid JSON, but it didn't. This may be caused by npx resolving to a legacy glob

    al react-native binary. Please make sure to uninstall any global 'react-native' binaries: 'npm uninstall -g react-native r

    eact-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 24s

        at checkExecSyncError (child_process.js:601:13)

        at execFileSync (child_process.js:621:13)

        at runOnAllDevices (C:\Users\zgwww\AppData\Roaming\npm\node_modules\react-native\node_modules\@react-native-community\

    cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:39)

        at <anonymous>

        at process._tickCallback (internal/process/next_tick.js:188:7)

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 秦小子 普通会员 1楼

      在React Native中,react-native run-android命令通常用于启动Android应用。然而,如果你在运行时收到错误,可能是由于以下原因:

      1. 确保你已经设置了Android SDK环境。你可以从Android Developers网站下载并安装最新的Android SDK。

      2. 确保你的应用和Android SDK版本匹配。例如,你的应用可能需要Android 8.0或更高版本,而Android SDK也需要与你的应用版本匹配。

      3. 如果你使用的是手动构建应用,确保你的构建设置正确。你可以在你的android/app/build.gradle文件中修改minifyEnabledcompileSdkVersiontargetSdkVersion的值。

      4. 确保你的应用有权限访问Android系统的文件和系统服务。你可以使用adb shell命令来检查你的应用是否有权限。

      5. 如果你的应用使用了特定的Android API,确保你已经安装了相应的API库。

      如果你已经尝试了上述方法但仍然遇到问题,你可能需要联系React Native的技术支持或者寻求更具体的帮助。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部