简体   繁体   中英

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

What I've tried: Removing Butterknife from Gradle, syncing, adding back, syncing again. Removing the Butterknife lib completely which doesn't produce this error on-compile, but obviously fails to compile due to missing Butterknife.

My environment: Butterknife 10.2.3 Android Grade Plugin Version: 7.1.2 - Gradle Version: 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. Thanks!

You should compile with a different jdk, I was compiling with a jdk which was too advanced. Reverting it to jdk11 solved it for me

Please use JDK 11. though we are setting the Gradle JDK as jdk11 or correto 11, Android studio is not recognizing that.

Solution:

  1. in your terminal type java --version to see it if is showing as 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

  3. in your terminal type java --version to see it if is showing as JDK 11.

Using ideas from answers above and using Android Studio: File | Settings | Build, Execution, Deployment | Build Tools | Gradle. Gradle JDK -> Android Studio default JDK (version 11.0.13...)

On Windows, to build from terminal, also had to add

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

To the File | Settings | Terminal | Environment variables

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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