如何解决这个 Butterknife 依赖错误? (在未命名模块@0x67c173dd)

问题描述 投票:0回答:2

我在一个项目中使用了 butterknife 作为我的依赖项之一,尽管我知道它已被弃用,但重写整个代码将是一项艰巨的工作。

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>

错误

任务“:app:compileDebugJavaWithJavac”执行失败。 > 超类访问检查失败:类 butterknife.compiler.ButterKnifeProcessor$RScanner (在未命名模块 @0x67c173dd 中)无法访问类 com.sun.tools.javac.tree.TreeScanner (在模块 jdk.compiler 中),因为模块 jdk.compiler 不访问将 com.sun.tools.javac.tree 导出到未命名模块 @0x67c173dd

尝试更新、重建项目,但没有帮助,我无法重写整个项目删除黄油刀依赖性。

java android butterknife
2个回答
1
投票

您没有太多选择,因为为了继续使用 ButterKnife,您必须降级到旧版本的 gradle (3.+),而这不再可能,并且会限制您太多。


0
投票

请将此行添加到 build.gradle(:app) 文件中。

安卓{ tasks.withType(JavaCompile).configureEach { 选项.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', ] } }

© www.soinside.com 2019 - 2024. All rights reserved.