butterknife10.1.0遇到的坑

一、使用步骤

1.在app或者model的build.gradle中:

apply plugin: 'com.jakewharton.butterknife'

android {
    compileOptions {//指定Java的版本
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies{//添加依赖
     implementation "com.jakewharton:butterknife:10.1.0" 
     annotationProcessor "com.jakewharton:butterknife-compiler:10.1.0"
}

2.在工程的build.gradle中:

 dependencies{
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:10.1.0"
        classpath "com.jakewharton:butterknife-gradle-plugin:10.1.0"
}

二、遇到的坑

1.butterknife10.1.0版本需要配合androidx使用

//替换android.support包
implementation 'androidx.appcompat:appcompat:1.0.2'

2.在使用butterknife10.1.0版本时,通过@BindView(R.id.xx)注解无效,控件报NullPointerException错。

原因是我的项目设置支持使用kotlin语言,以上添加依赖是有问题的,添加依赖需要将compiler的依赖改成kapt :

dependencies{//添加依赖
     implementation "com.jakewharton:butterknife:10.1.0" 
     kapt "com.jakewharton:butterknife-compiler:10.1.0"
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值