今天在Apple M1电脑上 添加Room数据库一直构建失败…
Caused by: java.lang.ExceptionInInitializerError
at androidx.room.processor.DatabaseProcessor.doProcess(DatabaseProcessor.kt:82)
at androidx.room.processor.DatabaseProcessor.process(DatabaseProcessor.kt:57)
at androidx.room.RoomProcessor$DatabaseProcessingStep.process(RoomProcessor.kt:134)
at com.google.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:330)
at com.google.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:181)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.process(incrementalProcessors.kt:90)
at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:166)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:980)
... 41 more
Caused by: java.lang.Exception: No native library is found for os.name=Mac and os.arch=aarch64. path=/org/sqlite/native/Mac/aarch64
at org.sqlite.SQLiteJDBCLoader.loadSQLiteNativeLibrary(SQLiteJDBCLoader.java:333)
at org.sqlite.SQLiteJDBCLoader.initialize(SQLiteJDBCLoader.java:64)
at androidx.room.verifier.DatabaseVerifier.<clinit>(DatabaseVerifier.kt:68)
... 49 more
产生的原因:猜测他们还没有为 aarch64 编译的 SQLite 本地库。
解决方式:
def room_version = "2.3.0"
implementation("androidx.room:room-runtime:$room_version") {
exclude(group:'org.xerial')
}
kapt("androidx.room:room-compiler:$room_version"){
exclude(group:'org.xerial')
}
implementation("androidx.room:room-ktx:$room_version"){
exclude(group:'org.xerial')
}
implementation 'org.xerial:sqlite-jdbc:3.34.0' // 最重要的 最重要的 最重要的
之后产生了第二个问题
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
解决方法:
移除build gradle中
"room.incremental":"true",
"room.expandProjection":"true"]