You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装react-navigation后出现react-native-safe-area-context构建依赖错误求助

React Native构建失败:无法创建compileDebugKotlin任务(JvmTargetValidationMode枚举错误)

问题详情

按官方文档安装react-navigation及相关依赖后,Android构建失败,核心错误为:

Could not create task ':react-native-safe-area-context:compileDebugKotlin'.
No enum constant org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.JvmTargetValidationMode.WARN�NG

项目依赖配置:

"dependencies": {
    "@react-navigation/native": "^6.1.9",
    "@react-navigation/native-stack": "^6.9.17",
    "axios": "^1.6.2",
    "react": "18.2.0",
    "react-native": "0.72.7",
    "react-native-safe-area-context": "^4.7.4",
    "react-native-screens": "^3.27.0"
  },

完整构建错误日志:

5 actionable tasks: 5 executed

info 💡 Tip: Make sure that you have set up your development environment correctly, by running react-native doctor. To read more about doctor command visit: https://github.com/react-native-community/cli/blob/main/packages/cli-doctor/README.md#doctor


FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':react-native-safe-area-context:bundleLibCompileToJarDebug'.
> Could not determine the dependencies of null.
   > Could not create task ':react-native-safe-area-context:compileDebugKotlin'.
      > No enum constant org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.JvmTargetValidationMode.WARN�NG

* 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

BU�LD FAILED in 16s
error Failed to install the app.
info Run CLI with --verbose flag for more details.

原因分析

该错误由Kotlin Gradle插件版本与项目Kotlin版本不兼容导致。错误中的WARN�NG是编码乱码,实际对应枚举值WARNING——该枚举是在较新版本的Kotlin Gradle插件中引入的,若项目使用的Kotlin版本过低,就会出现找不到该枚举的情况。React Native 0.72.x默认适配的Kotlin版本为1.8.20左右,低于此版本易触发该问题。

解决方案

1. 升级项目Kotlin版本

打开项目根目录下的android/build.gradle文件,修改ext中的kotlinVersion为兼容版本:

buildscript {
    ext {
        kotlinVersion = "1.8.20" // 或更高兼容版本
        // 其他配置项保持不变
    }
    // 其他代码...
}

2. 清理缓存并重新构建

执行以下命令清理项目缓存:

cd android && ./gradlew clean
cd .. && npx react-native clean

重新运行项目:

npx react-native run-android

3. 降级react-native-safe-area-context(可选)

若上述步骤无效,可尝试将react-native-safe-area-context降级到适配RN 0.72.x的稳定版本:

npm install react-native-safe-area-context@4.6.3 --save

完成后重复清理缓存并重新构建。

内容的提问来源于stack exchange,提问作者Alp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 18:05:30