android build_error ai_generated true

error: 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.

ID: android/room-schema-export-missing

Also available as: JSON · Markdown · 中文
95%Fix Rate
86%Confidence
1Evidence
2023-02-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Room 2.5 - 2.6 active
Android Gradle Plugin 7.4 - 8.2 active

Root Cause

Room database annotation processor requires a schema export directory for migration validation, but it is not configured in build.gradle or exportSchema is set to true without a path.

generic

中文

Room 数据库注解处理器需要架构导出目录以进行迁移验证,但未在 build.gradle 中配置,或者 exportSchema 设置为 true 但未提供路径。

Official Documentation

https://developer.android.com/training/data-storage/room/migrating#export-schema

Workarounds

  1. 98% success Add the following to build.gradle (app-level) for kapt: 'kapt { arguments { arg("room.schemaLocation", "$projectDir/schemas") } }' or for annotationProcessor: 'defaultConfig { javaCompileOptions { annotationProcessorOptions { arguments = ["room.schemaLocation": "$projectDir/schemas"] } } }'
    Add the following to build.gradle (app-level) for kapt: 'kapt { arguments { arg("room.schemaLocation", "$projectDir/schemas") } }' or for annotationProcessor: 'defaultConfig { javaCompileOptions { annotationProcessorOptions { arguments = ["room.schemaLocation": "$projectDir/schemas"] } } }'
  2. 90% success Set exportSchema = false in the @Database annotation if migration validation is not needed: '@Database(entities = [User::class], version = 1, exportSchema = false)'
    Set exportSchema = false in the @Database annotation if migration validation is not needed: '@Database(entities = [User::class], version = 1, exportSchema = false)'

中文步骤

  1. Add the following to build.gradle (app-level) for kapt: 'kapt { arguments { arg("room.schemaLocation", "$projectDir/schemas") } }' or for annotationProcessor: 'defaultConfig { javaCompileOptions { annotationProcessorOptions { arguments = ["room.schemaLocation": "$projectDir/schemas"] } } }'
  2. Set exportSchema = false in the @Database annotation if migration validation is not needed: '@Database(entities = [User::class], version = 1, exportSchema = false)'

Dead Ends

Common approaches that don't work:

  1. 50% fail

    If exportSchema is false, the schema is not exported, but the error may still occur if the processor expects the argument; the build.gradle configuration is still needed.

  2. 50% fail

    The path must be a valid project-relative directory; a wrong path causes the processor to fail silently or create the schema in an unexpected location.