android studio使用ButterKnife 8.0.1报空指针错误以及点击事件无效的解决方法

1.Project的build.gradle文件中增加classpath

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0-alpha4'
        **classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'**
    }
}

allprojects {
    repositories {
        jcenter()
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

2.在Module的build.gradle文件中增加plugin 
apply plugin: ‘com.Android.application’ 
apply plugin: ‘com.neenbedankt.android-apt’

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId "kdb.wq.com.kdb"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha3'
    testCompile 'junit:junit:4.12'
    **compile 'com.jakewharton:butterknife:8.0.1'**
    **apt 'com.jakewharton:butterknife-compiler:8.0.1'**
}

猜你喜欢

转载自blog.csdn.net/syusikoku/article/details/54587504