[Android Studio] 解決 superclass access check failed: class butterknife.compiler.ButterKnifeProcessor$RScanner (in unnamed module @0x2f03c4fc) cannot access class com.sun.tools.javac.tree.TreeScanner

 這陣子在研究一個Sample code的時候,出現的issue如下:

superclass access check failed: class butterknife.compiler.ButterKnifeProcessor$RScanner (in unnamed module @0x2f03c4fc) cannot access class com.sun.tools.javac.tree.TreeScanner


簡單說在implementation 'com.jakewharton:butterknife:10.0.0'之後出現的問題。

實在是不知道這麼解似乎是引用的這個lib裡面有`unnamed module`照成的?


之後在網路上有找到解法如下:

Try adding the following code to the app build.gradle(project level) inside android section {}

android{
    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

for example

android {
    namespace = "com.xp.vrsr"
    compileSdk = 34

    defaultConfig {
        applicationId "com.interact.vrsrilanka"
        minSdk 24
        targetSdk 34
        versionCode 4
        versionName "1.3"
        multiDexEnabled true
    }
    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']
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
        }
    }


簡單總結的說就是在build.gradle (Module:app)裡加入:

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

就可以解決了。 (原因我也說不清…

參考:

https://stackoverflow.com/questions/71257962/how-can-i-fix-this-error-with-butterknife-in-android-studio

留言

熱門文章