给定的工件包含一个包含引用"android.support.v4.content"的字符串文字,无法安全地重写.对于androidx

Tna*_*ffh 56 android butterknife androidx android-jetifier

我升级了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.
Run Code Online (Sandbox Code Playgroud)

更多细节:

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.)
Run Code Online (Sandbox Code Playgroud)

显然,这与它有关 Butterknife, androidx and Jetifier

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

Jor*_*Gil 54

尝试将jetifier列入黑名单:

dependencies {
    implementation 'com.jakewharton:butterknife:10.0.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
}
Run Code Online (Sandbox Code Playgroud)

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

gradle.properties file:

android.jetifier.blacklist = butterknife.*\\.jar
Run Code Online (Sandbox Code Playgroud)


Shi*_*hid 54

添加最后一个版本的butterknive依赖项,如果它发生变化,可以在这里查看(https://github.com/JakeWharton/butterknife).它支持androidX.然后转到您的app build graddle并使用以下内容替换旧版本:

dependencies {
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
}
Run Code Online (Sandbox Code Playgroud)


Ris*_*ena 22

For androidx simply upgrade your dependencies to version '10.0.0'

dependencies {
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
}
Run Code Online (Sandbox Code Playgroud)

Look for documentation here


twe*_*11k 11

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

android {
...
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}
Run Code Online (Sandbox Code Playgroud)


小智 7

我的项目不使用黄油刀,但我遇到了同样的错误“给定的工件包含一个字符串文字,其中包含无法安全重写的包引用 'android.support.v4.widget'。使用注释处理器等反射的库需要手动更新以添加对 androidx 的支持“这是我为解决它所做的:更新您的 Parceler 版本

gradle 构建文件

代替:

annotationProcessor 'org.parceler:parceler:1.1.6'
implementation 'org.parceler:parceler-api:1.1.6'
Run Code Online (Sandbox Code Playgroud)

和:

  annotationProcessor 'org.parceler:parceler:1.1.13'
  implementation 'org.parceler:parceler-api:1.1.13'
Run Code Online (Sandbox Code Playgroud)

gradle文件代码 gradle 文件视图