将WorkManager从1.0.0-alpha02升级到1.0.0-alpha03时出现运行时异常

时间:2018-06-23 04:54:32

标签: android android-workmanager

当我将WorkManager从1.0.0-alpha02升级到1.0.0-alpha03时。

旧build.gradle

def work_version = "1.0.0-alpha02"
implementation "android.arch.work:work-runtime:$work_version" // use -ktx for Kotlin
// optional - Firebase JobDispatcher support
implementation "android.arch.work:work-firebase:$work_version"

新建build.gradle

def work_version = "1.0.0-alpha03"
implementation "android.arch.work:work-runtime:$work_version" // use -ktx for Kotlin
// optional - Firebase JobDispatcher support
implementation "android.arch.work:work-firebase:$work_version"

我注意到我需要进行以下更改

1.0.0-alpha02

public WorkerResult doWork() {

1.0.0-alpha03

public Result doWork() {

但这不是主要问题。但是,如果我们倾向于升级以前已经使用1.0.0-alpha02运行的应用程序,则会得到以下运行时异常

android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: WorkTag.tag, WorkTag.work_spec_id (code 1555)
    at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method)
    at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:734)
    at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754)
    at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64)
    at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1679)
    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1608)
    at android.arch.persistence.db.framework.FrameworkSQLiteDatabase.execSQL(FrameworkSQLiteDatabase.java:242)
    at androidx.work.impl.WorkDatabaseMigrations$1.migrate(WorkDatabaseMigrations.java:73)
    at android.arch.persistence.room.RoomOpenHelper.onUpgrade(RoomOpenHelper.java:85)
    at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onUpgrade(FrameworkSQLiteOpenHelper.java:133)
    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:256)
    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
    at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:96)
    at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:54)
    at android.arch.persistence.room.RoomDatabase.compileStatement(RoomDatabase.java:244)
    at android.arch.persistence.room.SharedSQLiteStatement.createNewStatement(SharedSQLiteStatement.java:65)
    at android.arch.persistence.room.SharedSQLiteStatement.getStmt(SharedSQLiteStatement.java:72)
    at android.arch.persistence.room.SharedSQLiteStatement.acquire(SharedSQLiteStatement.java:87)
    at androidx.work.impl.model.WorkSpecDao_Impl.resetScheduledState(WorkSpecDao_Impl.java:337)
    at androidx.work.impl.WorkManagerImpl.rescheduleEligibleWork(WorkManagerImpl.java:514)
    at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:73)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
    at java.lang.Thread.run(Thread.java:761)

为了避免运行时异常,我可以知道一些解决方法吗?

1 个答案:

答案 0 :(得分:0)

我们在Worker中为alpha03引入了隐式标签。在极少数情况下,您有一个预先存在的标签,就会发生这种情况。我们将在alpha04中解决此问题。敬请关注。