JDK17 与 ButterKinife 冲突问题: class butterknife.compiler.ButterKnifeProcessor$RScanner

开发环境:

Android Studio Giraffe | 2022.3.1 Patch 1

Gradle插件:classpath 'com.android.tools.build:gradle:7.2.0'

Gradle版本:distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip

    Android Studio 升级到最新版后,带来一系列的更新(JDK、Gradle等),导致项目 Build 过程中错误频频,好不容易看到 Build Success 成功的字样,连接上真机设备安装过程中又报错了:

Cause: superclass access check failed: class butterknife.compiler.ButterKnifeProcessor$RScanner (in unnamed module @0x274412b0) cannot access class com.sun.tools.javac.tree.TreeScanner (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.tree to unnamed module @0x274412b0

    网上搜索了下,应该是 jdk17 与 ButterKnife 不兼容导致的,解决的办法如下:

方法一:降低JDK的版本

    在 Android Studio 的 setting - Build,Execution,Deployment - Build Tools - Gradle 可以选择下载 jdk 11 或 jdk 15, 下载成功后,重新 Build 项目即可。

如果在 Android studio 下载失败,可以自己手动到官网去下载安装,然后指定安装目录即可:

Android Studio -> File -> Project Structure -> SDK Location -> Click on Gradle Settings (blue hightlighted text) -> Select the jdk 11 with 11.0 something version name from list

方法二:编辑项目的 gradle.properties 文件

org.gradle.jvmargs=-Xmx1920M \
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

    这是在 stackoverflow 搜索找到的解决方案,解释如下:

Some of the sun libraries needs to be made visible for the newer Java compilers. See this answer for more info. I added the following to our gradle.properties file and it fixed the problem. (We use Butterknife and Realm, and needed the below three packages added. (You might get away without "javac.code" for just Butterknife))

参考:How can I fix this error with ButterKnife in Android Studio? - Stack Overflow

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

思涛的博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值