This module supports migrating SQLite to Room Persistence Library, loads pre-populated SQLite database base on albertogiunta/sqliteAsset
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.daolq3012:AssetSQLiteOpenHelper:V1.0.1'
// Because AssetSQLiteOpenHelper releases are few and far between (persistence room version using in module is 1.0.0),
// it is recommended you also explicitly depend on Persistence Room's latest version for bug fixes and new features.
implementation 'android.arch.persistence.room:runtime:x.x.x'
}
- Put your SQLite DB database_name.db into the
assets/databases
folder - in your
AppDatabase
class, modify your Room's DB creation code accordingly:
Room.databaseBuilder(context.getApplicationContext(),
AppDatabase.class,
"database_name.db")
.openHelperFactory(new AssetSQLiteOpenHelperFactory())
.build();
Alternatively, if you need precise control over the subfolder under assets/
containing your sqlite database,
specify the subfolder path as an argument to AssetSQLiteOpenHelperFactory
e.g. if your database is in
assets/databases#lang_en
you would use
Room.databaseBuilder(context.getApplicationContext(),
AppDatabase.class,
"database_name.db")
.openHelperFactory(new AssetSQLiteOpenHelperFactory("databases#lang_en"))
.build();
- See samples in this project to show more
The Example are built using Android studio
- Open pull request with improvements
- Discuss ideas in issues
- Spread the word
- Reach out to me directly at [email protected]
The content of this project itself is licensed under the Creative Commons Attribution 4.0 International (CC BY 4.0)