Challenge: Addressing the Schema Warning

If you look through your build logs, you will find a warning about your app not providing a schema export directory:

    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.

A database schema represents the structure of the database, including what tables are in the database, what columns are in those tables, and any constraints on and relationships between those tables. Room supports exporting your database schema into a file so you can store it in a source control. Exporting your schema is often useful so that you have a versioned history of your database.

The warning you see means that you are not providing a file location where Room can save your database schema. You can either provide a schema location to the @Database annotation, or you can disable the export to remove the warning. For this challenge, resolve the schema warning by choosing one of these options.

To provide a location for the export, you provide a path for the annotation processor’s room.schemaLocation property. To do this, add the following kapt{} block to your app/build.gradle file:

    ...
    android {
        ...
        buildTypes {
            ...
        }
        kapt {
            arguments {
                arg("room.schemaLocation", "some/path/goes/here/")
            }
        }
    }
    ...

To disable the export, set exportSchema to false:

    @Database(entities = [ Crime::class ], version=1, exportSchema = false)
    @TypeConverters(CrimeTypeConverters::class)
    abstract class CrimeDatabase : RoomDatabase() {

        abstract fun crimeDao(): CrimeDao
    }
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.90.242.249