我升级了我的android studio to 3.4 canary,但由于以下错误,我现在无法再成功构建:

The given artifact contains a string literal with a package reference 'android.support.v4.content' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.

更多详情:

Caused by: java.lang.RuntimeException: Failed to transform '.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/9.0.0-SNAPSHOT/732f93940c74cf32a7c5ddcc5ef66e53be052352/butterknife-compiler-9.0.0-SNAPSHOT.jar' using Jetifier. Reason: The given artifact contains a string literal with a package reference 'android.support.v4.content' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.. (Run with --stacktrace for more details.)

很明显,这跟Butterknife, androidx and Jetifier有关系

有人知道怎么解决这个问题吗?

推荐答案

New correct answer:

Butterknife 10.0.0增加了对AndroidX的支持.

dependencies {
    implementation 'com.jakewharton:butterknife:10.0.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
}

Old answer for Butterknife < 10.0.0:

try 将黄油刀从jetifier中列入黑名单:

gradle.properties file:

android.jetifier.blacklist = butterknife.*\\.jar

您需要使用AGP的3.3.0-rc1和Kotlin Gradle插件的1.3.0版本:

buildscript {
    repositories {
        ...
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0-rc01'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.0"
        classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-rc2'
    }
}

Android相关问答推荐

错误:无法解析Symbol@style/Theme. Androidstudio in AndroidManifest.html for Kotlin Android Development''

Android Studio -未显示布局预览(不推荐使用安全管理器)

Jetpack创作动画断断续续变化的观点

在Jetpack Compose中实现自动换行

在Jetpack Compose中实现焦点突出的最佳方式?

使用Jetpack Compose创建特定于电视的布局

如何在Jetpack Compose android中使用导航

有没有办法让协程通道在接收时遵循特定的顺序而不是先进先出

Android WebView 不会在滚动端加载新内容

如何将一个没有 GRADLE 的古老 Android 项目导入到今天的 Android Studio 中?

组成不重叠的元素

自定义 Recyclerview [Android & Kotlin]

Jetpack Compose Material3 禁用 ListItem

如何在 Jetpack Compose 中为中心对齐设置动画?

有人可以向我解释这两个结果有什么区别吗?

如何在 Android Studio 中使用 Github Copilot?

在 Compose 中使用 DeepLink 会导致无法向后导航

操作系统会终止已启动的服务并调用Service.onDestroy吗?

AndroidX Room 生成类错误:类是公共的,应在名为 class.java 的文件中声明

如何获取 Material Design 3 的底部导航栏高度?