I recently saw the new feature announced on Google I/O Room Persistence Library to work with Sqlite databases on Android. I have been looking to the official documentation and I
Open the build.gradle
file for your project (not the ones for your app or module) and add:
allprojects {
repositories {
google()
jcenter()
}
}
Open the build.gradle
file for your app or module and add the artifacts that you need as dependencies:
dependencies {
implementation "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
}
Reference: Android Adding Components
* Add these in project level gradle
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
ext {
buildToolsVersion = "25.0.2"
supportLibVersion = "25.3.1"
archRoomVersion = "1.0.0-alpha1"
}
* Add these in module level gradle dependencies
dependencies {
compile 'android.arch.persistence.room:runtime:' + rootProject.archRoomVersion;
annotationProcessor 'android.arch.persistence.room:compiler:' + rootProject.archRoomVersion;
}
Android doc:
Add the Google Maven repository Android Studio projects aren't configured to access this repository by default.
To add it to your project, open the build.gradle file for your project (not the ones for your app or module) and add the highlighted line as shown below:
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
Add Architecture Components
Open the build.gradle file for your app or module and add the artifacts that you need as dependencies:
For Lifecycles, LiveData, and ViewModel, add:
implementation "android.arch.lifecycle:runtime:1.0.0-alpha1"
implementation "android.arch.lifecycle:extensions:1.0.0-alpha1"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"
For Room, add:
implementation "android.arch.persistence.room:runtime:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
As of July 2019 if you wish to use Room with Kotlin, AndroidX, Coroutines or RxJava add lines below.
// Room
implementation 'androidx.room:room-runtime:' + rootProject.roomVersion
// For Kotlin use kapt instead of annotationProcessor
kapt 'androidx.room:room-compiler:' + rootProject.roomVersion
// optional - Kotlin Extensions and Coroutines support for Room
implementation 'androidx.room:room-ktx:' + rootProject.roomVersion
// optional - RxJava support for Room
implementation 'androidx.room:room-rxjava2:' + rootProject.roomVersion
It's possible to find the dependencies on the example codelab for the new architecture components.
Root :
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
For Room:
implementation 'android.arch.persistence.room:runtime:1.0.0-alpha1'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0-alpha1'
For Lifecycle dependencies:
implementation 'android.arch.lifecycle:extensions:1.0.0-alpha1'
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0-alpha1'
Adding Rxjava2 objects as result for our queries:
implementation 'android.arch.persistence.room:rxjava2:1.0.0-alpha1'
Test migrations:
testImplementation'android.arch.persistence.room:testing:1.0.0-alpha1'
Try this to compile Room Persistence library
implementation 'android.arch.persistence.room:runtime:1.1.1';
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1';
And add this in root level build gradle
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}