在我的Android项目(Kotlin)中,我想在我的数据层中使用Room持久库。
但是当我添加了Room持久库的依赖后,突然构建项目失败了。 我收到的错误如下: 请参考以下链接查看错误图片:
这是我的项目级别build.gradle文件:
我不知道如何解决这个问题。 感谢您的帮助。
但是当我添加了Room持久库的依赖后,突然构建项目失败了。 我收到的错误如下: 请参考以下链接查看错误图片:
![Error image](https://istack.dev59.com/JcO2U.webp)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
globalCompileSdkVersion = 26
globalMinSdkVersion = 19
globalTargetSdkVersion = 26
kotlin_version = '1.2.10'
support_version = "27.0.2"
constraint_layout_version = "1.0.2"
view_animator_version = "1.0.5"
junit_version = "4.12"
runner_version = "1.0.1"
espresso_core_version = "3.0.1"
room_version = "1.0.0"
dagger_version = "2.13"
rxJavaVersion = "2.1.7"
rxAndroidVersion = "2.0.1"
libs = [
appCompatV7 : "com.android.support:appcompat-v7:$support_version",
rxJava : "io.reactivex.rxjava2:rxjava:$rxJavaVersion",
rxAndroid : "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion",
junit : "junit:junit:$junit_version",
runner : "com.android.support.test:runner:$runner_version",
espressoCore: "com.android.support.test.espresso:espresso-core:$espresso_core_version"
]
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
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 {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这是我的应用程序模块build.gradle文件
apply plugin: 'com.android.application'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion project.globalCompileSdkVersion
defaultConfig {
applicationId "com.keepsafe.app"
minSdkVersion project.globalMinSdkVersion
targetSdkVersion project.globalTargetSdkVersion
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation libs.appCompatV7
implementation "com.android.support:design:$support_version"
implementation "com.android.support.constraint:constraint-layout:$constraint_layout_version"
implementation "com.github.florent37:viewanimator:$view_animator_version"
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
implementation libs.rxJava
implementation libs.rxAndroid
testImplementation libs.junit
androidTestImplementation libs.runner
androidTestImplementation libs.espressoCore
implementation project(":data")
implementation project(":domain")
}
这是我的域模块的build.gradle文件
apply plugin: 'java-library'
apply plugin: 'kotlin'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation libs.rxJava
implementation libs.rxAndroid
implementation libs.junit
}
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
这是我的数据模块 build.gradle 文件
apply plugin: 'com.android.library'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'
android {
compileSdkVersion project.globalCompileSdkVersion
defaultConfig {
minSdkVersion project.globalMinSdkVersion
targetSdkVersion project.globalTargetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "android.arch.persistence.room:runtime:$room_version"
implementation "android.arch.persistence.room:rxjava2:$room_version"
kapt "android.arch.persistence.room:compiler:$room_version"
testImplementation libs.junit
implementation project(":domain")
}
repositories {
mavenCentral()
}
我不知道如何解决这个问题。 感谢您的帮助。