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

新手上路,请多包涵

我升级了我的 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

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

原文由 Tnaffh 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.4k
2 个回答

新的正确答案:

Butterknife 10.0.0 添加了对 AndroidX 的支持。

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


Butterknife < 10.0.0 的旧答案:

尝试将 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'
    }
}

原文由 Jorge Gil 发布,翻译遵循 CC BY-SA 4.0 许可协议

如果未使用 Buterknife,则更新 Buterknife + 无效缓存并重新启动 + 同步 gradle 只需清除缓存并重新启动

原文由 Moustafa Shahin 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题