I’m getting the following error when I upgrade WorkManager from 2.2.0
to 2.3.0-rc01
during APK export:
C:\app: Error: Remove androidx.work.impl.WorkManagerInitializer from your AndroidManifest.xml when using on-demand initialization. [RemoveWorkManagerInitializer]
According to the documentation, I should remove the provider
from my AndroidManifest.xml
to use on-demand initialization. I’m not sure why I didn’t get such an error in 2.2.0
, as on-demand initialization is supported since 2.1.0
.
My Application
class is as follows:
public class MyApplication extends MultiDexApplication implements Configuration.Provider {
private static MyApplication me;
@Override
public void onCreate() {
super.onCreate();
me = this;
}
public static MyApplication instance() {
return me;
}
@NonNull
@Override
public Configuration getWorkManagerConfiguration() {
return new Configuration.Builder()
.build();
}
}
I construct WorkManager as follows:
public static WorkManager getWorkManager() {
MyApplication myApplication = MyApplication.instance();
if (myApplication == null) {
return WorkManager.getInstance();
} else {
return WorkManager.getInstance(myApplication);
}
}
Including the provider
in my AndroidManifest.xml
will eliminate the error during APK export. However, I’m not sure if this is the correct way to use on-demand initialization.