1. When using the Android Room database, the following error occurs:
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.
2. There are two kinds of solutions.
1). Set the exportSchema annotation to false for RoomDatabase. default is true
@Database(entities = [TableItem::class], version = 1,exportSchema = false)
abstract class AppDataBase : RoomDatabase() {
abstract fun tableItemDao(): TableItemDao
2) Add in the build.gradle of the app (recommended)
There are different configuration syntaxes for java environment and kotlin environment. Depending on the personal environment configuration, only one way of writing can exist for both. My environment is a kotlin environment, so use the kotlin environment writing method. At the beginning, I used the java environment writing method, and the result kept reporting errors, and only after changing to kotlin did it work.
defaultConfig {
applicationId "XXX"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
//Specify the path to the file generated by room.schemaLocation, java environment (choose one of the two, depending on the project environment)
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
//Specify the path to the file generated by room.schemaLocation, kotlin environment (choose one of the two, depending on the project environment)
kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas")
}
}
}
3. After configuration and compilation, JSON structure files of data will be generated in the following directory:
Read More:
- How to Solve Jetpack room use error
- [Solved] Android Room: Database Common Error ‘missing database’
- Room DB Error: AppDatabase_Impl does not exist [How to Solve]
- Android 10: How to Solve Systemui Error
- How to Solve Error inflating class android.support.design.widget.FloatingActionButton
- How to Solve Android Studio run main() Method Error
- Android: How to Solve libuv Compile Error
- How to Solve Android Arouter Frame Autowired Error
- Android Studio: How to Solve APK error in mobile phone installation
- How to Solve Error: Android java.lang.IllegalStateException: Could not execute method of the activity
- How to Solve Android Error: gps requires ACCESS_FINE_LOCATION
- How to Solve Error “Could not find com.android.tools.build:gradle:3.0.1”
- RuntimeError: ONNX export failed: Couldn‘t export operator aten::upsample_bilinear2d
- How to Solve Android wechat payment Error: error_code = -1
- How to Solve Android Error: Error inflating class
- [Solved] Mac Unity Export Android Project Error: Error building Player: Win32Exception
- Sqoop Error: Error during export:Export job failed [How to Solve]
- [Solved] Schema initialization FAILED Metastore state would be inconsistent
- How to Solve Project Upgrade to flutter2.5.0 Error
- Kotlin: How to Solve kapt import error