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

這樣我們就又可以使用了······

  

 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM