【问题标题】:Error in setting up realm with kotlin使用 kotlin 设置领域时出错
【发布时间】:2017-10-18 07:11:06
【问题描述】:

我在现有的 Android 项目(已经有领域)中使用了一些 kotlin 类,这些 kotlin 类没有使用任何领域功能,现在在运行时我收到此错误

:app:compileDebugKotlin
Using kotlin incremental compilation
:app:compileDebugJavaWithJavac
Destination for generated sources was modified by kapt. Previous value = /home/debu/AndroidStudioProjects/WT_Application/app/build/generated/source/apt/debug

error: Annotation processor '__gen.AnnotationProcessorWrapper_debug_io_realm_processor_RealmProcessor' not found
1 error

:app:compileDebugJavaWithJavac FAILED
:app:copyDebugKotlinClasses SKIPPED

FAILURE: Build failed with an exception. 

我的应用的 build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'realm-android'

android {
    def globalConfiguration = rootProject.extensions.getByName("ext")

    compileSdkVersion globalConfiguration.getAt("androidCompileSdkVersion")
    buildToolsVersion globalConfiguration.getAt("androidBuildToolsVersion")
    defaultConfig {
        applicationId globalConfiguration.getAt("androidApplicationId")
        minSdkVersion globalConfiguration.getAt("androidMinSdkVersion")
        targetSdkVersion globalConfiguration.getAt("androidTargetSdkVersion")
        versionCode globalConfiguration.getAt("androidVersionCode")
        versionName globalConfiguration.getAt("androidVersionName")
        testInstrumentationRunner globalConfiguration.getAt("testInstrumentationRunner")
        /*jackOptions {
            enabled true
        }*/
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    def presentationDependencies = rootProject.ext.presentationDependencies
    def presentationTestDependencies = rootProject.ext.presentationTestDependencies
    def developmentDependencies = rootProject.ext.developmentDependencies
    compile presentationDependencies.dagger
    compile presentationDependencies.butterKnife
    compile presentationDependencies.recyclerView
    compile presentationDependencies.cardview
    compile presentationDependencies.rxJava
    compile presentationDependencies.rxAndroid
    compile presentationDependencies.appcompat
    compile presentationDependencies.constraintLayout
    compile presentationDependencies.design
    compile presentationDependencies.retrofit
    compile presentationDependencies.gsonconverter
    compile presentationDependencies.rxjavaadapter
    compile presentationDependencies.glide
    compile presentationDependencies.flexbox
    compile presentationDependencies.maps
    compile presentationDependencies.mapUtils
    compile presentationDependencies.pagerIndicator
    annotationProcessor presentationDependencies.daggerCompiler
    annotationProcessor presentationDependencies.butterKnifeCompiler
    provided presentationDependencies.javaxAnnotation
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

    androidTestCompile presentationTestDependencies.junit
    androidTestCompile presentationTestDependencies.mockito
    androidTestCompile presentationTestDependencies.dexmaker
    androidTestCompile presentationTestDependencies.dexmakerMockito
    androidTestCompile presentationTestDependencies.espresso
    androidTestCompile presentationTestDependencies.testingSupportLib
    //Development

    compile developmentDependencies.leakCanary
    compile files('libs/YouTubeAndroidPlayerApi.jar')
}
repositories {
    mavenCentral()
}

项目构建.gradle

apply from: 'buildsystem/dependencies.gradle'
buildscript {
    ext.kotlin_version = '1.1.2-4'
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
        classpath "io.realm:realm-gradle-plugin:3.2.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 {
    ext {
        androidApplicationId = 'com.wandertrails'
        androidVersionCode = 1
        androidVersionName = "1.0"
        testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
        testApplicationId = 'com.wandertrails.test'
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

现在有人可以弄清楚这个错误的原因是什么????

【问题讨论】:

  • 请尝试将注解处理器依赖项也添加到kapt 配置中:kapt presentationDependencies.daggerCompilerkapt presentationDependencies.butterKnifeCompiler,看看是否有效。
  • 现在我收到以下错误 - 错误:以下任务之间的循环依赖: :app:compileDebugKotlin \--- :app:kaptDebugKotlin \--- :app:compileDebugKotlin () () - 省略细节(之前列出)
  • 如果你使用的是Android Gradle插件3.0.0-alpha1,那么循环依赖是Data Binding引起的已知问题,请看stackoverflow.com/questions/44035504/…;可能那里描述的解决方法(恢复到 Kotlin 1.1.2-2 并禁用 IC)将解决此问题。

标签: android realm kotlin


【解决方案1】:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'

kapt presentationDependencies.daggerCompiler
kapt presentationDependencies.butterKnifeCompiler

可能会修复它。

【讨论】:

  • 添加行后错误消失了 - annotationProcessor presentationDependencies.daggerCompiler annotationProcessor presentationDependencies.butterKnifeCompiler kapt presentationDependencies.daggerCompiler kapt presentationDependencies.butterKnife kapt "com.android.databinding:compiler:2.3.2" 现在是一个新问题到了,butterknife 不工作(BK 版本 - 8.6.0,Gradle 版本 - 3.4.1)
  • @Debu 你能接受这个答案吗?这个问题与Butterknife无关。您需要为此提出一个新问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-06
相关资源
最近更新 更多