当前位置: 首页 > article >正文

Execution failed for task ‘:app:compileDebugKotlin‘. 问题解决。

这个错误是因为你的 Kotlin 编译任务和 Java 编译任务的 JVM 目标版本不一致。具体来说,compileDebugJavaWithJavac 任务的目标版本是 1.8,而 compileDebugKotlin 任务的目标版本是 17。

要解决这个问题,你可以按照以下步骤进行:

检查 build.gradle 文件: 找到你的模块级 build.gradle 文件,通常在 app 目录下。

设置 Kotlin 和 Java 的目标版本一致: 在 android 块中,确保 Kotlin 和 Java 的版本一致。例如,如果你想把它们都设置为 1.8,可以这样做:

groovy
android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}
如果你希望使用 Java 17,则将上述所有版本改为 17:

groovy
android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = "17"
    }
}


同步 Gradle: 进行修改后,点击 Android Studio 上的 "Sync Now" 按钮以同步 Gradle。

重建项目: 同步完成后,清理并重建项目,看是否仍然存在错误。

通过上述步骤,应该可以解决由于版本不一致导致的编译问题。如果问题仍然存在,可以检查其他相关的依赖和插件,确保它们与所设置的 Java 和 Kotlin 版本兼容。

问题信息:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugKotlin'. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:130) at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:293) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:128) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:116) at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46) at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51) at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57) at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:74) at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52) at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:209) at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204) at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66) at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59) at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:166) at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59) at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52) at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:42) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:331) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:318) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.lambda$execute$0(DefaultTaskExecutionGraph.java:314) at org.gradle.internal.operations.CurrentBuildOperationRef.with(CurrentBuildOperationRef.java:85) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:314) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:303) at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:459) at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:376) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64) at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:48) Caused by: org.gradle.api.InvalidUserCodeException: Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlin' (17).


http://www.kler.cn/a/390859.html

相关文章:

  • day01-HTML-CSS——基础标签样式表格标签表单标签
  • MATLAB语言的循环实现
  • C#Halcon找线封装
  • 【Maui】动态菜单实现(绑定数据视图)
  • java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
  • HTTP-响应协议
  • java数据结构与算法:栈
  • Unity3D UI 双击和长按
  • uni-app上拉加载更多⑩
  • 掌握 Java 集合框架:从基础到高级的全面指南
  • 量化交易系统开发-实时行情自动化交易-3.4.2.Okex行情交易数据
  • MySQL 常见时间字段设置
  • class com.alibaba.fastjson2.JSONObject cannot be cast to class com.ruoyi.sys
  • Redhat8.6安装JDK1.8
  • Docker--Docker是什么和对Docker的了解
  • 【实验10】卷积神经网络(1)卷积算子
  • H5移动端预览PDF方法
  • leetcode61:旋转链表
  • DolphinDB 与南方科技大学联合授课啦!
  • LeetCode 457.环形数组是否存在循环
  • 学习python的第八天之数据类型——list列表
  • 《青牛科技GC6150:摇头机驱动芯片的卓越替代品,超越 TMI8150》
  • 设计模式-七个基本原则之一-单一职责原则 + SpringBoot案例
  • ubuntu22.04 安装FFmpeg,并进行视频的转化格式和裁剪
  • 信创替代步入快车道|暴雨助力实现信创替代目标
  • ArkTS的进阶语法-1(泛型,工具类型,空安全)