locked
FirebaseApp is not initialized on real devices RRS feed

  • Question

  • User332990 posted

    Hello! I'm trying to add push notifications in Xamarin.Forms. On Genymotion it's work fine but on real devices i have an error: Default FirebaseApp is not initialized.Make shure to call FirebaseApp.initializeApp(Context)

    google-services.json is present in Android project with GoogleServicesJson BuildAction

    My MainActivity:

         public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
            {
                internal static MainActivity Instance { get; private set; }
                internal static FirebaseInstanceId FirebaseInstance { get; private set; }
    
                public static int CurrentUserId { get; set; }
                protected override async void OnCreate(Bundle bundle)
                {
                    base.OnCreate(bundle);           
    
                    TabLayoutResource = Resource.Layout.Tabbar;
                    ToolbarResource = Resource.Layout.Toolbar;
    
                    VideoViewRenderer.Init();
                    global::Xamarin.Forms.Forms.Init(this, bundle);
                    string dbPath = FileAccessHelper.GetLocalFilePath("LocalDataBase.db");
    
                    LoadApplication(new App());
    
                    Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
                    UserDialogs.Init(this);
                    CachedImageRenderer.Init();           
    
                //on real devices it return  null
                    var app = Firebase.FirebaseApp.InitializeApp(this.ApplicationContext);
    
                    Instance = this;
                }
    
    Sunday, March 11, 2018 5:05 PM

All replies

  • User332990 posted

    Do i need to create Application class that extends Application and call Firebase.FirebaseApp.InitializeApp(this.ApplicationContext) in that class?

    Monday, March 12, 2018 3:12 PM
  • User332990 posted
        Java.Lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.intensfit.android. Make sure to call FirebaseApp.initializeApp(Context) first.
          at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <fcbf47a04b2e4d90beafbae627e1fca4>:0 
          at Java.Interop.JniEnvironment+StaticMethods.CallStaticObjectMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method) [0x00068] in <dcbf64ae8f9943dcab345b6fa6378854>:0 
          at Android.Runtime.JNIEnv.CallStaticObjectMethod (System.IntPtr jclass, System.IntPtr jmethod) [0x0000e] in <303b75409d4e4a17bc65607d320bb98e>:0 
          at Firebase.Iid.FirebaseInstanceId.get_Instance () [0x00032] in <09a4f89addb34f02af055f39e6c540b7>:0 
          at Rel_002.Droid.FirebaseCloudMessaging+<AddOrUpdateTokenAsync>d__2.MoveNext () [0x0005e] in E:\Projects\Rel_002\Rel_002\Rel_002.Android\FirebaseCloudMessaging.cs:73 
          --- End of managed Java.Lang.IllegalStateException stack trace ---
        java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.intensfit.android. Make sure to call FirebaseApp.initializeApp(Context) first.
            at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
            at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
            at mono.java.lang.RunnableImplementor.n_run(Native Method)
            at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:7325)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
    
    Monday, March 12, 2018 10:04 PM
  • User332990 posted

    Worked after downgrade NuGet Xamari.Firebase.Messaging to 42.1001.0

    Tuesday, March 13, 2018 9:03 AM
  • User31968 posted

    Hey,

    I had the same problem and after some investigation I've tried to initiate it manually in that way

        var options = new FirebaseOptions.Builder()
          .SetApplicationId("<AppID>")
          .SetApiKey("<APIKey>")
          .SetDatabaseUrl("https://<url>.firebaseio.com")
          .SetStorageBucket("*.appspot.com")
          .SetGcmSenderId("<senderID").Build();
          var fapp = FirebaseApp.InitializeApp(this, options);
    
          LoadApplication(App);
    
          PushNotificationManager.ProcessIntent(this, Intent);
    

    That worked for me and it seems that the build process "GoogleServiceJson" doesn't work which should does it instead.

    Best regards,

    Thomas

    Tuesday, July 17, 2018 12:47 PM
  • User328763 posted

    In my case the Firebase app not initialized until I cleaned the solution and re-ran then all worked fine (VS2017, Firebase v60).

    Google-services.json was pulled in fine (without using the options builder as above) and I had no need to call FirebaseApp.InitializeApp manually (apparently this is done automatically whenever registration is required).

    Monday, July 30, 2018 2:14 PM
  • User262022 posted

    In my case I had the package name different between my application and my firebase project. So I created another project with the correct package name and downloaded the google-services.json again and put into my application.

    Tuesday, November 6, 2018 4:14 PM
  • User390182 posted

    In my case adding "using Firebase;" to the MainActivity works for me

    Tuesday, November 5, 2019 2:28 PM
  • User392882 posted

    I have the same issue, Rebuild my project solved the issue.

    Wednesday, February 19, 2020 2:43 PM
  • User281843 posted

    Add this Nuget package in the Android project: Xamarin.GooglePlayServices.Basement. After that package has been installed, you will be able to choose the GoogleServicesJson in the build action.

    Thursday, April 23, 2020 5:07 PM
  • User358946 posted

    @ThomasLoidolt said: Hey,

    I had the same problem and after some investigation I've tried to initiate it manually in that way

        var options = new FirebaseOptions.Builder()
          .SetApplicationId("<AppID>")
          .SetApiKey("<APIKey>")
          .SetDatabaseUrl("https://<url>.firebaseio.com")
          .SetStorageBucket("*.appspot.com")
          .SetGcmSenderId("<senderID").Build();
          var fapp = FirebaseApp.InitializeApp(this, options);
    
          LoadApplication(App);
    
          PushNotificationManager.ProcessIntent(this, Intent);
    

    That worked for me and it seems that the build process "GoogleServiceJson" doesn't work which should does it instead.

    Best regards,

    Thomas

    work for me. at any moment, he no longer compiled the google-services file

    Sunday, May 10, 2020 4:38 PM
  • User356280 posted

    I had the same issue, somehow I had to manually add Xamarin.Firebase.Messaging. to my Nuget packages. The plugin has a dependency but did not properly download it.

    Thursday, July 16, 2020 8:53 AM
  • User391162 posted

    After two days of troubleshooting, finally i found out that the latest versions of the below nuget packages (or may be one of them) is causing this. I downgraded to the below versions and it started working.

    Xamarin.Azure.NotificationHubs.Android -> v0.6.0
    Xamarin.Firebase.Messaging -> v71.1740.0
    Xamarin.GooglePlayServices.Base -> v71.1610.0
    
    Tuesday, December 1, 2020 9:15 AM
  • User111256 posted

    I hit this problem and nothing seemed to help. In the end it turned out this was the root issue: https://stackoverflow.com/questions/58495985/firebase-403-permission-denied-firebaseerror-installations-requests-are-blo

    Monday, April 12, 2021 1:35 PM