解决AGP升级到8.0后编译报错kaptGenerateStubsDebugKotlin

ops/2024/10/21 3:26:06/

问题描述

升级了Gradle插件到8.0,运行报以下错误.

Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'kaptGenerateStubsDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

解决方案

看错误是Kapt和java版本不兼容,根据提示的网站地址(https://kotl.in/gradle/jvm/toolchain),AGP版本小于8.1.0,需要显式的设置jdk的兼容版本。如果不指定版本,Android默认使用的是JDK1.8。

A warning for Android users. To use Gradle toolchain support, use the Android Gradle plugin (AGP) version 8.1.0-alpha09 or higher.Gradle Java toolchain support is available only from AGP 7.4.0. Nevertheless, because of this issue, AGP did not set targetCompatibility to be equal to the toolchain's JDK until the version 8.1.0-alpha09. If you use versions less than 8.1.0-alpha09, you need to configure targetCompatibility manually via compileOptions. Replace the placeholder <MAJOR_JDK_VERSION> with the JDK version you would like to use:android {compileOptions {sourceCompatibility = <MAJOR_JDK_VERSION>targetCompatibility = <MAJOR_JDK_VERSION>}
}

打开app的build.gradle,在android块中添加以下代码,设置java的版本为本地对应的版本,因为我本地的是17,所以都为17.

gradle">android {....compileOptions {sourceCompatibility JavaVersion.VERSION_17targetCompatibility JavaVersion.VERSION_17}kotlinOptions {jvmTarget = '17'}....
}

重新运行,报错消失。


http://www.ppmy.cn/ops/4059.html

相关文章

Android,AMS、WMS、PKMS添加动态控制debug开关功能

问题背景 在framework源码中有很多debug开关,通常我们想要看某个模块的日志,比如说广播,就需要去修改源码,把对应的debug值改为true,但是这种方法耗时耗力,比如说我想看sendBroadcast的流程,但是BroadcastQueue中有很多debug开关,如下: 这种就需要去修改对应的源码才…

2024 抖音欢笑中国年(五):Wasm、WebGL 在互动技术中的创新应用

前言 随着 Web 前端技术的不断发展&#xff0c;越来越多的新兴技术方案被引入到 Web 开发中&#xff0c;其中 Wasm 和 WebGL 作为前端领域的两大利器&#xff0c;为开发者带来了更多的可能性。 本文将结合2024 年抖音欢笑中国年的部分项目&#xff0c;重点介绍如何利用 Wasm 和…

对单片机的一点理解

前言 大一时学过一段时间的51单片机&#xff0c;后面就一直研究STM32和算法&#xff0c;最近工作搞51单片机有半年了&#xff0c;有一些自己的想法&#xff0c;跟公司的工程师也探讨了一些&#xff0c;结合聊天记录&#xff0c;写了这篇博客&#xff0c;希望对读者有帮助。 有…

Redis从入门到精通(十六)多级缓存(一)Caffeine、JVM进程缓存

文章目录 第6章 多级缓存6.1 什么是多级缓存&#xff1f;6.2 搭建测试项目6.2.1 项目介绍6.2.2 新增商品表6.2.3 编写商品相关代码6.2.4 启动服务并测试6.2.5 导入商品查询页面&#xff0c;配置反向代理 6.3 JVM进程缓存6.3.1 Caffeine6.3.2 实现JVM进程缓存6.3.2.1 需求分析6.…

第十章 单调栈part03

今天是代码随想录一刷结束&#xff01;&#xff01; 不敢想象坚持了60天。 84. 柱状图中最大的矩形 class Solution:def largestRectangleArea(self, heights: List[int]) -> int:heights.insert(0, 0)heights.append(0)stack [0]result 0for i in range(1, len(height…

iOS依赖库版本一致性检测:确保应用兼容性

一、背景 在 iOS 应用开发的世界里&#xff0c;每次 Xcode 更新都带来了新的特性和挑战。最近的 Xcode 15 更新不例外&#xff0c;这次升级引入了对 SwiftUI 的自动强依赖。SwiftUI最低是从 iOS 13 开始支持。 这一变化也带来了潜在的兼容性问题。如果您的项目在升级到 Xcode…

最小生成树算法的实现c++

最小生成树算法的实现c 题目链接&#xff1a;1584. 连接所有点的最小费用 - 力扣&#xff08;LeetCode&#xff09; 主要思路&#xff1a;使用krusal算法&#xff0c;将边的权值进行排序&#xff08;从小到大排序&#xff09;&#xff0c;每次将权值最小且未加入到连通分量中…

docker 环境变量设置实现方式

1、前言 docker在当前运用的越来广泛&#xff0c;很多应用或者很多中间软件都有很多docker镜像资源&#xff0c;运行docker run 启动镜像资源即可应用。但是很多应用或者中间件有很多配置参数。这些参数在运用过程怎么设置给docker 容器呢&#xff1f;下面介绍几种方式 2 、do…