I have a Xamarin.Android app which I recently switched to use R8 code shrinker. Unfortunately, my app is crashing on startup with the following error:
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn’t find class “com.google.firebase.provider.FirebaseInitProvider” on path: DexPathList[[zip file “/data/app/app-bundle-1/base.apk”],nativeLibraryDirectories=[/data/app/app-bundle-1/lib/arm64, /data/app/app-bundle-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
at android.app.ActivityThread.installProvider(ActivityThread.java:6105)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5572)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5511)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1611)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:165)
at android.app.ActivityThread.main(ActivityThread.java:6375)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
I found this article, it's more related to MultiDex and native android and wasn't helpful.
Then I discovered this Xamarin.Android specific article with multiplex.keep
file definition. I've added the file multiplex.keep
and set build action to MultiDexMainDexList
:
mono/android/app/ApplicationRegistration.class
mono/android/app/NotifyTimeZoneChanges.class
mono/MonoRuntimeProvider.class
mono/MonoPackageManager.class
mono/MonoPackageManager_Resources.class
com/google/firebase/provider/FirebaseInitProvider.class
The result was the same crash, so I had to disable code shrinker and go with that for now.
Please, advise, how I can have R8 code shrinker enabled (I do want faster builds and smaller packages) and not to crash the app on startup?