首页 文章

错误:找不到注释处理器'__gen.AnnotationProcessorWrapper_debug_android_databinding_annotationprocessor_ProcessDataBinding'

提问于
浏览
3

所以,我正在尝试使用Kotlin构建我的Android项目并将Android DataBinding库添加到其中 . 在Android Studio 2.2.3中没有问题 . 但在更新到最新的Android Studio版本(2.3.0)后,我在尝试运行应用程序时遇到此错误 .

enter image description here

这是我的Project的build.gradle

buildscript {

    ext.kotlinVersion = '1.1.0'
    ext.androidGradlePluginVersion = '2.3.0'

    ...

    dependencies {
        classpath "com.android.tools.build:gradle:${androidGradlePluginVersion}"

        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

...

这是我的App的build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    ...

    packagingOptions {
        exclude 'META-INF/rxjava.properties'
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
    dataBinding.enabled = true
}

dependencies {

    ...
    compile "com.google.dagger:dagger:${daggerVersion}"
    compile "com.google.dagger:dagger-compiler:${daggerVersion}"
    provided 'javax.annotation:jsr250-api:1.0'
    kapt "com.android.databinding:compiler:$androidGradlePluginVersion"
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
}

有什么东西需要更新才能使Kotlin与Android DataBinding库一起使用吗?请帮忙 . 提前致谢 .

EDIT:

根据@Rene的回答,我尝试用 kotlin-kapt 替换 kotlin-android-extensions ,但是当我尝试同步gradle时,我又遇到了另一个错误 .

enter image description here

enter image description here

这个错误有什么问题吗?谢谢

FIX THAT WORKS:

事实证明我只需要在我的gradle中更新与Dagger2相关的一些行 . 我从我的Project的build.gradle文件中删除下面这一行 .

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

并在我的应用程序的build.gradle文件中更新与Dagger2相关的依赖项,如下所示 .

compile "com.google.dagger:dagger:${daggerVersion}"
kapt "com.google.dagger:dagger-compiler:${daggerVersion}"
provided 'org.glassfish:javax.annotation:10.0-b28'

我从这个article得到了这个设置

这是我的build.gradle内容,对我来说很有用 .

Project的build.gradle

buildscript {
    ext.kotlinVersion = '1.1.0'
    ext.androidGradlePluginVersion = '2.3.0'

    repositories {
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:${androidGradlePluginVersion}"

        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app的build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    dexOptions {
        maxProcessCount 2
        javaMaxHeapSize "2g"
    }
    defaultConfig {
        applicationId "my.application.id"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/rxjava.properties'
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
    dataBinding.enabled = true
}

kapt {
    generateStubs = true
}

ext {
    supportLibVersion = '25.2.0'
    retrofitVersion = '2.2.0'
    daggerVersion = '2.7'
    googleServiceVersion = '10.2.0'
    rxJavaVersion = '2.0.6'
    rxAndroidVersion = '2.0.1'
    glideVersion = '3.7.0'
    constraintLayoutVersion = '1.0.1'
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'

    compile "com.squareup.retrofit2:retrofit:${retrofitVersion}"
    compile "com.squareup.retrofit2:converter-gson:${retrofitVersion}"
    compile "com.squareup.retrofit2:adapter-rxjava:${retrofitVersion}"
    compile 'com.squareup.okhttp3:logging-interceptor:3.3.0'

    compile "com.android.support:support-compat:${supportLibVersion}"
    compile "com.android.support:support-core-utils:${supportLibVersion}"
    compile "com.android.support:support-core-ui:${supportLibVersion}"

    compile "com.android.support:design:${supportLibVersion}"
    compile "com.android.support:appcompat-v7:${supportLibVersion}"
    compile "com.android.support:recyclerview-v7:${supportLibVersion}"
    compile "com.android.support:cardview-v7:${supportLibVersion}"
    compile "com.android.support.constraint:constraint-layout:${constraintLayoutVersion}"

    compile "com.google.dagger:dagger:${daggerVersion}"
    kapt "com.google.dagger:dagger-compiler:${daggerVersion}"
    provided 'org.glassfish:javax.annotation:10.0-b28'

    compile 'com.android.support:multidex:1.0.1'

    compile('com.mikepenz:fastadapter:1.8.2@aar') {
        transitive = true
    }
    compile 'com.mikepenz:fastadapter-extensions:1.8.0@aar'
    compile 'com.mikepenz:materialize:1.0.0@aar'


    compile "com.google.android.gms:play-services-location:${googleServiceVersion}"
    compile "com.google.android.gms:play-services-maps:${googleServiceVersion}"

    compile "io.reactivex.rxjava2:rxjava:${rxJavaVersion}"
    compile "io.reactivex.rxjava2:rxandroid:${rxAndroidVersion}"

    compile "com.github.bumptech.glide:glide:${glideVersion}"

    kapt "com.android.databinding:compiler:$androidGradlePluginVersion"
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion"

    compile 'de.hdodenhof:circleimageview:2.1.0'
}

repositories {
    mavenCentral()
}

谢谢 .

3 回答

  • 4

    从Kotlin 1.1开始,我不得不切换到更新的Kotlin注释处理器 .

    像这样应用:

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'
    apply plugin: 'kotlin-kapt'
    

    我发现它首次在1.06发布时提到kotlin-1-0-6-is-here

  • 0
    • 从构建脚本类路径中删除 android-apt 插件 .

    • 在依赖项配置中使用 kapt 而不是 apt / annotationProcessor .

    • kapt 'com.android.databinding:compiler:2.3.0' 添加到您的依赖项,因为带有数据绑定组合的Kotlin Android Build Plugin 2.3.0已损坏 .

    我认为发生的是 kapt 正在替换注释处理器而不是拾取 annotationProcessor 配置,这是数据绑定使用的,而不是自2.3.0以来的 android-apt 插件 .

    另见:https://code.google.com/p/android/issues/detail?id=228983


    如果你没有使用Kotlin:

    • 从构建脚本类路径中删除 android-apt 插件 .

    • 在依赖项配置中使用 annotationProcessor 而不是 apt .

  • 0

    升级到Kotlin 1.1时,今天遇到了同样的问题 .

    通过回滚到平台2.2.3“固定”它

    我根本没有在我的项目中使用apt,可能与数据绑定库有关 . 我使用kapt作为领域,刀,匕首和数据绑定 .

相关问题