Android--我的Butterknife黄油刀怎么找不到控件了!!!

时间:2024-01-06 13:52:26

1,首先说一下Butterknife这个插件真的挺好用的,不过最近几天在写demo的时候发现总是出现绑定的view是空的,当时着急写代码,也没有深究一下,直接手工findViewbyid了,今天下午写demo的时候还是出现这个问题,就想好好的研究一下了,

一看不知道,原来是版本升级了,以前一直用的是7.0的版本

compile 'com.jakewharton:butterknife:7.0.1'

但是最近几次都是用的8.0的版本

compile 'com.jakewharton:butterknife:8.0.1'

然后果断去github上看了下官方文档,果然,麻蛋,引用都变了,所以以后变成这样了

首先在工程的gradle的这样写

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' //主要是这句话
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
} allprojects {
repositories {
jcenter()
}
} task clean(type: Delete) {
delete rootProject.buildDir
}

再看一下我们在app的gradle的使用,有了些许变化

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt' //这儿要添加
android {
compileSdkVersion 25
buildToolsVersion "25.0.0" defaultConfig {
applicationId "com.qianmo.myview2"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
} dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.+'
compile 'com.android.support:recyclerview-v7:25.+'
compile 'com.android.support:cardview-v7:25.+'
compile 'com.balysv:material-ripple:1.0.2'
//下面两句就是依赖了
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1' }

这样我们就又可以使用了······