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

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'
    
}

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

  

 

  

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值