2

I have updated kotlin plugin to 1.5.20 and this issue happened. If I return it 1.5.10 all works fine.

Schema export directory is not provided to the annotation processor so we cannot import the schema. To generate auto migrations, you must provide `room.schemaLocation` annotation processor argument AND set exportSchema to true.
public abstract class BatteryInfoDatabase extends androidx.room.RoomDatabase {

I'm using the latest version of Room persistence library alpha 3, because it offers auto migration

def room_version = "2.4.0-alpha03"
    implementation("androidx.room:room-ktx:$room_version")
    kapt("androidx.room:room-compiler:$room_version")
        javaCompileOptions {
            annotationProcessorOptions {
                arguments += [
                        "room.schemaLocation":"$projectDir/schemas".toString()]
            }
        }
Danijel Markov
  • 160
  • 1
  • 8

1 Answers1

7

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

Markus Penguin
  • 1,581
  • 12
  • 19
  • Finally a real Kotlin answer. All the people back at https://stackoverflow.com/questions/44322178/room-schema-export-directory-is-not-provided-to-the-annotation-processor-so-we just spammed Java answers and even provided wrong alternatives for Kotlin users. This one actually works! Thank you. – Akito Oct 09 '21 at 21:29