简体   繁体   English

在Xamarin.Forms中使用Android支持库API Level 26(MonoAndroid 8.0 Oreo)?

[英]Using android support libraries API Level 26 (MonoAndroid 8.0 Oreo) in Xamarin.Forms?

I can't upgrade Android support libraries to 26.xx (API level 26 = 8.0 Oreo) because Xamarin.forms have a strict dependency to 25.xx It seems Xamarin.Forms don't support Mono.Android 8.0? 我无法将Android支持库升级到26.xx(API级别26 = 8.0 Oreo),因为Xamarin.forms对25.xx有严格的依赖性。似乎Xamarin.Forms不支持Mono.Android 8.0?

Example: When trying to upgrade Xamarin.Android.Support.Design to 26.1.0.1 the following error occurs: "Version conflict detected for Xamarin.Android.Support.Compat. Reference the package directly from the project to resolve this issue. TestApp.Android -> Xamarin.Android.Support.Design 26.1.0.1 -> Xamarin.Android.Support.Compat (= 26.1.0.1) TestApp.Android -> Xamarin.Android.Support.v4 25.4.0.2 -> Xamarin.Android.Support.Compat (= 25.4.0.2)." 示例:尝试将Xamarin.Android.Support.Design升级到26.1.0.1时,会发生以下错误:“检测到Xamarin.Android.Support.Compat的版本冲突。直接从项目引用包以解决此问题.TestApp.Android - > Xamarin.Android.Support.Design 26.1.0.1 - > Xamarin.Android.Support.Compat(= 26.1.0.1)TestApp.Android - > Xamarin.Android.Support.v4 25.4.0.2 - > Xamarin.Android.Support。 Compat(= 25.4.0.2)。“

And also, if you look at the dependencies for the Xamarin.Forms nuget package, MonoAndroid 8.0 isn't even listed. 而且,如果你看看Xamarin.Forms nuget包的依赖项,MonoAndroid 8.0甚至没有列出。 Why is that? 这是为什么? And what can I do to use API level 26 support libraries in XF? 如何在XF中使用API​​级别26支持库?

You need to make sure you have the Android SDK installed for Oreo. 您需要确保为Oreo安装了Android SDK。 You then need to go to the android project properties (Right click on the project folder in the solution explorer and select 'Properies' from the popup menu. 然后,您需要转到android项目属性(右键单击解决方案资源管理器中的项目文件夹,然后从弹出菜单中选择“Properies”。

Under the 'Application Tab', you will find 'Compile using Android version: (Target Framework)' Select the Oreo SDK. 在“应用程序选项卡”下,您将找到“使用Android版编译:(目标框架)”选择Oreo SDK。 Now you should be able to update the app compat libraries to use 26.2.0.1. 现在您应该能够更新app compat库以使用26.2.0.1。

if you look at the dependencies for the Xamarin.Forms nuget package, MonoAndroid 8.0 isn't even listed. 如果你看看Xamarin.Forms nuget包的依赖项,MonoAndroid 8.0甚至没有列出。 It seems Xamarin.Forms don't support Mono.Android 8.0? 看来Xamarin.Forms不支持Mono.Android 8.0吗?

You could use Mono.Android 8.0 with Xamarin.Forms . 您可以将Mono.Android 8.0Xamarin.Forms一起Xamarin.Forms Here are my nuget packages . 这是我的nuget包

Version conflict detected for Xamarin.Android.Support.Compat. 检测到Xamarin.Android.Support.Compat的版本冲突。 Reference the package directly from the project to resolve this issue. 直接从项目引用包以解决此问题。 TestApp.Android -> Xamarin.Android.Support.Design 26.1.0.1 -> Xamarin.Android.Support.Compat (= 26.1.0.1) TestApp.Android -> Xamarin.Android.Support.v4 25.4.0.2 -> Xamarin.Android.Support.Compat (= 25.4.0.2). TestApp.Android - > Xamarin.Android.Support.Design 26.1.0.1 - > Xamarin.Android.Support.Compat(= 26.1.0.1)TestApp.Android - > Xamarin.Android.Support.v4 25.4.0.2 - > Xamarin.Android .Support.Compat(= 25.4.0.2)。

The Xamarin.Android.Support.Compat 26.1.0.1 NuGet package contains assemblies for MonoAndroid v8.0 . Xamarin.Android.Support.Compat 26.1.0.1 NuGet包中包含MonoAndroid v8.0程序集。 So you will need to change the target framework of your Android project to be 8.0. 因此,您需要将Android项目的目标框架更改为8.0。 You should be able to change that in the Visual Studio project options . 您应该能够在Visual Studio 项目选项中更改它。

You may need to update your Android SDKs if v8.0 is not available. 如果v8.0不可用,您可能需要更新Android SDK。

Using android support libraries API Level 26 (MonoAndroid 8.0 Oreo) in Xamarin.Forms? 在Xamarin.Forms中使用Android支持库API Level 26(MonoAndroid 8.0 Oreo)?

  • Install Android 8.0 SDK 安装Android 8.0 SDK
  • Adjust Target SDK version in the project settings in VS 在VS中的项目设置中调整Target SDK版本
  • Upgrade your nunget package. 升级您的nunget包。 (Include Xamarin.Forms package) (包括Xamarin.Forms包)

In theory, we should be done here. 从理论上讲,我们应该在这里完成。 However, if it stil not work, you could do some additional steps: 但是,如果它不起作用,您可以执行一些额外的步骤:

  • Remove all "bin" and "obj" folders in the solution 删除解决方案中的所有“bin”和“obj”文件夹
  • Restart VS 重启VS.
  • Do a nuget restore and rebuild 做一个nuget恢复和重建

If you set your targeted framework lets say to 8.1 make sure that your .csproj has the folowwing <TargetFrameworkVersion>v8.1</TargetFrameworkVersion> 如果你设置了你的目标框架,那么就说8.1确保你的.csproj具有以下<TargetFrameworkVersion>v8.1</TargetFrameworkVersion>

The problem for me was that I also had a <TargetFrameworkVersion>v7.1</TargetFrameworkVersion> that I had to delete. 对我来说问题是我还有一个我必须删除的<TargetFrameworkVersion>v7.1</TargetFrameworkVersion> Once I deleted this line everything started working. 删除此行后,一切都开始工作了。

Apparently visual studio wasn't able to remove previous version from csproj. 显然,visual studio无法从csproj中删除以前的版本。

You can access csproj by unloading the android project, then right click on android project, edit csproj, then you can look for TargetFrameworkVersion tags. 你可以通过卸载android项目访问csproj,然后右键单击android项目,编辑csproj,然后你可以查找TargetFrameworkVersion标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM