首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >任务:react本机-gradle-plugin:编译plugin失败,“compileJava”任务(当前目标为1.8)和“compileKotlin”任务(当前目标为11)

任务:react本机-gradle-plugin:编译plugin失败,“compileJava”任务(当前目标为1.8)和“compileKotlin”任务(当前目标为11)
EN

Stack Overflow用户
提问于 2022-09-19 04:33:10
回答 2查看 1.7K关注 0票数 1
代码语言:javascript
复制
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文件:

代码语言:javascript
复制
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包装

代码语言:javascript
复制
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清除也会引发相同的错误。

代码语言:javascript
复制
> 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文件中

代码语言:javascript
复制
android {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
}

请帮我解决这个问题,我以前经常使用世博CLI,一切都很好,所有这些都是为了学习反应本机CLI。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-09-19 17:54:01

找到了解决方案,但不知道为什么会起作用

我使用以下命令启动构建

代码语言:javascript
复制
npm start

现在打开另一个终端并执行以下操作

代码语言:javascript
复制
npm run android

而不是

代码语言:javascript
复制
npx react-native start

代码语言:javascript
复制
npx react-native run-android

如果后者是由正式文件提出的

票数 1
EN

Stack Overflow用户

发布于 2022-09-19 06:10:27

我面临的同样问题是,所有Java包都安装或同步得很完美,但是kotlin软件包没有同步,这会引发kotlin编译错误。

我通过遵循在Android上安装kotlin软件包。

Android→首选项…→插件→浏览存储库→类型“Kotlin”在搜索框中→安装

之后,您需要从

文件->无效缓存、->失效并重新启动。

在此之后,当您的项目被重新打开和同步成功,然后清理您的项目从Build -> Clean Project

在那之后,所有的kotlin软件包都安装得很完美。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73768537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档