Android,领域,Gradle:错误:注释处理器:找不到RealmProcessor

Android Studio 2.3.3

我的项目bulid.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_version = '1.1.3' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.google.gms:google-services:2.0.0-alpha6' classpath "io.realm:realm-gradle-plugin:3.5.0" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() maven { url 'https://dl.bintray.com/jetbrains/anko' } } } task clean(type: Delete) { delete rootProject.buildDir } repositories { mavenCentral() } 

我的应用程序build.gradle。

 buildscript { repositories { maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'io.fabric.tools:gradle:1.+' } } apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'io.fabric' repositories { maven { url 'https://maven.fabric.io/public' } mavenCentral() } android { compileSdkVersion 25 buildToolsVersion "25.0.0" dexOptions { jumboMode = true } defaultConfig { applicationId "my.project.com" minSdkVersion 15 targetSdkVersion 23 versionCode 53 versionName "1.1.13" javaCompileOptions { annotationProcessorOptions { arguments = ["resourcePackageName": android.defaultConfig.applicationId] } } } // exclude buildTypes = "debug" from build Variants variantFilter { variant -> if (variant.buildType.name.equals('debug')) { variant.setIgnore(true); } } buildTypes { def APP_NAME_STAGE = "My project Stage" def APP_ID_SUFFIX_STAGE = ".stage" release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } stage { initWith(debug) } } sourceSets { main.java.srcDirs += 'src/main/kotlin' } packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' } lintOptions { abortOnError false } } def AAVersion = '4.3.0' dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile('com.digits.sdk.android:digits:1.11.0@aar') { transitive = true; } compile('com.crashlytics.sdk.android:crashlytics:2.6.0@aar') { transitive = true; } compile 'com.android.support:appcompat-v7:23.0.0' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.android.volley:volley:1.0.0' compile 'com.baoyz.swipemenulistview:library:1.3.0' compile 'com.google.android.gms:play-services-gcm:9.0.2' compile 'com.google.code.gson:gson:2.7' compile 'com.miguelcatalan:materialsearchview:1.4.0' compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.3' compile 'com.squareup.okhttp:okhttp:2.7.3' compile 'com.theartofdev.edmodo:android-image-cropper:2.2.5' compile 'commons-codec:commons-codec:1.9' compile 'commons-io:commons-io:2.4' compile 'org.apache.commons:commons-lang3:3.4' compile 'org.apache.httpcomponents:httpcore:4.4.4' compile 'org.apache.httpcomponents:httpmime:4.3.6' compile 'us.feras.mdv:markdownview:1.1.0' compile fileTree(dir: 'libs', include: ['*.jar']) compile 'org.jetbrains.anko:anko-sdk15:0.9.1' annotationProcessor "org.androidannotations:androidannotations:$AAVersion" compile "org.androidannotations:androidannotations-api:$AAVersion" testCompile 'junit:junit:4.12' } 

并项目建立并运行成功。 所以现在我想添加Realm。 我添加build.gradle

 apply plugin: 'realm-android' 

结果我得到错误。

错误:未find注释处理器’__gen.AnnotationProcessorWrapper_stage_io_realm_processor_RealmProcessor’错误:执行任务’:app:compileStageJavaWithJavac’失败。

编译失败 详细信息请参阅编译器错误输出。 :app:compileDevJavaWithJavac生成源的目标由kapt修改。 以前的值= myProject \ app \ build \ generated \ source \ apt \ dev错误:找不到注释处理器

2 Solutions collect form web for “Android,领域,Gradle:错误:注释处理器:找不到RealmProcessor”

我find解决方案。 两种方法:

  1. 通过插件

在应用程序的budile.gradle:

 apply plugin: 'com.neenbedankt.android-apt' apt { arguments { resourcePackageName android.defaultConfig.applicationId androidManifestFile variant.outputs[0]?.processResources?.manifestFile } } dependencies { apt 'io.realm:realm-android-library:3.5.0' apt "org.androidannotations:androidannotations:$AAVersion" } 

要么

  1. kapt插件

     apply plugin: 'kotlin-kapt' kapt { arguments { arg( "resourcePackageName", android.defaultConfig.applicationId) arg( "androidManifestFile", variant.outputs[0]?.processResourcesTask?.manifestFile) } } 

    依赖{

     kapt 'io.realm:realm-android-library:3.5.0' kapt "org.androidannotations:androidannotations:$AAVersion" 

    }

如果你使用Kotlin,那么你需要使用KAPT。

 annotationProcessor "org.androidannotations:androidannotations:$AAVersion" 

应该

 kapt "org.androidannotations:androidannotations:$AAVersion" 

 apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'io.fabric' apply plugin: 'realm-android' 

应该

 apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' apply plugin: 'io.fabric' apply plugin: 'realm-android' 

  // javaCompileOptions { // annotationProcessorOptions { // arguments = ["resourcePackageName": android.defaultConfig.applicationId] // } // } kapt { arguments { arg('resourcePackageName', android.defaultConfig.applicationId) } } 

编辑:基于https://stackoverflow.com/a/34708575/2413303

 kapt { arguments { arg('androidManifestFile', variant.outputs[0]?.processResources?.manifestFile) arg('resourcePackageName', android.defaultConfig.applicationId) } } 

如果这仍然不起作用,那么问题就变成与AndroidAnnotations有关。

Kotlin language will be the best programming language for Android.