butterknife issue, after updating to latest version of android studio with latest gradle plugin

976 Views Asked by At

this is log 'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.

I expected to run it successfully

2

There are 2 best solutions below

0
Zaman Rajpoot On

After all research on this, i found solution this worked for me just add the code in your app-level gradle.build 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',
    ]
      
}
0
Atick Faisal On

A workaround can be found here:

# <app/build.gradle>

# https://stackoverflow.com/questions/65380359/lomboks-access-to-jdk-compilers-internal-packages-incompatible-with-java-16

# enable internal JDK API access at runtime
tasks.withType(JavaCompile).configureEach {
    options.fork = true
    options.forkOptions.jvmArgs += [
        # essential for butterknife
        '--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',

        # if you need Glide or LomBok
        # these may not be the exact list, but it works for me
        '--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',
    ]
}
# <gradle.properties>

# https://developer.android.com/build/releases/gradle-plugin#default-changes

# @BindView requires a constant resource ID
android.nonFinalResIds=false