Hello guys.
I have an app that I am developing and that has been working fine for a long time now and the other day I tried to modify it to upload an update and I started gettting this error:
**Java.Lang.IllegalStateException:** 'Default FirebaseApp is not initialized in this process XXXXX. Make sure to call FirebaseApp.initializeApp(Context) first.'
I get the error when I run the app.
This is my MainActivity.cs
[Activity(Label = "XXXXX", Icon = "@mipmap/icon", MainLauncher = true, Theme = "@style/MainTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
#if DEBUG
Android.Webkit.WebView.SetWebContentsDebuggingEnabled(true);
#endif
base.OnCreate(savedInstanceState);
Rg.Plugins.Popup.Popup.Init(this, savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
XF.Material.Droid.Material.Init(this, savedInstanceState);
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
var mChannel = new NotificationChannel("XXXXX", "XXXXX", NotificationImportance.Default);
mChannel.Description = "Notificaciones de la APP";
AudioAttributes audioAttributes = new AudioAttributes.Builder().SetContentType(AudioContentType.Sonification).SetUsage(AudioUsageKind.Notification).Build();
Android.Net.Uri sound1 = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
mChannel.SetSound(sound1, audioAttributes);
mChannel.EnableVibration(true);
mChannel.SetVibrationPattern(new long[] { 800 });
mChannel.ShouldVibrate();
mChannel.EnableLights(true);
mChannel.ShouldShowLights();
var notificationManager = GetSystemService(NotificationService) as NotificationManager;
notificationManager.CreateNotificationChannel(mChannel);
FirebasePushNotificationManager.DefaultNotificationChannelId = "XXXXX";
FirebasePushNotificationManager.DefaultNotificationChannelName = "XXXXX";
}
FirebasePushNotificationManager.IconResource = Resource.Drawable.firebase1;
Android.Net.Uri sound = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
FirebasePushNotificationManager.SoundUri = sound;
#if DEBUG
FirebasePushNotificationManager.Initialize(this, true, false);
#else
FirebasePushNotificationManager.Initialize(this, false, false);
#endif
LoadApplication(new App());
Window.ClearFlags(WindowManagerFlags.TranslucentStatus);
Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
Window.SetStatusBarColor(Android.Graphics.Color.Rgb(0, 72, 224));
}
}
My AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="13" android:versionName="1.4" package="XXXXX" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
<application android:label="XXXXX" android:icon="@mipmap/icon" android:usesCleartextTraffic="true" android:roundIcon="@mipmap/icon_round">
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/firebase1" />
<service android:name="XXXXX.MyFirebaseMessagingService" android:stopWithTask="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
I am using the https://github.com/CrossGeeks/FirebasePushNotificationPlugin plugin to handle Firebase Notifications.
Any help is appreciated.
Thank You.