Room - Schema Export Directory Is Not Provided to the Annotation Processor So We Cannot Export the Schema

Room - Schema export directory is not provided to the annotation processor so we cannot export the schema

As per the docs:

You can set annotation processor argument (room.schemaLocation) to tell Room to export the schema into a folder. Even though it is not mandatory, it is a good practice to have version history in your codebase and you should commit that file into your version control system (but don't ship it with your app!).

So if you don't need to check the schema and you want to get rid of the warning, just add exportSchema = false to your RoomDatabase, as follows.

@Database(entities = { YourEntity.class }, version = 1, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
//...
}

If you follow @mikejonesguy answer below, you will follow the good practice mentioned in the docs :).
Basically you will get a .json file in your ../app/schemas/ folder.
And it looks something like this:

{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "53db508c5248423325bd5393a1c88c03",
"entities": [
{
"tableName": "sms_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `message` TEXT, `date` INTEGER, `client_id` INTEGER)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER"
},
{
"fieldPath": "message",
"columnName": "message",
"affinity": "TEXT"
},
{
"fieldPath": "date",
"columnName": "date",
"affinity": "INTEGER"
},
{
"fieldPath": "clientId",
"columnName": "client_id",
"affinity": "INTEGER"
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"53db508c5248423325bd5393a1c88c03\")"
]
}
}

If my understanding is correct, you will get such a file with every database version update, so that you can easily follow the history of your db.

Room - Schema export directory is not provided to the annotation processor so we cannot import the schema

I had a similar problem to yours after updating my Kotlin version (my schema would not be generated anymore). I could fix it by moving from javaCompileOptions to kapt like so:

kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas".toString())
}
}

So replacing your javaCompileOptions with the above block should do the trick.

Edit: Apparently it's a bug in Kotlin. You can follow the discussion (and see other workarounds) in this ticket and its related tickets: https://youtrack.jetbrains.com/issue/KT-47416

Room Schema Export Directory - Could not find method javaCompileOptions() for arguments

I believe that you need to move the compile option to be within the android options as per (inside defaultConfig) :-

apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions{
annotationProcessorOptions{
arguments= ["room.schemaLocation":
"$projectDir/schemas".toString()]
}}
}


buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'androidx.appcompat:appcompat:1.0.0'

//room
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"

}

Room Database with Android Studio

That tutorial is broken.

For your specific problem, change:

@Query("SELECT * FROM task")

to:

@Query("SELECT * FROM Recipe")

and hope for the best.



Related Topics



Leave a reply



Submit