info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 936 file(s) to forward-jetify. Using 12 workers...
info JS server already running.
info Installing the app...
> Task :react-native-gradle-plugin:compileKotlin FAILED
'compileJava' task (current target is 1.8) and 'compileKotlin' task (current target is 11) jvm target compatibility should be set to the same Java version.
1 actionable task: 1 executed
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-gradle-plugin:compileKotlin'.
> Failed to query the value of task ':react-native-gradle-plugin:compileKotlin' property 'compilerRunner$kotlin_gradle_plugin'.
> Kotlin could not find the required JDK tools in the Java installation. Make sure Kotlin compilation is running on a JDK, not JRE.
* 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 4s
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
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-gradle-plugin:compileKotlin'.
> Failed to query the value of task ':react-native-gradle-plugin:compileKotlin' property 'compilerRunner$kotlin_gradle_plugin'.
> Kotlin could not find the required JDK tools in the Java installation. Make sure Kotlin compilation is running on a JDK, not JRE.
* 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 4s
at makeError (C:\Users\dhanp\React native projects\test3\ProjectName\node_modules\execa\index.js:174:9)
at C:\Users\dhanp\React native projects\test3\ProjectName\node_modules\execa\index.js:278:16
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async runOnAllDevices (C:\Users\dhanp\React native projects\test3\ProjectName\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
at async Command.handleAction (C:\Users\dhanp\React native projects\test3\ProjectName\node_modules\@react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details
我看到过涉及到更改classpath()和分发URL的解决方案,但我已经这样做了。
从我build.gradle文件中:
dependencies {
classpath("com.android.tools.build:gradle:7.2.1")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("de.undercouch:gradle-download-task:4.1.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
从Gradle Package 纸
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
这些都不能修复错误,另外,我注意到运行gradlew clean也会引发同样的错误
> Task :react-native-gradle-plugin:compileKotlin FAILED
'compileJava' task (current target is 1.8) and 'compileKotlin' task (current target is 11) jvm target compatibility should be set to the same Java version.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-gradle-plugin:compileKotlin'.
> Failed to query the value of task ':react-native-gradle-plugin:compileKotlin' property 'compilerRunner$kotlin_gradle_plugin'.
> Kotlin could not find the required JDK tools in the Java installation. Make sure Kotlin compilation is running on a JDK, not JRE.
* 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 4s
1 actionable task: 1 executed
我还尝试将以下代码段添加到build.gradle文件中
android {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
}
请帮助我解决这个问题,我以前使用过EXPO CLI,一切都运行良好,所有这些都是在尝试学习React-native CLI时发生的。
2条答案
按热度按时间fdx2calv1#
我面临着同样的问题,所有的Java包都安装或同步完美,但Kotlin包没有同步,它抛出了一个kotlin编译错误。
我安装Kotlin软件包在Android Studio通过以下This.
Android Studio →首选项... →插件→浏览存储库→在搜索框中键入“Kotlin”→安装
之后,您需要将此项目该高速缓存从
文件-〉使缓存无效-〉使缓存无效并重启。
之后,当您的项目重新打开并成功同步,然后从
Build -> Clean Project
清理您的项目。从那以后,Kotlin的所有软件包都安装得很完美。
20jt8wwn2#
找到了解决方案,但不知道为什么它的工作
我使用了以下命令来启动构建
现在打开另一个终端并执行以下命令
而不是
和
如果正式文件建议采用后者