Android Studio3.4配置Butterknife

亲自捣鼓了一个上午才成功的,分享一下我的步骤,有不足的地方,请多指教,谢谢!

一:在Project的build.gradle里面引入:

dependencies {
    classpath 'com.android.tools.build:gradle:3.4.0'
    classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-rc2'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files

}

:在build.gradle(app)的dependencies里面引入:

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

注:使用时@BindView(R.id.XXX)

三:在需要使用Butterknife的build.gradle(是library)dependencies里面引入:

apply plugin: 'com.jakewharton.butterknife'

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

注:使用时@BindView(R2.id.XXX)

四:若没有出现,可以适当的进行Clean Project、Rebuild Project几次

五:为方便快速生成@BindView(R.id.XXX),下载butterknife插件:

File—>Settings—>Plugins—>下载Android ButterKnife Zelezny(在Marketplace里面搜索ButterKnife就会出现)

在activity/fragment里面,把鼠标放在R.layout.XXXXXX上:

鼠标右键—>Generate—>Generate Butterknife Injections

Alt + Insert—>Generate Butterknife Injections

 

 

 

你可能感兴趣的:(AS配置笔记)