2017-08-14 58 views
1

的Android 2.3.3工作室的Android,境界,摇篮:错误:注释处理器:RealmProcessor没有找到

我的项目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:[email protected]') { 
     transitive = true; 
    } 
    compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
     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

+0

请认准【如何问一个很好的问题(https://开头计算器。com/help/how-to-ask) – LazerBanana

回答

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。

+0

错误:(54,0)没有这样的属性:processResources for class:com.android.build.gradle.internal.variant.ApkVariantOutputData' – lmdic

+0

什么是你的[kotlin版本]( https://stackoverflow.com/a/44043185/2413303)?这个新的错误似乎是[非常类似于这个](https://stackoverflow.com/q/44170064/2413303) – EpicPandaForce

+0

ext.kotlin_version ='1.1.3-2',classpath“org.jetbrains.kotlin:kotlin -gradle-plugin:$ kotlin_version“ – lmdic

1

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

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

OR

  • 通过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" 
    

    }

  • 相关问题