【问题标题】:Applying Realm plugin in Kotlin project results in compilation error在 Kotlin 项目中应用 Realm 插件会导致编译错误
【发布时间】:2017-01-20 19:12:26
【问题描述】:

我正在尝试将 Realm 添加到 Android 项目中,我已经添加了项目级别的 classpath 依赖项,但是将 apply plugin: 'realm-android' 我模块的build.gradle 文件中的行导致以下构建错误:

Error:Execution failed for task ':data:compileDebugAndroidTestJavaWithJavac'. java.lang.NoClassDefFoundError: org/jetbrains/kotlin/annotation/AnnotationProcessorWrapper

没有那一行,应用程序构建并运行良好,其中还没有 Realm 代码。

项目级 build.gradle:

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

buildscript {
    ext.kotlin_version = '1.0.6'
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "io.realm:realm-gradle-plugin:2.3.0"
    }
}

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

模块构建.gradle:

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

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'

        test {
            java.srcDirs = ['src/test/kotlin']
        }
    }
}

buildscript {
    ext.kotlin_version = '1.0.6'
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

kapt {
    generateStubs = true
}

dependencies {  
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(path: ':domain')

    compile 'org.jetbrains.kotlin:kotlin-stdlib:1.0.6'

    compile 'io.reactivex:rxjava:1.1.6'
    compile 'io.reactivex:rxkotlin:0.60.0'

    compile 'javax.inject:javax.inject:1'

    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:2.6.3'
    testCompile 'com.nhaarman:mockito-kotlin:1.1.0'
}

【问题讨论】:

  • 您能否包含整个 gradle 构建脚本,包括应用程序模块和项目。
  • 更新:有人建议降级到 2.2.2 立即修复它,所以显然这是 2.3.0 版本的一些模糊问题。
  • 我还添加了 Gradle 文件,以防有人发现其中的错误。
  • 这是改变基于 kapt 的项目的拉取请求,尽管我看不出它不应该工作的原因...github.com/realm/realm-java/pull/4022
  • apply plugin: 'kotlin-kapt' 添加到app/build.gradle 可以解决这个问题吗?此问题由github.com/realm/realm-java/issues/4087 跟踪

标签: android android-gradle-plugin realm kotlin


【解决方案1】:

要结束这个问题: @zaki50 写的评论对我有用:

apply plugin: 'kotlin-kapt' 添加到 app/build.gradle。 我在apply plugin: 'kotlin-android'之后添加了它。

https://github.com/realm/realm-java/issues/4087跟踪此问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 2021-02-22
    • 1970-01-01
    • 2020-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多