错误:未找到注释处理器'__gen.AnnotationProcessorWrapper_debug_android_databinding_annotationprocessor_ProcessDataBinding'
所以,我试图用Kotlin构建我的Android项目,并添加Android DataBinding库。 在Android Studio 2.2.3中没有问题。 但是在更新到最新的Android Studio版本(2.3.0)之后,当尝试运行应用程序时出现此错误。
这是我的项目的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' } } ...
这里是我的应用程序的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库工作? 请帮忙。 提前致谢。
编辑:
基于@Rene的答案,我试图用kotlin-kapt替换kotlin-android-extensions ,但是当我尝试同步gradle的时候,又出现了一个错误。
任何人有什么错误从这个错误? 谢谢
修复这个工作:
原来我只需要在我的gradle中更新一些与Dagger2相关的行。 我从我的项目的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'
我从这篇文章中得到了这个设置
这是我的build.gradle内容,适合我。
项目的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 }
应用程序的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() }
谢谢。
从Kotlin 1.1开始,我不得不切换到更新的Kotlin注释处理器。
像这样应用它:
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt'
我发现它在kotlin-1-0-6-is- 1.0.6版本中首次提到
- 从构建脚本类路径中移除
android-apt
插件。 - 在依赖配置中使用
kapt
而不是apt
/annotationProcessor
。 - 添加
kapt 'com.android.databinding:compiler:2.3.0'
到您的依赖项,因为Kotlin + Android Build Plugin 2.3.0与数据绑定组合被打破。
我认为会发生的是, kapt
是取代注释处理器,而不是从2.3.0以上拿起注释处理器配置,这是数据绑定使用,而不是android-apt
插件。
另请参阅: https : //code.google.com/p/android/issues/detail?id=228983
如果你没有使用Kotlin:
- 从构建脚本类路径中移除
android-apt
插件。 - 在依赖配置中使用
annotationProcessor
而不是apt
。
今天升级到Kotlin 1.1时遇到了同样的问题。
“固定”它通过回滚到2.2.2
我在我的项目中根本不使用apt,可能与数据绑定库有关。 我使用kapt领域,butterknife,匕首和数据绑定。
- Kotlin和Dagger:我可以使用@Inject的对象仍然可以为空/可选?
- 错误:error.NonExistentClass Kotlin在多模块Dagger项目中
- 参数不匹配; SimpleXML的
- 未解决的参考DaggerApplicationComponent
- Moshi的定制适配器与RxAndroid&Retrofit&Kotlin
- AndroidInjector <android.app.Activity>不能提供@ Provide或者@ Produces注解的方法
- 为什么在编译时使用kotlin在Dagger2中使用Scopes和Singleton注释会导致错误?
- Kapt generatestubs – 不能用单元测试的内部构造函数初始化对象
- HttpLoggingInterceptor不与日志记录2