Android Work Manager: “Could not instantiate Worker”

↘锁芯ラ 提交于 2019-12-05 01:38:23

This is a known issue with WorkManager 1.0.0-alpha09 that is already marked as fixed for alpha10.

As a workaround, you can add the following lines to your proguard configuration:

-keepclassmembers class * extends androidx.work.Worker {
    public <init>(android.content.Context,androidx.work.WorkerParameters);
}

I had the same issue. The cause of the issue for me was that my Worker class was a nested class. The moment I made it an independent class, it worked.

I had this problem in stable version 1.0.0 and I fixed it by making my worker class public.

class MyWorker extends Worker {...} > public class MyWorker extends Worker {...}

The problem for me was the constructor of my kotlin class:

WRONG

class MyWorker(val app: Application, workerParams: WorkerParameters): Worker(app, workerParams)

GOOD

class MyWorker(val context: Context, workerParams: WorkerParameters): Worker(context, workerParams)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!