Remove default init when using both Default & Custom?

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.

To resolve the error and use on-demand initialization with WorkManager 2.3.0-rc01, you should remove the provider from your AndroidManifest.xml.

Here’s the updated AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.yourapp">

    <!-- Other manifest entries -->

    <application
        android:name=".MyApplication"
        <!-- Remove the following line -->
        <!-- <provider
            android:name="androidx.work.impl.WorkManagerInitializer"
            android:authorities="${applicationId}.workmanager-init"
            android:exported="false"
            tools:node="remove" /> -->
    </application>
</manifest>

By removing the provider entry, you will be using the on-demand initialization feature correctly, as described in the documentation.