0

저는 Rooms에서 app에있는 이전 sqlite db를 마이그레이션 중이며 사용자의 90 %에서 작동합니다. 문제는 100 %가 아니라는 것입니다. 충돌 보고서에 따르면 기기에는 많은 여유 공간과 RAM이 있으며 대부분 Android 4.4의 Samsung Note 2입니다. 또한 응용 프로그램에서 DB를 닫지 않을 것입니다.이전에 회의실 데이터베이스가 폐쇄되었습니다.

충돌 :

Fatal Exception: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/com.szyk.myheart/databases/database.db 
     at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55) 
     at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1648) 
     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594) 
     at android.arch.persistence.db.framework.FrameworkSQLiteDatabase.execSQL(SourceFile:240) 
     at com.szyk.myheart.data.room.Migrations$1.migrate(SourceFile:16) 
     at android.arch.persistence.room.RoomOpenHelper.onUpgrade(SourceFile:73) 
     at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onUpgrade(SourceFile:118) 
     at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:257) 
     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164) 
     at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(SourceFile:93) 
     at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(SourceFile:54) 
     at android.arch.persistence.room.RoomDatabase.inTransaction(SourceFile:305) 
     at android.arch.persistence.room.InvalidationTracker$1.run(SourceFile:281) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
     at java.lang.Thread.run(Thread.java:838) 

룸이 대거 모듈 초기화된다

@Provides 
@ApplicationScope 
public static Database provideDatabase(Context context) { 
    return Room 
      .databaseBuilder(context, Database.class, "database.db") 
      .allowMainThreadQueries() 
      .addMigrations(Migrations.MIGRATION_25_to_26) 
      .addMigrations(Migrations.newDummyMigration(26, 27)) 
      .build(); 
} 

마이그레이션 코드 :

public class Migrations { 
    public static final Migration MIGRATION_25_to_26 = new Migration(25, 26) { 
     @Override 
     public void migrate(@NonNull SupportSQLiteDatabase database) { 
      Timber.d("Migrating to room"); 
      Timber.d("Migration - creating new tables"); 
      // Create the new table - it fails on first call to db 
      database.execSQL(
        "CREATE TABLE IF NOT EXISTS users_new (_id INTEGER PRIMARY KEY AUTOINCREMENT, user_name TEXT NOT NULL, user_birth_date INTEGER, is_diabetes INTEGER NOT NULL)"); 
      ... 

      Timber.d("Migration - completed"); 
     } 
    }; 

    public static Migration newDummyMigration(int from, int to) { 
     return new Migration(from, to) { 
      @Override 
      public void migrate(@NonNull SupportSQLiteDatabase database) { 

      } 
     }; 
    } 
} 

답변

0

문제는 마이그레이션 자체였다. 예외가 자동으로 (Rx) 삼킨 다음 처음으로 충돌 한 다음 각 다음 호출이 닫힌 DB에서 마이그레이션을 실행했습니다.