领域和 butterknife 一起使用然后 butterknife 不起作用

realm and butterknife use together then butterknife not work

这是我项目级别的一部分build.gradle:

buildscript {
    ext.kotlin_version = '1.1.51'
    repositories {
        mavenCentral()
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
        classpath "io.realm:realm-gradle-plugin:4.3.3"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

a应用级别build.gradle:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'realm-android'

android {
    compileSdkVersion 25
    defaultConfig {
        applicationId "com.reader.hanli.reader"
        minSdkVersion 17
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

realm {
    syncEnabled = true
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:' + rootProject.supportVersion
    implementation 'com.android.support:design:' + rootProject.supportVersion
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.jakewharton:butterknife:8.4.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}

在我添加领域之前,butterknife 没问题。 而且我没有收到 butterknife 抛出的任何异常,只是

NullPointer Exception

在视图中。 那么是什么问题呢?有没有人遇到过seem的问题?

您正在使用 Kotlin,因此您应该

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt' // <-- !!!!
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'realm-android'

kapt 'com.jakewharton:butterknife-compiler:8.4.0'