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我见过涉及更改类路径()和分发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包装
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清除也会引发相同的错误。
> 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()
}
}请帮我解决这个问题,我以前经常使用世博CLI,一切都很好,所有这些都是为了学习反应本机CLI。
发布于 2022-09-19 17:54:01
找到了解决方案,但不知道为什么会起作用
我使用以下命令启动构建
npm start现在打开另一个终端并执行以下操作
npm run android而不是
npx react-native start和
npx react-native run-android如果后者是由正式文件提出的
发布于 2022-09-19 06:10:27
我面临的同样问题是,所有Java包都安装或同步得很完美,但是kotlin软件包没有同步,这会引发kotlin编译错误。
我通过遵循这在Android上安装kotlin软件包。
Android→首选项…→插件→浏览存储库→类型“Kotlin”在搜索框中→安装
之后,您需要从
文件->无效缓存、->失效并重新启动。
在此之后,当您的项目被重新打开和同步成功,然后清理您的项目从Build -> Clean Project。
在那之后,所有的kotlin软件包都安装得很完美。
https://stackoverflow.com/questions/73768537
复制相似问题