Room - Schema export directory is not provided to the annotation processor so we cannot export the schema
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
When building an Android project that uses the Room persistence library, you may encounter the warning or error "Schema export directory is not provided to the annotation processor so we cannot export the schema." This happens because Room can generate JSON schema files for each database version, but it needs to know where to write them. Without this configuration, the build either warns you or fails outright depending on your Room version and build settings.
Why Schema Export Matters
Room schema files are JSON representations of your database structure at each version number. They serve two critical purposes. First, they enable Room to auto-generate migration test helpers that verify your migrations transform the database correctly between versions. Second, they provide a version-controlled history of your database schema, making it easy to review structural changes during code review.
Without exported schemas, you lose access to MigrationTestHelper and must manually verify every migration path.
Fixing with KAPT (Kotlin Annotation Processing)
If your project uses KAPT for annotation processing, add the room.schemaLocation argument in your module-level build.gradle.kts file.
For Groovy-based build.gradle files, the syntax differs slightly.
Make sure you also have the KAPT plugin applied at the top of your build file.
Fixing with KSP (Kotlin Symbol Processing)
KSP is the recommended annotation processor for Room in modern Android projects because it is faster than KAPT. The configuration uses the ksp block instead.
Starting with Room 2.6.0 and the Room Gradle Plugin, you can also use the plugin-based configuration.
This approach is the cleanest option and works with both KSP and KAPT.
Fixing with Java Annotation Processor
For pure Java projects that do not use Kotlin, the annotation processor options are configured through annotationProcessor in the dependencies block combined with the arguments configuration.
Setting exportSchema on the Database Class
The @Database annotation has an exportSchema parameter that defaults to true. If you have configured the schema location, keep it set to true so Room generates the files.
If you intentionally do not want schema exports (for example, in a quick prototype), you can suppress the warning by setting exportSchema = false. However, this is not recommended for production applications because it disables migration testing support.
Using Exported Schemas for Migration Testing
Once schema files are generated, you can use them with MigrationTestHelper to write automated migration tests.
Add the schemas directory as a test asset source so the test runner can find the JSON files.
Common Pitfalls
- Using KAPT config with KSP dependency: If you switched from
kapttokspfor Room but left the schema location injavaCompileOptions, KSP will not pick it up; use thekspblock or Room Gradle Plugin instead. - Forgetting to commit the schemas directory: The generated JSON files in
schemas/should be committed to version control so that migration tests work for all developers and in CI. - Mismatched Room compiler and runtime versions: The
room-compilerversion must match theroom-runtimeversion exactly, or schema generation may produce unexpected results. - Setting exportSchema to false to silence the warning: This suppresses the message but disables migration testing, leading to potential data loss bugs when database versions change.
- Not adding schemas to androidTest assets: Even with schema files generated, migration tests will fail with "Cannot find the schema file" unless the schemas directory is registered as an asset source for the androidTest source set.
Summary
- The "schema export directory not provided" error is resolved by setting
room.schemaLocationin your Gradle configuration matching your annotation processor (KAPT, KSP, or Java AP). - The Room Gradle Plugin (2.6.0+) provides the cleanest configuration via
room { schemaDirectory(...) }. - Always keep
exportSchema = truein production to enable automated migration testing withMigrationTestHelper. - Commit the generated
schemas/directory to version control and register it as an androidTest asset source. - Make sure the Room compiler and runtime dependency versions match exactly across your project.

