我正在尝试将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
}
模块build.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'
}
答案 0 :(得分:4)
要关闭此问题: 评论@ zaki50写给我的是:
将apply plugin: 'kotlin-kapt'
添加到app / build.gradle。
我在apply plugin: 'kotlin-android'
之后立即添加了它。