设备上的文件系统状态不佳。WorkManager无法访问应用程序的内部数据存储。

13

当我在Android Studio中添加工作管理器库并运行应用程序时,它会崩溃,并显示以下错误:

E/SQLiteLog: (14) cannot open file at line 37816 of [c255889bd9]
    (14) os_unix.c:37816: (13) lstat(/data/user/0/com.example/no_backup/androidx.work.workdb) - 
    (1) Process m.example : Pid (13632) Uid (11395) Euid (11395) Gid (11395) Egid (11395)
    (1) osStat failed "/data/user/0/com.example/no_backup/androidx.work.workdb" due to error (13)
    (1) osStat failed "/data/user/0/com.first.academy/no_backup" due to error (13)
    (1) Stat of /data/user/0/com.example : st_mode(40700) st_uid(11385) st_gid(11385) st_ino(164253)
    (1) Stat of /data/user/0 : st_mode(40771) st_uid(1000) st_gid(1000) st_ino(131074)
    (1) Stat of /data/user : st_mode(40711) st_uid(1000) st_gid(1000) st_ino(655366)
    (1) Stat of /data : st_mode(40771) st_uid(1000) st_gid(1000) st_ino(2)
    .....


E/SQLiteDatabase: Failed to open database '/data/user/0/com.example/no_backup/androidx.work.workdb'.
    android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 1806 SQLITE_CANTOPEN_EACCES[1806]): Could not open database
...

E/WM-ForceStopRunnable: The file system on the device is in a bad state. WorkManager cannot access the app's internal data store.
    android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 1806 SQLITE_CANTOPEN_EACCES[1806]): Could not open database
...

E/AndroidRuntime: FATAL EXCEPTION: pool-3-thread-1
    Process: com.example, PID: 13632
    java.lang.IllegalStateException: The file system on the device is in a bad state. WorkManager cannot access the app's internal data store.
        at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:115)
        at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 1806 SQLITE_CANTOPEN_EACCES[1806]): Could not open database
....

这是我添加的库:

implementation "androidx.work:work-runtime-ktx:2.4.0"

当我移除这个库时,应用程序又可以正常工作了。我不知道问题是设备还是应用程序引起的。


你有检查过这个吗?https://dev59.com/G7voa4cB1Zd3GeqPxBqW - Carson Holzheimer
@CarsonHolzheimer 我创建了一个新项目来测试这个问题,我没有向项目中添加任何代码。 - ameencarpenter
1
只有一个设备出现了相同的崩溃。应用程序无法打开。@ameencarpenter,你有什么解决方案吗? - Bhavesh Jabuvani
2个回答

0

我通过将以下内容添加到AndroidManifest.xml文件中成功解决了此问题:

 <provider
    android:name="androidx.startup.InitializationProvider"
    android:authorities="${applicationId}.androidx-startup"
    android:exported="false"
    tools:node="merge">
    <!-- If you are using androidx.startup to initialize other components -->
    <meta-data
        android:name="androidx.work.WorkManagerInitializer"
        android:value="androidx.startup"
        tools:node="remove" />
 </provider>

我从这里的文档中获取了以下内容: https://developer.android.com/topic/libraries/architecture/workmanager/advanced/custom-configuration

3
似乎这个解决方法不足以修复它。这是在我的项目的AndroidManifest上完成的,但我们在这里仍然遇到了相同的问题。 - Rodrigo Bagni
请升级到 AndroidX Work 2.8.1 https://developer.android.com/jetpack/androidx/releases/work#2.8.1 - Quantum_VC

0
只需按照以下代码更改Application类中的Workmanager初始化即可
val configuration: androidx.work.Configuration = androidx.work.Configuration.Builder().build()
        configuration.initializationExceptionHandler.let {
            this.deleteDatabase(WorkManagerImpl::class.java.simpleName)
            this.getSharedPreferences(WorkManagerImpl::class.java.simpleName, Context.MODE_PRIVATE)
                ?.edit()?.clear()?.apply()
            this.let { WorkManager.initialize(it, androidx.work.Configuration.Builder().build()) }
        }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接