本文介绍了如何使用Xamarin.Forms.Maps安装Xamarin.Firebase.Messaging的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安装nuget Xamarin.Firebase.Messaging 使用 xamarin.forms.maps 打包到干净的空项目由于Xamarin.GooglePlayServices.Basement依赖性导致版本冲突.

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.

我的Xamarin.Forms csproj包含以下nuget依赖项:

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>

Android csproj包含以下nuget依赖项:

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>

当我尝试安装nuget软件包时 Xamarin.Firebase.Messaging 失败,并显示以下信息:

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?

推荐答案

使用下面的答案,我们可以构建并运行,但是当试图显示地图时,会出现大量的Java异常.

With my answer below we can build and run, but when try to show a map tons of java exceptions occurs.

最终解决方案:真正的问题是Xamarin.Forms.Maps与Xamarin.GooglePlayServices.Maps的依赖关系(> = 42.1021.1).我以为由于安装了'> =',所以安装了最新版本,但是安装的版本是42.1021.1.在Android csproj中,我将Xamarin.GooglePlayServices.Maps设置为60.1142.0版本,现在可以安装Firebase和Maps了,就像一个魅力! :)

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! :)

在马特·沃德(Matt Ward)回答之后,我遇到了以下错误:

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`

,正如Briefkasten所说.

, as Briefkasten has commented.

为避免此错误,我在Android项目.csproj(在此处查看答案).

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

我已经安装了Xamarin.GooglePlayServices.Base 60.1142.0,它与之前安装的GooglePlayServices版本相同:

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>

现在,我可以使用Firebase和Maps编译并运行我的Android项目了:")

Now I can compile and run my Android project with Firebase and Maps :´)

这篇关于如何使用Xamarin.Forms.Maps安装Xamarin.Firebase.Messaging的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:06