7

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?

DreamTeam Mobile
  • 531
  • 3
  • 15
  • Did you have multidex enabled in your Android project? – FreakyAli Apr 24 '20 at 05:25
  • 1
    I recommand you to use Custom Linker Configuration : take a look at this tutorial: [progrunning.net/fixing-xamarin-forms-linker-issues](https://progrunning.net/fixing-xamarin-forms-linker-issues/) – Leo Zhu Apr 24 '20 at 05:27
  • @FreakyAli yes, I had to switch multidex on because without it I wasn't able to compile the app at all. – DreamTeam Mobile Apr 24 '20 at 07:18
  • @LeoZhu-MSFT I'm familiar with custom linker configuration, but I don't understand how that will help my R8 not to strip required classes. Because the classes are removed by R8, not by Xamarin linker. I assume that because my linker configuration is set to SDK only and this doesn't touch 3d party libs like Google Firebase provider – DreamTeam Mobile Apr 24 '20 at 07:21
  • 2
    R8 and ProGuard will load the obfuscation configuration file,you could try to [Customizing ProGuard](https://learn.microsoft.com/en-us/xamarin/android/deploy-test/release-prep/proguard?tabs=windows#customizing-proguard),e.g: `-keep public class xxxxx` – Leo Zhu Apr 28 '20 at 07:03
  • @LeoZhu-MSFT Thanks, I had the same problem, but using the new [AndroidX Startup Library](https://developer.android.com/topic/libraries/app-startup). Excluding some classes from the obfuscation is the right thing to do! –  Jun 22 '20 at 18:38
  • Still same issue. Any update please? – Ibrahim Sep 10 '21 at 20:24
  • @DreamTeamMobile did you ever resolve this, I am facing a similar issue where I can't use r8 at all or my app crashes at start. – jmichas Mar 14 '22 at 11:48

0 Answers0