React Native安卓构建失败:无法创建compileDebugKotlin任务
问题
我们有一个React Native应用,在朋友的电脑上运行完全正常,但在我的计算机上仅iOS端可正常运行。尝试构建安卓端时出现如下报错:
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':tasks'. > Could not create task ':lottie-react-native:compileDebugAndroidTestKotlin'. > 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 13s
在Android Studio中运行该应用,出现类似错误:
Multiple build operations failed. Could not create task ':lottie-react-native:compileDebugKotlin'. Could not create task ':react-native-avoid-softinput:compileDebugKotlin'. Could not create task ':react-native-gesture-handler:compileDebugKotlin'. Could not create task ':react-native-pager-view:compileDebugKotlin'. Could not create task ':react-native-safe-area-context:compileDebugKotlin'. Could not create task ':react-native-screens:compileDebugKotlin'. Could not create task ':react-native-webview:compileDebugKotlin'. Could not create task ':lottie-react-native:compileDebugKotlin'. No enum constant org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.JvmTargetValidationMode.WARNİNG
解决方案
- 检查系统区域设置,切换为英文(美国)作为默认语言/区域,重启终端或Android Studio后重新构建。
- 临时在终端设置环境变量后执行构建命令:
export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 npx react-native run-android - 在Android Studio中配置Gradle JVM参数:
打开File > Settings > Build, Execution, Deployment > Build Tools > Gradle,在Gradle JVM options中添加:-Duser.language=en -Duser.country=US - 清理项目缓存后重新构建:
cd android && ./gradlew clean cd .. && npx react-native run-android
内容的提问来源于stack exchange,提问作者emre
相关产品推荐
相关产品推荐

