harry_mitch
harry_mitch

Reputation: 167

NuGet packages Xamarin.Forms and Xamarin.Firebase.Messaging are not working together

I created a new Android project in Visual Studio for Mac and I installed the NuGet packages Xamarin.Forms and Xamarin.Firebase.Messaging. But I get the following error if I use the NuGet packages Xamarin.Forms and Xamarin.Firebase.Messaging in my Android project:

/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/32.0.476/tools/Xamarin.Android.D8.targets(5,5): Error: java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: /Users/myname/.nuget/packages/xamarin.google.guava.listenablefuture/1.0.0.5/buildTransitive/net6.0-android31.0/…/…/jar/guava-listenablefuture.jar : com/google/common/util/concurrent/ListenableFuture.class

I don’t get the error when I only use Xamarin.Forms in my Android project or if I only use Xamarin.Firebase.Messaging in my Android project.

I use Visual Studio for Mac 2022 17.4 (build 2406).

How can I use the NuGet packages Xamarin.Forms and Xamarin.Firebase.Messaging together in my Android project?

enter image description here

Upvotes: 0

Views: 576

Answers (2)

harry_mitch
harry_mitch

Reputation: 167

I found the answer here: https://github.com/xamarin/AndroidX/issues/535

It seems to work now. I installed Xamarin.Google.Guava Version="31.1.0.4" and then I installed Xamarin.Firebase.Messaging and finally Xamarin.Forms. In addition, it was necessary to add this line to my .csproj file:

<XamarinGoogleGuavaOptOut>true</XamarinGoogleGuavaOptOut>

Upvotes: 0

ToolmakerSteve
ToolmakerSteve

Reputation: 21340

What "project template" did you use to create this?

If you didn't choose a "Xamarin.Forms" template, then you won't succeed in adding Xamarin.Forms.

  • Start over, and choose Xamarin.Forms / Blank App. Build. You should see MULTIPLE projects in your solution: a cross-platform one (that references Xamarin.Forms nuget), and an Android one.

  • Add Xamarin.Firebase.Messaging to the Android project.

The end result is that Xamarin.Forms nuget is part of cross-platform code, the Android implementation of XFM is part of Android code.

These are two separate projects; it is not meaningful to have both nugets in a single project.

  • Now, when you build the app for Android, it will include the cross-platform project correctly.

Upvotes: 0

Related Questions