AppLinks crashes with "Make sure to call FirebaseApp.initializeApp(Context) first."

faceoffers28faceoffers28 USUniversity ✭✭✭

For anyone else that runs into this issue, here is how I fixed it.

I was running Xamarin.Forms 2.4.0.282 and Xamarin.Forms.AppLinks 2.4.0.282 using Visual Studio 2015 Enterprise and Xamarin.Android 7.1.0.43 and everything was working just fine. My target is Android 7.1.

I upgraded to Visual Studio 2017 Enterprise and Xamarin.Android 8.2.0.16 (HEAD/a78295902). My target is Android 7.1. That's when I started seeing issues with Xamarin.Forms.AppLinks 2.4.0.282, Xamarin.GooglePlayServices.AppIndexing 29.0.0.1, Xamarin.GooglePlayServices.Base 29.0.0.1 and Xamarin.GooglePlayServices.Basement 29.0.0.1.

Occurring in the OnCreate method
Java.Lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.domainname.appname. Make sure to call FirebaseApp.initializeApp(Context) first.

I upgraded to Xamarin.Forms.AppLinks 2.5.0.280555 and applied Pablo Biagioli's comment on 2017-07-07 15:52:15 UTC from this Bugzilla entry.

https://bugzilla.xamarin.com/show_bug.cgi?id=54383

It fixed the FirebaseApp.initializeApp(Context) issue, but I noticed that none of the new registered links were appearing in the Google Search. One of my old links was appearing in Google Search, but when I clicked on it, it pulled up the web page instead of Deep Linking into my app.

I then upgrade to Xamarin.Forms 2.5.1.444934, did a clean - rebuild and build. I now getting the error again.

Occurs when Application.Current.AppLinks.RegisterLink(_appLink); is used in the Page
Java.Lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.domainname.appname. Make sure to call FirebaseApp.initializeApp(Context) first.

I set the Target to 8.0 and the error still occurred. I set the Target to 8.1 and the error has gone away.

Deep Linking is still not working like it was, so I'm not sure what is wrong. At least the error has gone away.

Posts

  • faceoffers28faceoffers28 USUniversity ✭✭✭

    It looks like I'm not the only one who is having problems with Deep Linking now.

    https://bugzilla.xamarin.com/show_bug.cgi?id=60907

  • JTOneJTOne USMember ✭✭

    The same!

  • JTOneJTOne USMember ✭✭

    I added firebase options
    var options = new FirebaseOptions.Builder()
    .SetApplicationId("1:36385392236:android:c0d54c779ee347e4")
    .SetApiKey("AIzaSyAX-rofUTdK9Z3SGRlvheFBSjyA3AyQRSQ")

    and google-services.json
    https://github.com/vdchernikov/TestKrista/blob/master/DeepLinking/Droid/MainActivity.cs

    All these things got at https://console.firebase.google.com

    No error and the search is working fine

  • faceoffers28faceoffers28 USUniversity ✭✭✭

    @JTOne You shouldn't have to add the options. The google-services.json file should get picked up automatically. I tried your code and kept getting the "FirebaseApp name [DEFAULT] already exists!" message. The only way around the error was to add the FIREBASE-APPNAME to the initialization statement like so.

    FirebaseApp app = FirebaseApp.InitializeApp(this, options, "FIREBASE-APPNAME");

    This gets past the [Default] error but the AppLinks still didn't work.

    I then added this bit of code in the MainActivity and I can see that the [Default] app is already being created.

    var appTest = FirebaseApp.Instance;

    I think my problem is that I'm targeting monoandroid81.

    <package id="Xamarin.Forms" version="2.5.1.444934" targetFramework="monoandroid81" />
      <package id="Xamarin.Forms.AppLinks" version="2.5.0.280555" targetFramework="monoandroid81" />
      <package id="Xamarin.GooglePlayServices.AppIndexing" version="60.1142.1" targetFramework="monoandroid81" /> 
    

    Are you using 7.1 of the Android SDK?

  • JTOneJTOne USMember ✭✭

    Yep, I'm using 8.1 and I added non-default firebase app name

  • PieterjanDeClippelPieterjanDeClippel USMember ✭✭

    I forgot to change the Build Action of the google-services.json to GoogleServicesJson.
    If you can't see this build action, this link tells you to close and reopen your solution after adding the googleservices.json file.
    I didn't need any Initialize command anywhere.

  • ixmliamixmliam Member

    going with @JTOne answer, but just adding "using Firebase;" to the MainActivity solve it form me

Sign In or Register to comment.