Firebase Java Runtime exception for xamarin android

Phil 166 Reputation points
2021-03-16T14:15:24.497+00:00

Hi there
I have had a look around and could not find a solution to my problem. I am trying to get push notifications to work using the "firebase cloud messaging" service.
I am following the Microsoft xamarin guide
https://learn.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=windows#fcm-notifications-overview.

I am unable to get past the first stage.
I have created a firecloud account. I have the Json and have included it in the project with the same name etc.

In order to import the Nuget packages I also had to import a few more that seemed to be missing from the guide for the project to build.

Namely xamarin.google.dagger

I have as far as I can tell everything correct but I get the exception Java.Lang.RuntimeException
Message=Unable to get provider com.google.firebase.provider.FirebaseInitProvider: com.google.firebase.components.MissingDependencyException: Unsatisfied dependency for component Component<[class com.google.firebase.messaging.FirebaseMessaging]>{1, type=0, deps=[Dependency{anInterface=class com.google.firebase.FirebaseApp, type=required, injection=direct}, Dependency{anInterface=interface com.google.firebase.platforminfo.UserAgentPublisher, type=optional, injection=provider}, Dependency{anInterface=class com.google.firebase.iid.FirebaseInstanceId, type=required, injection=direct}, Dependency{anInterface=interface com.google.firebase.events.Subscriber, type=required, injection=direct}, Dependency{anInterface=interface com.google.android.datatransport.TransportFactory, type=optional, injection=direct}, Dependency{anInterface=interface com.google.firebase.heartbeatinfo.HeartBeatInfo, type=optional, injection=provider}, Dependency{anInterface=interface com.google.firebase.installations.FirebaseInstallationsApi, type=required, injection=direct}]}: class com.google.firebase.iid.FirebaseInstanceId.

I have done some googling and tried the things I saw such as enabling multi-dex.
My manifest has the permissions:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

I saw that these maybe needed. I have tried to run it on both an emulator and a physical device.

I am using the d8 Dex Compiler and my minimum android version is 8.1 with my target android version being set to Android 9.0.

Any help would be appreciated. The error implies it is looking for some kind of dependency injection for a messaging service?
The Microsoft guide doesn't specify having to set anything up.

It feels like I may be missing a Nuget package or some kind of configuration/manifest issue.

Any pointers would be greatly appreciated.

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,971 Reputation points
    2021-03-17T08:37:00.64+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Hi,Phil-3682. Here are the related packages about the function, please check if there is anything missing.

       <PackageReference Include="Xamarin.Build.Download">  
       <Version>0.4.11</Version>  
       </PackageReference>  
       <PackageReference Include="Xamarin.Firebase.Common">  
       <Version>60.1142.1</Version>  
       </PackageReference>  
       <PackageReference Include="Xamarin.Firebase.Iid">  
       <Version>60.1142.1</Version>  
       </PackageReference>  
       <PackageReference Include="Xamarin.Firebase.Messaging">  
       <Version>60.1142.1</Version>  
       </PackageReference>  
       <PackageReference Include="Xamarin.GooglePlayServices.Base">  
       <Version>60.1142.1</Version>  
       </PackageReference>  
       <PackageReference Include="Xamarin.GooglePlayServices.Basement">  
       <Version>60.1142.1</Version>  
       </PackageReference>  
       <PackageReference Include="Xamarin.GooglePlayServices.Tasks">  
       <Version>60.1142.1</Version>  
    

    You could check the official sample code:
    https://learn.microsoft.com/en-us/samples/xamarin/monodroid-samples/firebase-fcmnotifications/

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Phil 166 Reputation points
    2021-03-19T09:47:48.89+00:00

    Hi
    I started a new project and it seemed to configure itself with androidX (sorry i'm quite new to all this). I have found some tutorials and examples haven't worked as a result. I have had to adapt them when passing in the application context etc.

    The Nuget Packages for androidX I have are:
    Xamarin.AndrodiX.AppCompat 1.1.0.1
    Xamarin.AndroidX,AppCompat.Resources 1.1.0.1
    Xamarin.AndroidX.Browser 1.2.0.2
    Xamarin.AndrodiX.Legacy.Support.V4 1.0.0.2 **
    **Xamarin.AndroidX.Lifecycle.LiveData 2.2.0.2

    Xamarin.Forms 4.8.0.1269

    I found a lot of tutorials and git code to either have issues due to the forms being older. The way the context is passed also seems to have changed (as I stated above). As I started a new xamarin.forms and a separate xamarin.android project to try things out I didn't have to migrate things. These are the libraries and packages it came with and I have been learning/adding to it from there.

    I did manage to get fire base working and can publish using the API to get the notification in the background. The version for xamarin firebase needs to be 71.1740 for it to compile. This might be due to some of my other Nuget packages not being updated? If I go for later versions I get the exception I started this question for.

    Hope this is of some help.

    Like I said i'm still relatively new to this and feeling my way around.

    1 person found this answer helpful.
    0 comments No comments

  2. Phil 166 Reputation points
    2021-03-17T09:28:48.53+00:00

    Hi thanks for the reply.
    I have done some experimenting with the different packages and versions,
    I can get it to work with Xamarin.Firebase.Messaging Version 71.1740.4.
    After that it jumps to version 119.0.1 and then there are some versions until the latest at 121.0.1.

    I have done some testing and got the notifications sending from the firebase console to my physical tablet. It now builds etc.
    Something has obviously changed between versions 71 and 119.
    I am curious as to what has changed and why it would stop building?

    Here is my list of References that seem to be working for me.

    <PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.3" />
    <PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.3" />
    <PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="28.0.0.3" />
    <PackageReference Include="Xamarin.AndroidX.Browser">
      <Version>1.3.0.5</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Legacy.Support.Core.UI">
      <Version>1.0.0.8</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData">
      <Version>2.3.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
    <PackageReference Include="Xamarin.Firebase.Messaging">
      <Version>71.1740.4</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Google.Android.Material">
      <Version>1.3.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Base">
      <Version>117.6.0</Version>
    </PackageReference>
    <PackageReference Include="XamarinLibrary.Xamarin.Android.Javax.Inject.JavaxInject">
      <Version>1.0.0</Version>
    </PackageReference>
    

    Feel free to mention if you think I have missed anything or added anything I don't need.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.