Android, Realm , Gradle : Error:Annotation processor: RealmProcessor not found

标签 android gradle realm

安卓工作室 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'

结果我得到了错误。

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

Compilation failed; see the compiler error output for details. :app:compileDevJavaWithJavac Destination for generated sources was modified by kapt. Previous value = myProject\app\build\generated\source\apt\dev error: Annotation processor '__gen.AnnotationProcessorWrapper_dev_io_realm_processor_RealmProcessor' not found

最佳答案

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

  1. 通过apt插件

在应用程序的 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"
    

关于Android, Realm , Gradle : Error:Annotation processor: RealmProcessor not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45675247/

相关文章:

swift - 无法调用非函数类型的值 'ThreadConfined.Type' - Swift 4.0

android - Android : Correct structure or not? 中具有单例模式的 Realm

android - 如果曾经调用过方法,则必须在 [proguard.classfile.editor.AttributeAdder] 中重写

android - AVCDecoder : Video resolution too high, 拒绝它

java - 无法使用 Gradle (Buildship 1.x) 导入,因为未安装 Buildship Gradle Tooling 版本 1.x

android - bash脚本或Python解析gradle依赖

java - 设置onSeekBarChangeListener导致空对象异常

java - Eclipse 无法识别 gradle 依赖项

android - 什么都不起作用。 Realm 迁移 [Android 1.2]

ios - 在 Realm 迁移期间创建 Realm 对象