Butterknife issue that occurred when Android Studio was updated to the latest version and jdk was upgraded

739 Views Asked by At

I update android studio. I ran the project as usual.

In my project I use butterknife library.

When building the project, I got this error.

Cause: superclass access check failed: class butterknife.compiler.ButterKnifeProcessor$RScanner (in unnamed module @0x46be592) 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 @0x46be592

And while I was looking for a solution, butterknife issue, after updating to latest version of android studio with latest gradle plugin

found the article,

in the android section of the app-level build.gradle code

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',
     ]
      
}

When I added the following, the project built normally like a lie.

However, I understand that this approach is a kind of hacky approach.

Is there a normal approach besides these approaches?

thank you

1

There are 1 best solutions below

0
minhazur On

A better alternative is to use either JDK-8 or JDK-11.