java.lang.IllegalStateException: Pre-packaged database has an invalid schema: WORDS(mobile.falco.EnglishTrainer.db.model.Words).
 Expected:
TableInfo{name='WORDS', columns={average=Column{name='average', type='INTEGER', affinity='3', notNull=notNull, primaryKeyPosition=0, defaultValue='0'}, ngCount=Column{name='ngCount', type='INTEGER', affinity='3', notNull=notNull, primaryKeyPosition=0, defaultValue='0'}, japanese=Column{name='japanese', type='TEXT', affinity='2', notNull=notNull, primaryKeyPosition=0, defaultValue='null'}, english=Column{name='english', type='TEXT', affinity='2', notNull=notNull, primaryKeyPosition=0, defaultValue='null'}, kigou=Column{name='kigou', type='TEXT', affinity='2', notNull=notNull, primaryKeyPosition=0, defaultValue='null'}, id=Column{name='id', type='INTEGER', affinity='3', notNull=notNull, primaryKeyPosition=1, defaultValue='null'}, ipa=Column{name='ipa', type='TEXT', affinity='2', notNull=notNull, primaryKeyPosition=0, defaultValue='null'}, okCount=Column{name='okCount', type='INTEGER', affinity='3', notNull=notNull, primaryKeyPosition=0, defaultValue='0'}}, foreignKeys=[], indices=[]}
 Found:
TableInfo{name='WORDS', columns={}, foreignKeys=[], indices=[]}
    at androidx.room.RoomOpenHelper.checkIdentity(RoomOpenHelper.kt:159)
    at androidx.room.RoomOpenHelper.onOpen(RoomOpenHelper.kt:128)
    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(FrameworkSQLiteOpenHelper.java:326)
    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:432)
    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:321)
    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableOrReadableDatabase(FrameworkSQLiteOpenHelper.java:273)
    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.innerGetDatabase(FrameworkSQLiteOpenHelper.java:225)
    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getSupportDatabase(FrameworkSQLiteOpenHelper.java:183)
    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:133)
    at androidx.room.SQLiteCopyOpenHelper.getWritableDatabase(SQLiteCopyOpenHelper.kt:71)
    at androidx.room.RoomDatabase.inTransaction(RoomDatabase.kt:634)
    at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.kt:430)

Android11 で実行すると上記のエラーとなる。

Android6 では問題なし。

database = Room.databaseBuilder(applicationContext, AppDatabase::class.java, "hatuon_.db")
    // .fallbackToDestructiveMigration()
    .createFromAsset("database/hatuon.db")
    .allowMainThreadQueries()
    .setJournalMode(RoomDatabase.JournalMode.TRUNCATE)
    .build()

database の名称を huton.db -> hatuon_.db にすることで正常に起動

© 2024 Falco Tech Blog Suffusion theme by Sayontan Sinha