In my Android project (Kotlin), I want to use Room persistent library for my DATA LAYER.
But when I added dependencies for Room Persistent library suddenly build projects start failing.
// 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
}
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")
}
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"
}
}
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()
}
I don't know how to resolve this issue.
Your help will be appreciated.
Android Gradle Plugin 3.0 and higher added a new behaviour for dependencies. You can read more about this here. Long story short, by using implementation
in a submodule you're not sharing a dependency with a consumer module(your app
module). Thus, it's not possible to generate the code needed for Room.
Essentially, what you need to do is simply change implementation
to api
in your data module for the Room's dependencies. The result will be:
api "android.arch.persistence.room:runtime:$room_version"
api "android.arch.persistence.room:rxjava2:$room_version"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With