如何使用Xamarin.Forms.Maps安装Xamarin.Firebase.Messaging

时间:2018-02-27 14:41:25

标签: xamarin.forms nuget nuget-package

我尝试在Xamarin.Firebase.Messaging的干净空项目上安装nuget xamarin.forms.maps软件包,但因Xamarin.GooglePlayServices.Basement依赖项版本冲突而失败。

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

<ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="2.5.0.280555" />
    <PackageReference Include="Xamarin.Forms.Maps" Version="2.5.0.280555" />
</ItemGroup>

Android csproj包含以下nuget依赖项:

  <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时,它失败了:

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
[...]

此问题是否有解决方法?有点像版本的后备吗?

2 个答案:

答案 0 :(得分:1)

  

编辑

     

根据我的回答,我们可以构建并运行,但是当试图显示地图时会发生大量的java异常。

     

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

按照马特沃德的回答,我得到的错误如下:

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评论的那样。

为避免此错误,我在Android项目.csproj(See answer here)中将AndroidErrorOnCustomJavaObject属性设置为false。

之后我收到了新的错误:

java.lang.IllegalArgumentException: already added : Lcom/google/android/gms/internal/zzat

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

<PackageReference Include="Xamarin.GooglePlayServices.Base">
      <Version>60.1142.0</Version>
</PackageReference>

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

答案 1 :(得分:0)

如果为Xamarin.GooglePlayServices.Basement 60.1142.0和Xamarin.GooglePlayServices.Tasks 60.1142.0添加显式PackageReferences,则NuGet包还原似乎有效。

  <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>

我刚刚尝试了原始包引用,然后使用了还原失败中的信息来查看需要哪些显式引用。第一次失败是:

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).

然后我添加了NuGet恢复输出中显示的显式PackageReference,重试等,直到恢复成功。

我使用的Android项目有一个v8.1的TargetFrameworkVersion。

值得测试,如果这一切仍然有效,因为这是一个很大的版本从42.1021.1跳到60.1142.0。