31

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!

justColbs
  • 1,504
  • 2
  • 18
  • 28
  • 1
    i hope you do find an answer for this, seems like a mostly legitimate question, but in the time it takes you to find an answer you could potentially have fully implemented viewbinding already :) – a_local_nobody Feb 24 '22 at 20:48
  • @a_local_nobody That is an ironically true point and probably what I will end up doing. Trying to get lucky here lol – justColbs Feb 24 '22 at 20:53
  • 1
    that's fine, just thought it was worth pointing out because this isn't a complicated change, just one which would take time, so i figured it would be worth pointing out, while you wait you might as well start, you'll have to do this eventually anyway, might as well be productive – a_local_nobody Feb 24 '22 at 21:10
  • @a_local_nobody You've inspired me. I think I will lol thanks! – justColbs Feb 24 '22 at 21:18

8 Answers8

38

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))

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
Diederik
  • 5,536
  • 3
  • 44
  • 60
13

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

  1. https://www.oracle.com/pk/java/technologies/javase/jdk11-archive-downloads.html
  2. Download JDK 11 for your desired OS
  3. Install it
  4. 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
  5. Run The Project
  6. Boom! it's works
Zaman Rajpoot
  • 326
  • 2
  • 5
11

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

George
  • 111
  • 1
  • 3
  • 1
    I ended up upgrading a lot of the project to the latest (it was pretty outdated) and resolved it. Thank you for your response. – justColbs Jun 08 '22 at 14:54
4

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.

Chris Maggiulli
  • 3,375
  • 26
  • 39
HMI
  • 41
  • 2
4

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

Farid Z
  • 960
  • 1
  • 9
  • 18
2

Try adding following code to app build.gradle

tasks.withType(JavaCompile).configureEach{
options.fork = true
options.forkOptions.jvmArgs +=[
'--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']
}

In gradle.properties file,

android.nonFinalResIds=false
azzits
  • 345
  • 2
  • 3
  • 10
1

Deleting the folder .gradle from the folder C:\Users\yourUser.gradle\ fixed the issue.

1

please add this line in build.gradle(:app) file.

android { tasks.withType(JavaCompile).configureEach { options.fork = true options.forkOptions.jvmArgs += [ '--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED', '--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED', '--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED', '--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED', '--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED', '--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED', '--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED', '--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED', '--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED', '--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED', ] } }

MEGHA DOBARIYA
  • 1,622
  • 9
  • 7