android集成butterknife异常

  • androidx:android.support.xxx 包过于混乱,官方整理后产物,
  • support-v4:4在这里指的是Android API版本号,库中提供的API会向下兼容到Android 1.6系统。
  • support-v7:7同理,库中提供的API会向下兼容到Android 2.1系统。

为项目添加butterknife功能的时候,因为使用了androidx 碰到问题异常报错如下:

Execution failed for task ':app:javaPreCompileDebug'.
> Could not resolve all files for configuration ':app:debugAnnotationProcessorClasspath'.
   > Failed to transform butterknife-compiler-8.8.1.jar (com.jakewharton:butterknife-compiler:8.8.1) to match attributes {artifactType=processed-jar, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for JetifyTransform: /Users/mahui/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/8.8.1/b2f4505a1babb7b7c11abbbf8ea4c90b18c3aeac/butterknife-compiler-8.8.1.jar.
         > Failed to transform '/Users/mahui/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/8.8.1/b2f4505a1babb7b7c11abbbf8ea4c90b18c3aeac/butterknife-compiler-8.8.1.jar' using Jetifier. Reason: AmbiguousStringJetifierException, message: 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.)
           This is a known exception, and Jetifier won't be able to jetify this library.
           Suggestions:
            - If you believe this library doesn't need to be jetified (e.g., if it already supports AndroidX, or if it doesn't use support libraries/AndroidX at all), add android.jetifier.blacklist = {comma-separated list of regular expressions (or simply names) of the libraries that you don't want to be jetified} to the gradle.properties file.
            - If you believe this library needs to be jetified (e.g., if it uses old support libraries and breaks your app if it isn't jetified), contact the library's authors to update this library to support AndroidX and use the supported version once it is released.
           If you need further help, please leave a comment at https://issuetracker.google.com/issues/140747218.

报错原因是没有:android.support.v4.content.


为解决这个问题:butterknife 也对应升级。
最新butterknife版本已升级到:10.2.3


处理方式:
1:添加:android.support.v4.content包依赖
implementation 'com.android.support:support-v4:28.4.1'
2:添加
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
3:更新butterknife
implementation "com.jakewharton:butterknife:10.2.3"
    annotationProcessor "com.jakewharton:butterknife-compiler:10.2.3"

    

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值