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!
6
Answers
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:
in your terminal type
java --version
to see it if is showing as JDK 11If the version is not JDK 11, then set the
JAVA_HOME
env variableexport JAVA_HOME=/Users/${echo $USER}/documents/AndroidStudio.app/Contents/jre/Contents/Home
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
To the File | Settings | Terminal | Environment variables
Deleting the folder .gradle from the folder C:UsersyourUser.gradle fixed the issue.
I faced this issue just after updating android Studio to Android Studio Flamingo | 2022.2.1, my project was using embeded jdk, i fixed using simple steps
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))