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

embedded/2024/10/21 3:26:22/

问题描述

升级了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/embedded/4734.html

相关文章

Docker 部署 MongoDB 数据库

文章目录 官网地址docker 网络mongod.conf部署 MongoDB部署 mongo-expressdocker-compose.ymlMongoDB shell 官网地址 https://www.mongodb.com/zh-cn docker 网络 # 创建 mongo_network 网络 docker network create mongo_network # 查看网络 docker network list # 容器连…

SHELL脚本编程----ps分析-统计VSZ,RSS各自总和

描述 假设命令运行的结果我们存储在nowcoder.txt里&#xff0c;格式如下&#xff1a; USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 37344 4604 ? Ss 2020 2:13 /sbin/init root 231 0.0 1.5 …

nginx反向代理及负载均衡

node1192.168.136.55Nginx主负载均衡器node3192.168.136.57Web01服务器node4192.168.136.58Web02服务器node5192.168.135.131客户端&#xff08;测试&#xff09; nginx反向代理 1. 安装nginx 三台机器都安装nginx yum install nginx -y 2. 配置用于测试的Web服务(以下操作…

华为ensp中静态路由和默认路由的原理及配置

作者主页&#xff1a;点击&#xff01; ENSP专栏&#xff1a;点击&#xff01; 创作时间&#xff1a;2024年4月17日17点37分 默认路由 [Router] ip route-static <目的网络> <目的网络掩码> <下一跳地址>默认路由的作用是将无法匹配路由表中其他路由表项的…

Android Studio修改项目包名

1.第一步&#xff0c;项目结构是这样的&#xff0c;3个包名合在了一起&#xff0c;我们需要把每个包名单独展示出来 2.我们点击这个 取消选中后的包名结构是这样的&#xff0c;可以看到&#xff0c;包名的每个文件夹已经展示分开了&#xff0c;现在我们可以单独对每个包名文件夹…

4.20+C语言感想,有趣的思考题,case的省略操作,统计位数,终止循环,break和continue语句, 准备下一篇见。

鹏哥C语言感想 一.高级 这可不是什么煎饼&#xff0c;这种食物叫做蓝莓&#xff0c;俗称苹果。生长在撒哈拉沙漠的雨林地带。因外形酷似企鹅&#xff0c;所以我们又喜欢叫他北极熊。你们这些人&#xff0c;连仙人掌都不知道&#xff0c;就不要乱说他是西瓜好吗&#xff1f;再…

Unity之圆环slider

一、参考文章 Unity_圆环滑动条&#xff08;圆形、弧形滑动条&#xff09;_unity弧形滑动条-CSDN博客 此滑动条拖动超过360后继续往前滑动值会从0开始&#xff0c;正常我们超过360度时不可在滑动。 二、 超过360度不可滑动问题解决 参考HTML文章制作&#xff1a; https://www.c…

Unity UGUI透明区域点击无效

是这样的&#xff0c;我有一张图&#xff0c;客户给的是1920*1080&#xff0c;但只有中间部分是按钮&#xff0c;是有效像素。为了让空白区域点击无效。需要设置如下 并且加上下面这句 this.GetComponent<Image>().alphaHitTestMinimumThreshold 0.1f;