How to solve this Butterknife dependency error? (in unnamed module @0x67c173dd)

4.2k views Asked by At

I used butterknife as one of my Dependency in one of my project though I know its deprecated but it'd be a huge work to rewrite the whole code.

build.gradle :

buildscript {
    repositories {
        maven {
            url "https://jcenter.bintray.com"
        }

        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.3.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

AndroidManifest.xml :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="nikolairb.createpdf">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
        tools:ignore="scopedStorage"/>

    <uses-feature android:name="android.hardware.camera" />
    <uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" />

    <uses-permission android:name="android.permission.CAMERA" />

    <application
        android:name="androidx.multidex.MultiDexApplication"
        android:allowBackup="true"
        android:fullBackupContent="@xml/backup_descriptor"
        android:hardwareAccelerated="true"
        android:requestLegacyExternalStorage="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:supportsRtl="true"
        android:theme="@style/AppThemeWhite"
        tools:ignore="GoogleAppIndexingWarning,RtlEnabled">
        <activity android:name=".activity.SplashActivity" android:exported="true"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
            android:exported="true"
            android:theme="@style/Base.Theme.AppCompat" />
        <activity
            android:name=".activity.MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan">

            <intent-filter>
                <action android:name="android.intent.action.SEND_MULTIPLE" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="image/*" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="image/*" />
            </intent-filter>

            <meta-data
                android:name="android.app.shortcuts"
                android:resource="@xml/shortcuts" />
        </activity>
        <activity android:name=".activity.CropImageActivity" />

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="com.swati4star.shareFile"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths" />
        </provider>

        <activity android:name=".activity.WelcomeActivity" android:exported="true"/>
        <activity android:name=".activity.ImageEditor" android:exported="true" />
        <activity android:name=".activity.PreviewActivity" android:exported="true" />
        <activity android:name=".activity.RearrangeImages" android:exported="true" />
        <activity android:name=".activity.ImagesPreviewActivity" android:exported="true"/>
        <activity android:name=".activity.RearrangePdfPages"  android:exported="true"/>
        <activity android:name=".activity.FavouritesActivity"  android:exported="true"/>
    </application>

</manifest>

The ERROR:

Execution failed for task ':app:compileDebugJavaWithJavac'. > superclass access check failed: class butterknife.compiler.ButterKnifeProcessor$RScanner (in unnamed module @0x67c173dd) 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 @0x67c173dd

Tried to update, rebuild project but it didn't help and please I cannot rewrite the entire project removing butterknife dependency.

2

There are 2 answers

0
MEGHA RAMOLIYA On BEST ANSWER
In Android studio Flamingo and above version below code working for butterknife library.

 1. add below code in build.gradle(:app) file 

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

 2. 
    android {
      ...
      // Butterknife requires Java 8.
      compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
      }
    }
    
    dependencies {
      implementation 'com.jakewharton:butterknife:10.2.3'
      annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
    }
    
     3. To use Butter Knife in a library, add the plugin to your buildscript:
    
    buildscript {
      repositories {
        mavenCentral()
        google()
      }
      dependencies {
        classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'
      }
    }
    
     4. and then apply it in your module:
    apply plugin: 'com.android.library'
    apply plugin: 'com.jakewharton.butterknife'
    
     5. Now make sure you use R2 instead of R inside all Butter Knife annotations.
    class ExampleActivity extends Activity {
      @BindView(R2.id.user) EditText username;
      @BindView(R2.id.pass) EditText password;
    ...
    }
4
Igor Román On

You don't have much choice, since in order to continue using ButterKnife you would have to downgrade to an older version of gradle (3.+) and that is no longer possible and would limit you too much.