Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

androidx.work.impl.WorkManagerInitializer: java.lang.ClassNotFoundException: "androidx.work.impl.WorkManagerInitializer" on path: /data/app/app-2.apk

I recently migrated my old app's background services to WorkManager. On recent devices (down to sdk 22 included) it looks OK, running repeating work units and scheduling them even across device reboots as expected.

The problem is when I test against old version (old is very relative here), Android sdk 14 which is my minSdkVersion. BTW also WorkManager should have the same: Backwards compatible up to API 14 according to doc. As stated in title, error I get is:

 java.lang.RuntimeException: Unable to get provider androidx.work.impl.WorkManagerInitializer: java.lang.ClassNotFoundException: Didn't find class "androidx.work.impl.WorkManagerInitializer" on path: /data/app/com.example.myapp.apk
    at android.app.ActivityThread.installProvider(ActivityThread.java:4822)

I don't have any custom WorkManager configuration/initialization, I simply added

     implementation 'androidx.work:work-runtime:2.2.0'

to my module's gradle and used it quite typcally to schedule background operations.

like image 287
Shine Avatar asked Oct 28 '19 17:10

Shine


2 Answers

I have the same problem in Androd 19

Reading this and this I solved using

Gradle:

multiDexEnabled true

Java:

public class MyApp extends Application {

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}
like image 52
MadMurdok Avatar answered Dec 07 '22 12:12

MadMurdok


Problem was caused by multiDexEnabled true which I had in defaultConfig for unknown reasons. I found it out after some digging and an issue

like image 39
Shine Avatar answered Dec 07 '22 12:12

Shine