Android,Realm,Gradle:错误:注释处理器:未找到RealmProcessor

时间:2017-08-14 13:07:46

标签: android gradle realm

Android Studio 2.3.3

我的项目bulid.gradle:

from hyperopt import space_eval
space_eval(parameter_space_svc, best)

Output:
{'C': 13.271912841932233, 'gamma': 0.0017394328334592358, 'kernel': 'rbf'}

我的应用build.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()
}

项目建立并成功运行。 所以现在我要添加Realm。我添加了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'
}

结果我得到了错误。

错误:注释处理器' __ gen.AnnotationProcessorWrapper_stage_io_realm_processor_RealmProcessor'未找到     错误:任务':app:compileStageJavaWithJavac'执行失败。

  

编译失败;请参阅编译器错误输出以获取详细信       :应用:compileDevJavaWithJavac       生成源的目标由kapt修改。上一个值= myProject \ app \ build \ generated \ source \ apt \ dev       错误:注释处理器' __ gen.AnnotationProcessorWrapper_dev_io_realm_processor_RealmProcessor'找不到

2 个答案:

答案 0 :(得分:1)

我找到了解决方案。两种方法:

  1. 通过 apt 插件
  2. 在app的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"
    }
    

    OR

    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"
      

      }

答案 1 :(得分:0)

如果您使用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相关。