【问题标题】:Getting the error while starting react-native project启动 react-native 项目时出现错误
【发布时间】:2022-02-01 13:41:46
【问题描述】:

我是 react-native 的初学者。在为 android 构建我的应用程序时,我收到了这个错误

Task :react-native-community_toolbar-android:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
39 actionable tasks: 39 executed
Note: /home/kanhaiya/testapp/node_modules/@react-native-community/async-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/home/kanhaiya/testapp/node_modules/@react-native-community/toolbar-android/android/src/main/java/com/reactnativecommunity/toolbarandroid/ReactToolbar.java:107: error: IconImageInfo is not abstract and does not override abstract method getExtras() in HasImageMetadata
  private static class IconImageInfo implements ImageInfo {
                 ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

FAILURE:构建失败并出现异常。

  • 出了什么问题: 任务 ':react-native-community_toolbar-android:compileDebugJavaWithJavac' 执行失败。

编译失败;有关详细信息,请参阅编译器错误输出。

  • 尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。 使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • 通过https://help.gradle.org获得更多帮助

25 秒后构建失败

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 app:installDebug -PreactNativeDevServerPort=8081
Note: /home/kanhaiya/testapp/node_modules/@react-native-community/async-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/home/kanhaiya/testapp/node_modules/@react-native-community/toolbar-android/android/src/main/java/com/reactnativecommunity/toolbarandroid/ReactToolbar.java:107: error: IconImageInfo is not abstract and does not override abstract method getExtras() in HasImageMetadata
  private static class IconImageInfo implements ImageInfo {
                 ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

FAILURE:构建失败并出现异常。

  • 出了什么问题: 任务 ':react-native-community_toolbar-android:compileDebugJavaWithJavac' 执行失败。

编译失败;有关详细信息,请参阅编译器错误输出。

  • 尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。 使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • 通过https://help.gradle.org获得更多帮助

25 秒后构建失败

at makeError (/home/kanhaiya/testapp/node_modules/execa/index.js:174:9)
at /home/kanhaiya/testapp/node_modules/execa/index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async runOnAllDevices (/home/kanhaiya/testapp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
at async Command.handleAction (/home/kanhaiya/testapp/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:192:9)

我已经在我的项目中使用react-native link @react-native-community/toolbar-android 链接了react-native-community/toolbar-android。还是报错。

【问题讨论】:

    标签: react-native gradlew react-native-community


    【解决方案1】:

    有几个步骤,你可以跟进,看看一切是否正常。

    第一种方式:

    cd Android && cd ./gradlew clean
    

    请注意: ./gradlew <follow_by_script_command> 适用于 MacOS。对于 Windows,只需执行gradlew <follow_by_script_command>

    如果你想生成一个bundle,那么在上面的命令之后这样做:

    ./gradlew :app:bundleRelease
    

    第二种方式:

    此错误的可能原因是您的 RN 版本可能与 Android 的 build.gradle 版本 不同,后者 android/app/build.gradle。当您创建 react-native 应用程序时,它可能会创建类似以下的 android 应用程序:

    implementation "com.facebook.react:react-native:+"
    

    尝试检查您的 node_modules 文件夹,查找 react-native 文件夹并查找带有数字的文件夹,该数字是 react-native 版本。对我来说是 0.66.4 然后更新 android/app/build.gradle

    implementation "com.facebook.react:react-native:0.66.4"
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-24
    • 1970-01-01
    • 2018-02-11
    • 2017-07-25
    • 2022-11-07
    • 1970-01-01
    • 2019-03-09
    • 2021-07-21
    相关资源
    最近更新 更多