2017-08-14 60 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" 
    

    }

  • 相關問題