无法将 Xamarin.Azure.NotificationHub.Android nuget 安装到现有项目

Unable to installl Xamarin.Azure.NotificationHub.Android nuget to existing project

当我尝试将 Xamarin.Azure.NotificationHub.Android nuget 包安装到我现有的 xamarin.forms 项目时出现以下错误。

One or more unresolved package dependency constraints detected in the existing packages.config file. All dependency constraints must be resolved to add or update packages. If these packages are being updated this message may be ignored, if not the following error(s) may be blocking the current package operation: 'Xamarin.Forms 4.5.0.617 constraint: Xamarin.AndroidX.Lifecycle.LiveData (>= 2.1.0)', 'Xamarin.Forms 4.5.0.617 constraint: Xamarin.Google.Android.Material (>= 1.0.0)', 'Xamarin.Forms 4.5.0.617 constraint: Xamarin.AndroidX.Legacy.Support.V4 (>= 1.0.0)', 'Xamarin.Forms 4.5.0.617 constraint: Xamarin.AndroidX.Browser (>= 1.0.0)'

Unable to find a version of 'Xamarin.Android.Arch.Core.Common' that is compatible with 'Xamarin.Android.Arch.Core.Runtime 1.1.1.3 constraint: Xamarin.Android.Arch.Core.Common (= 1.1.1.3)', 'Xamarin.Android.Arch.Lifecycle.LiveData 1.1.1.3 constraint: Xamarin.Android.Arch.Core.Common (= 1.1.1.3)', 'Xamarin.Android.Arch.Lifecycle.LiveData.Core 1.1.1.3 constraint: Xamarin.Android.Arch.Core.Common (= 1.1.1.3)'.

但是我的项目已经安装了 Xamarin.Android.Arch.*** 1.1.1.3。

我在将 Xamarin.Azure.NotificationHub.Android nuget 安装到新项目时没有遇到任何问题。安装到我现有的已经使用 AppCenter 的 Xamarin.Forms 项目时发生错误。 这是因为某些包依赖冲突吗?如果有,如何解决?

Xamarin.Azure.NotificationHub.Android (1.1.1) 包使用 Xamarin.GooglePlayServices.Base (>= 70.x.x)Xamarin.Firebase.Messaging (>= 70.x.x) 作为依赖项。项目中安装的包之一也依赖于 Xamarin.GooglePlayServices.Base 包。 Xamarin.Azure.NotificationHub.Android (1.1.1) 包需要更高版本的 GooglePlayservices.Base (>= 70.x.x) 包。由于我的项目使用 package.config 文件来管理已安装的包,现有包已经安装了较低版本的 GooglePlayservices.Base 包(60.x.x)。

我可以通过两种方式解决这个问题:

  1. 卸载与其所有依赖项产生冲突的包。然后重新安装包,将依赖行为设置为最低。然后我能够安装 NotificationHub.Android 包而没有任何错误。

  2. Migrate from package.config to new PackageReference 格式。这样可以更方便的看到项目上直接安装了哪些包,不用担心依赖关系。这也显示了哪些包造成了冲突。修复了错误日志建议的问题。

NU1107: Version conflict detected for Xamarin.GooglePlayServices.Basement. Install/reference Xamarin.GooglePlayServices.Basement 71.1620.4 directly to project XXX to resolve this issue. XXX -> Xamarin.Azure.NotificationHubs.Android 1.1.1 -> Xamarin.Firebase.Messaging 71.1740.4 -> Xamarin.GooglePlayServices.Basement (>= 71.1620.4)