简体   繁体   English

如何在 Android Studio 中使用 ButterKnife 修复此错误?

[英]How can I fix this error with ButterKnife in Android Studio?

Building succeeds, but running on an emulator fails with this message in the console:构建成功,但在模拟器上运行失败,并在控制台中显示以下消息:

Cause: superclass access check failed: class butterknife.compiler.ButterKnifeProcessor$RScanner (in unnamed module @0x65e8e2f6) 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 @0x65e8e2f6原因:超类访问检查失败:class butterknife.compiler.ButterKnifeProcessor$RScanner(在未命名模块@0x65e8e2f6 中)无法访问 class com.sun.tools.javac.tree.TreeScanner(在模块 jdk.compiler 中)将 com.sun.tools.javac.tree 导出到未命名模块 @0x65e8e2f6

What I've tried: Removing Butterknife from Gradle, syncing, adding back, syncing again.我尝试过的:从 Gradle 中删除 Butterknife,同步,添加回来,再次同步。 Removing the Butterknife lib completely which doesn't produce this error on-compile, but obviously fails to compile due to missing Butterknife.完全删除 Butterknife 库不会在编译时产生此错误,但显然由于缺少 Butterknife 而无法编译。

My environment: Butterknife 10.2.3 Android Grade Plugin Version: 7.1.2 - Gradle Version: 7.2 - Android Studio Bumblebee我的环境: Butterknife 10.2.3 Android Grade Plugin 版本:7.1.2 - Gradle 版本:7.2 - Android Studio Bumblebee

I've read that this error happens with other libraries in some rare cases that seem unrelated to mine and I still haven't found a solution.我读到过这个错误发生在其他库中,在极少数情况下似乎与我的无关,但我仍然没有找到解决方案。 I'm aware the Butterknife is deprecated and I should migrate to ViewBinding, but that's a big task to convert this entire project to at the moment.我知道 Butterknife 已被弃用,我应该迁移到 ViewBinding,但目前将整个项目转换为该项目是一项艰巨的任务。 Thanks!谢谢!

You should compile with a different jdk, I was compiling with a jdk which was too advanced.您应该使用不同的 jdk 进行编译,我正在使用过于高级的 jdk 进行编译。 Reverting it to jdk11 solved it for me将其还原为 jdk11 为我解决了

Please use JDK 11. though we are setting the Gradle JDK as jdk11 or correto 11, Android studio is not recognizing that.请使用 JDK 11。虽然我们将 Gradle JDK 设置为 jdk11 或 correto 11,但 Android Studio 无法识别。

Solution:解决方案:

  1. in your terminal type java --version to see it if is showing as JDK 11在您的终端类型java --version中查看它是否显示为 JDK 11

  2. If the version is not JDK 11, then set the JAVA_HOME env variable export JAVA_HOME=/Users/${echo $USER}/documents/Android\Studio.app/Contents/jre/Contents/Home如果版本不是 JDK 11,则设置JAVA_HOME环境变量export JAVA_HOME=/Users/${echo $USER}/documents/Android\Studio.app/Contents/jre/Contents/Home

  3. in your terminal type java --version to see it if is showing as JDK 11.在您的终端中输入java --version以查看它是否显示为 JDK 11。

Using ideas from answers above and using Android Studio: File |使用上述答案中的想法并使用 Android Studio:文件 | Settings |设置 | Build, Execution, Deployment |构建、执行、部署 | Build Tools |构建工具 | Gradle. Gradle JDK -> Android Studio default JDK (version 11.0.13...) Gradle。Gradle JDK -> Android Studio 默认 JDK(版本 11.0.13 ...)

On Windows, to build from terminal, also had to add在 Windows 上,要从终端构建,还必须添加

JAVA_HOME=C:\Program Files\Android\Android Studio\jre

To the File |到文件 | Settings |设置 | Terminal |航站楼 | Environment variables环境变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM