Xamarin-android: Unable to get provider com.google.firebase.provider.FirebaseInitProvider

Created on 26 Jul 2019  路  11Comments  路  Source: xamarin/xamarin-android

Hi,

Why I started getting this error since I updated to Visual Studio 16.2?

I am not getting anything logged in AppCenter but attached is what I got from Google Play Console for different devices

Thanks,
Jassim

Most helpful comment

I kept r8 to keep low size of my production app and included this line in my proguard.cfg. Worked for me.
-keep class com.google.firebase.provider.FirebaseInitProvider
Edit: this caused the app not to be able to initialize firebase service. I had to add additionally:
-dontwarn com.google.android.gms.*
-keep class com.google.android.gms.
* { ; }
-keep class com.google.firebase.
* { *; }

All 11 comments

@jrahma can you give more detail? Which error message should we be looking at here?

Please see the attached from Android Device Monitor and you can see the same error

My app crashes immediately when apk from Release mode but works perfectly when using Debug mode

I opened this case too so maybe you can merge both

log.txt

Do you need a proguard rule for this type?

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

I am not using proguard, do I need to use it?

AndroidSetup

Code Shrinker = r8 uses proguard rules, stripping Java code, r8 is _mostly_ backwards compatible with proguard.

@jonathanpeppers do I need to add all the below from Microsoft website including this line?

-keep class com.google.firebase.provider.FirebaseInitProvider

From Microsoft:

# This is Xamarin-specific (and enhanced) configuration.

-dontobfuscate

-keep class com.google.firebase.provider.FirebaseInitProvider
-keep class mono.MonoRuntimeProvider { *; <init>(...); }
-keep class mono.MonoPackageManager { *; <init>(...); }
-keep class mono.MonoPackageManager_Resources { *; <init>(...); }
-keep class mono.android.** { *; <init>(...); }
-keep class mono.java.** { *; <init>(...); }
-keep class mono.javax.** { *; <init>(...); }
-keep class opentk.platform.android.AndroidGameView { *; <init>(...); }
-keep class opentk.GameViewBase { *; <init>(...); }
-keep class opentk_1_0.platform.android.AndroidGameView { *; <init>(...); }
-keep class opentk_1_0.GameViewBase { *; <init>(...); }

-keep class android.runtime.** { <init>(***); }
-keep class assembly_mono_android.android.runtime.** { <init>(***); }
# hash for android.runtime and assembly_mono_android.android.runtime.
-keep class md52ce486a14f4bcd95899665e9d932190b.** { *; <init>(...); }
-keepclassmembers class md52ce486a14f4bcd95899665e9d932190b.** { *; <init>(...); }

# Android's template misses fluent setters...
-keepclassmembers class * extends android.view.View {
   *** set*(***);
}

# also misses those inflated custom layout stuff from xml...
-keepclassmembers class * extends android.view.View {
   <init>(android.content.Context,android.util.AttributeSet);
   <init>(android.content.Context,android.util.AttributeSet,int);
}

I usually only put rules in my apps when I a hit a crash, so I would start with:

-keep class com.google.firebase.provider.FirebaseInitProvider

Here is a good blog post to learn about proguard rules: https://www.jon-douglas.com/2016/11/22/xamarin-android-proguard/

If you don't want to go through this, you can probably set Code Shrinker to None for now.

I had to get rid of the r8 just to get it up and running which is sad decision but at least it's working now

Thanks @jonathanpeppers

I kept r8 to keep low size of my production app and included this line in my proguard.cfg. Worked for me.
-keep class com.google.firebase.provider.FirebaseInitProvider
Edit: this caused the app not to be able to initialize firebase service. I had to add additionally:
-dontwarn com.google.android.gms.*
-keep class com.google.android.gms.
* { ; }
-keep class com.google.firebase.
* { *; }

Yes @Adlorem that sounds right, my guess here is that more proguard rules were needed.

@jrahma I think we can actually close this, as I don't think there was a problem in Xamarin.Android here, let me know, thanks!

Was this page helpful?
0 / 5 - 0 ratings