【问题标题】:I tried everything but it's show this error in React-Native我尝试了一切,但它在 React-Native 中显示了这个错误
【发布时间】:2022-02-10 13:16:53
【问题描述】:

我在完成我的 react js 后才开始学习 React Native,每次创建新的 React-Native 项目时都会显示此错误,我失去了学习 React-Native 的希望

error Failed to install the app. Make sure you have the Android development environment 
set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01

FAILURE: Build failed with an exception.

  * What went wrong:
    Execution failed for task ':app:processDebugMainManifest'.
    > Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @36838899       

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

at makeError (D:\React-Native\React Native Cli\AwesomeProject\node_modules\execa\index.js:174:9)
at D:\React-Native\React Native Cli\AwesomeProject\node_modules\execa\index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)       
at async runOnAllDevices (D:\React-Native\React Native Cli\AwesomeProject\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
at async Command.handleAction (D:\React-Native\React Native Cli\AwesomeProject\node_modules\@react-native-community\cli\build\index.js:192:9)## Heading ##

【问题讨论】:

标签: react-native


【解决方案1】:

如果您在运行 react-native run-android 时收到错误消息,请尝试转到 android 文件夹并清理 gradlew cd android && ./gradlew clean 您也可以尝试运行chmod +x gradlew

您的项目应该已成功启动

或访问here

【讨论】:

    【解决方案2】:

    首先确保您的环境设置正确,正如documentation 所说。

    如果是这样,请尝试以下方法:

    1. cd android 然后./gradlew clean
    2. 否则尝试删除node modules 并运行npm install

    【讨论】:

      【解决方案3】:

      检查您是否需要像 build.gradle 一样编辑 AndroidManifest.xml 中的 uses-sdk

      <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="14" />
      

      还有 android 部分,尤其是 build.gradle 文件中的 minSdkVersion 和 targetSdkVersion

      android {
          compileSdkVersion 17
          buildToolsVersion "17.0.0"
      
          defaultConfig {
              minSdkVersion 11
              targetSdkVersion 14
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2020-11-08
        • 1970-01-01
        • 1970-01-01
        • 2022-01-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多