I'm trying to install the nuget Xamarin.Firebase.Messaging package on a clean empty project with xamarin.forms.maps which fails because of version conflict by Xamarin.GooglePlayServices.Basement
dependency.
My Xamarin.Forms csproj contains the following nuget dependencies:
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="2.5.0.280555" />
<PackageReference Include="Xamarin.Forms.Maps" Version="2.5.0.280555" />
</ItemGroup>
The Android csproj contains the following nuget dependencies:
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="2.5.0.280555" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="26.1.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="26.1.0.1" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="26.1.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="26.1.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="26.1.0.1" />
<PackageReference Include="Xamarin.Forms.Maps">
<Version>2.5.0.280555</Version>
</PackageReference>
</ItemGroup>
When I try to install the nuget package Xamarin.Firebase.Messaging it fails with:
PM> Install-Package Xamarin.Firebase.Messaging -IgnoreDependencies
GET https://api.nuget.org/v3/registration3-gz-
semver2/xamarin.firebase.messaging/index.json
OK https://api.nuget.org/v3/registration3-gz-
semver2/xamarin.firebase.messaging/index.json 128ms
Restoring packages for
D:\Projects\mfe\App3\App3\App3.Android\App3.Android.csproj...
Install-Package : Version conflict detected for
Xamarin.GooglePlayServices.Basement. Reference the package directly from the
project to resolve this issue.
App3.Android -> Xamarin.Firebase.Messaging 60.1142.0 ->
Xamarin.GooglePlayServices.Basement (= 60.1142.0)
App3.Android -> Xamarin.Forms.GoogleMaps 2.3.0 ->
Xamarin.GooglePlayServices.Maps 42.1021.1 ->
Xamarin.GooglePlayServices.Basement (= 42.1021.1).
At line:1 char:1
+ Install-Package Xamarin.Firebase.Messaging -IgnoreDependencies
[...]
Is there any workaround for this issue? Something like a fallback to version?
EDIT
With my answer below we can build and run, but when try to show a map tons of java exceptions occurs.
Definitive solution: The real problem was Xamarin.Forms.Maps dependency with Xamarin.GooglePlayServices.Maps (>= 42.1021.1). I thought that the latest version was installed due to '>=', but version installed is 42.1021.1. In Android csproj I set Xamarin.GooglePlayServices.Maps to 60.1142.0 version and now Firebase and Maps can be installed and works like a charm! :)
Following the Matt Ward answer I'm getting errors like:
Type Android.Gms.Maps.Model.CameraPosition` implements
Android.Runtime.IJavaObject but does not inherit Java.Lang.Object or Java.Lang.Throwable. This is not supported. .Android`
, as Briefkasten has commented.
To avoid this errors I set the AndroidErrorOnCustomJavaObject property to false in the Android project .csproj (See answer here).
After that I get new errors like:
java.lang.IllegalArgumentException: already added : Lcom/google/android/gms/internal/zzat
I´ve installed Xamarin.GooglePlayServices.Base 60.1142.0, the same version of GooglePlayServices installed previously:
<PackageReference Include="Xamarin.GooglePlayServices.Base">
<Version>60.1142.0</Version>
</PackageReference>
Now I can compile and run my Android project with Firebase and Maps :´)
If you add a explicit PackageReferences for Xamarin.GooglePlayServices.Basement 60.1142.0 and for Xamarin.GooglePlayServices.Tasks 60.1142.0 then the NuGet package restore seems to work.
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="2.5.0.280555" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="26.1.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="26.1.0.1" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="26.1.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="26.1.0.1" />
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="26.1.0.1" />
<PackageReference Include="Xamarin.GooglePlayServices.Basement" Version="60.1142.0" />
<PackageReference Include="Xamarin.GooglePlayServices.Tasks" Version="60.1142.0" />
<PackageReference Include="Xamarin.Forms.Maps">
<Version>2.5.0.280555</Version>
</PackageReference>
<PackageReference Include="Xamarin.Firebase.Messaging">
<Version>60.1142.0</Version>
</PackageReference>
</ItemGroup>
I just tried your original package references and then used the information in the restore failure to see what explicit references were needed. The first failure was:
Version conflict detected for Xamarin.GooglePlayServices.Basement. Reference the package directly from the project to resolve this issue.
weaga32ewgegw (>= 1.0.0) -> Xamarin.Firebase.Messaging (>= 60.1142.0) -> Xamarin.GooglePlayServices.Basement (>= 60.1142.0)
weaga32ewgegw (>= 1.0.0) -> Xamarin.Forms.Maps (>= 2.5.0.280555) -> Xamarin.GooglePlayServices.Maps (>= 42.1021.1) -> Xamarin.GooglePlayServices.Basement (>= 42.1021.1).
Then I added the explicit PackageReference as indicated in the NuGet restore output, retried, etc, until the restore was successful.
The Android project I was using had a TargetFrameworkVersion of v8.1.
Worth testing if this all still works since that is quite a version jump from 42.1021.1 to 60.1142.0.