首页 > 编程知识 正文

Java Butter Knife _ Butter Knife-给定工件包含字符串文字,其包引用' android.support.v4.content '无法安全重写

时间:2023-05-05 20:24:59 阅读:276764 作者:729

黄油刀-给定的工件包含字符串文字,其包引用'android.support.v4.content'无法安全地重写。 对于androidx

我升级了Butterknife, androidx and Jetifier,现在由于以下错误而无法成功构建:

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有关

有人知道如何解决这个问题吗?

6个解决方案

52 votes

添加最新版本的butterknive依赖项,如果它发生更改,可以在此处进行检查([https://github.com/JakeWharton/butterknife)。]它支持androidX。 然后转到您的应用构建版本,并用以下内容替换旧版本:

dependencies {

implementation 'com.jakewharton:butterknife:10.0.0'

annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'

}

Shid answered 2020-07-06T03:01:30Z

38 votes

新的正确答案:

Butterknife 10.0.0添加了对AndroidX的支持。

dependencies {

implementation 'com.jakewharton:butterknife:10.0.0'

annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'

}

黄油刀<10.0.0的旧答案:

尝试从喷射器中将黄油刀列入黑名单:

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'

}

}

Jorge Gil answered 2020-07-06T03:01:09Z

22 votes

对于androidx,只需将您的依赖项升级到版本“ 10.0.0”

dependencies {

implementation 'com.jakewharton:butterknife:10.0.0'

annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'

}

在此处查找文档

Rishabh Saxena answered 2020-07-06T03:01:54Z

7 votes

将ButterKnife升级到最新版本,并确保将其添加到build.gradle(app)中:

android {

...

compileOptions {

sourceCompatibility JavaVersion.VERSION_1_8

targetCompatibility JavaVersion.VERSION_1_8

}

}

twenk11k answered 2020-07-06T03:02:14Z

1 votes

如果您使用的是热情的老虎,哪个版本? 最新版本9.0.0-rc2支持androidx。

UPD:Butterknife的github存储库上有一个已关闭的问题。 临时解决方法

将android.jetifier.blacklist = butterknife-compiler添加到gradle.properties文件中。

Konstantin Berkov answered 2020-07-06T03:02:43Z

1 votes

使用最新版本的Butterknife解决了该问题。 使用> = 9.0.0-rc2(Butterknife版本)来支持androidX。对于最新版本,请检查链接-[https://github.com/JakeWharton/butterknife/releases]

Chahat Jain answered 2020-07-06T03:03:03Z

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。