Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.9k points)

I am using Android Database Component Room

I've configured everything, but when I compile, Android Studio gives me this warning:

Schema export directory is not provided to the annotation processor so we cannot export the schema. You can either provide room.schemaLocation annotation processor argument OR set exportSchema to false.

As I understand it is location where DB file will be located

How can it affect my app ? What is best practice here ? Should I use default location (false value) ?

1 Answer

0 votes
by (46k points)

As through the docs:

You can arrange the annotation processor discussion (room.schemaLocation) to know the Room to export the schema within a folder. Even though it is not necessary, it is a great method to have version tale in your codebase and you should perform that file into your version restriction system (but don't send it with your app!).

So if you don't require to check the schema and you require to get rid of the advice, just add exportSchema = false to your RoomDatabase, as heeds.

@Database(entities = { YourEntity.class }, version = 1, exportSchema = false)

public abstract class AppDatabase extends RoomDatabase {

//...

}

You will receive 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 opinion is right, you will notice such a file with each database variant update, so that you can simply catch the history of your DB.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...