ButterKnife配置及使用教程及报错解决

参考博客:

https://www.jianshu.com/p/eaafc13e71ba

https://www.cnblogs.com/chenyangsocool/p/9565730.html

https://www.jianshu.com/p/7c20d777578f

安装方法:

打开androidstudio,file->settings->plugins->marketplugins->android butterknife zelezny:install->重启android studio

配置方法:

1.添加在线依赖库,一行代码,在project下的build.gradle的repositories括号里添加两遍。

maven { url "https://oss.sonatype.org/content/repositories/snapshots" }

2.配置刚刚添加的

依赖库,就是加两行代码。在app下的build.gradle里加上

    implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
    annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'

使用方法:将鼠标放在activity文件中引用的layout文件名上,右击选中generate点击“generate butterknife injections”,点击“confirm”即可

----------------------------------------------------------------一条很有必要的分割线----------------------------------------------------------------------

昨晚以上步骤,我以为一切都搞定了。然而现实却是:在编译app时候报错了“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.”

一番搜索后了解到,是butterknife的版本太旧导致的,于是修改了一下版本:

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

结果又报了新错误:“Error: Static interface methods are only supported starting with Android N (--min-api 24): void butterknife.Unbinder.lambda$static$0()”,在app的build.gradle中加个编译选项即可。

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值