【问题标题】:Android, Realm, Gradle: Error:Annotation processor: RealmProcessor not foundAndroid,领域,Gradle:错误:注释处理器:找不到领域处理器
【发布时间】:2018-01-22 08:02:48
【问题描述】:

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'
}

项目建设并运行成功。 所以现在我想添加领域。我在 build.gradle 中添加

apply plugin: 'realm-android'

结果我得到了错误。

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

编译失败;有关详细信息,请参阅编译器错误输出。 :app:compileDevJavaWithJavac kapt 修改了生成源的目标。以前的值 = myProject\app\build\generated\source\apt\dev 错误:未找到注释处理器“__gen.AnnotationProcessorWrapper_dev_io_realm_processor_RealmProcessor”

【问题讨论】:

标签: android gradle realm


【解决方案1】:

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

  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"
    

    }

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • Error:(54, 0) No such property: processResources for class: com.android.build.gradle.internal.variant.ApkVariantOutputData
    • 你的kotlin version 是什么?这个新错误似乎是very similar to this one
    • ext.kotlin_version = '1.1.3-2', 类路径 "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    • 您使用的是 Android Studio 2.3.x 还是 3.0.0-x?
    • Android Studio 2.3.3
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 1970-01-01
    相关资源
    最近更新 更多