简体   繁体   English

Xamarin 项目无法在 Android 或 Windows 中找到 SkiaSharp

[英]Xamarin project failing to find SkiaSharp in Android or Windows

I confess I'm new to Xamarin and cross-platform development, so apologies if this seems a trivial question, but I've been trying to get to the bottom of it for several evenings now.我承认我是 Xamarin 和跨平台开发的新手,所以如果这似乎是一个微不足道的问题,我深表歉意,但我已经几个晚上一直试图深入了解它。

I have a basic Xamarin Forms application, which runs in Windows 8.1, Windows UWP and Android.我有一个基本的 Xamarin Forms 应用程序,它在 Windows 8.1、Windows UWP 和 Android 中运行。 It uses SkiaSharp for some basic graphics (based on the Skia example).它使用 SkiaSharp 来制作一些基本图形(基于 Skia 示例)。

It was running in all three platforms, but I had to remove and re-add the Xamarin packages to the project and I can't get SkiaSharp to run properly any more in Windows or Android.它在所有三个平台上都运行,但我必须删除 Xamarin 包并将其重新添加到项目中,而且我无法再让 SkiaSharp 在 Windows 或 Android 中正常运行。 I get a BadImageFormatException:我得到一个 BadImageFormatException:

Additional information: Could not load file or assembly 'SkiaSharp, Version=1.56.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)

I get this exception in the x86, x64 and Any CPU configurations for the Windows 8.1 version, and from the Android version.我在 Windows 8.1 版本和 Android 版本的 x86、x64 和 Any CPU 配置中遇到此异常。

If I run it the UWP project, it works perfectly.如果我在 UWP 项目中运行它,它会完美运行。

Relevant project structure:相关项目结构:

  • MyProj.XMForms (Portable) - PCL containing the core Xamarin.Forms App, MainPage with a StackLayout containing a Frame with a MyView, and MyView which contains a Grid with an SKCanvasView. MyProj.XMForms (Portable) - PCL 包含核心 Xamarin.Forms 应用程序,MainPage 包含一个 StackLayout,其中包含一个带有 MyView 的 Frame,以及包含一个带有 SKCanvasView 的 Grid 的 MyView。
  • MyProj.Windows (Windows 8.1) - wrapper - just contains an empty App and a MainPage which loads the MyProj.XMForms App. MyProj.Windows (Windows 8.1) - 包装器 - 只包含一个空的应用程序和一个加载 MyProj.XMForms 应用程序的 MainPage。
  • MyProj.UWP (Universal Windows) - wrapper - just contains an empty App and a MainPage which loads the MyProj.XMForms App. MyProj.UWP (Universal Windows) - 包装器 - 只包含一个空的应用程序和一个加载 MyProj.XMForms 应用程序的 MainPage。
  • MyProj.Droid (Android) - wrapper - just contains a MainActivity which loads the MyProj.XMForms App. MyProj.Droid (Android) - 包装器 - 只包含加载 MyProj.XMForms 应用程序的 MainActivity。

All projects NuGet packages have Xamarin.Forms 2.3.3.180, SkiaSharp 1.56.0 and SkiaSharp.Views.Forms 1.56.0 .所有项目 NuGet 包都有 Xamarin.Forms 2.3.3.180、SkiaSharp 1.56.0 和 SkiaSharp.Views.Forms 1.56.0。 MyProj.Droid also has SkiaSharp.Views (none of the others will accept it). MyProj.Droid 也有 SkiaSharp.Views(其他人都不会接受它)。

I have discovered https://github.com/mono/SkiaSharp/issues/190 and added <ShouldIncludeNativeSkiaSharp>true</ShouldIncludeNativeSkiaSharp> to the csproj without making any difference.我发现了https://github.com/mono/SkiaSharp/issues/190并将<ShouldIncludeNativeSkiaSharp>true</ShouldIncludeNativeSkiaSharp>到 csproj 而没有任何区别。

I have tried removing and re-adding the SkiSharp NuGet packages.我尝试删除并重新添加 SkiSharp NuGet 包。

What am I missing?我错过了什么?

Thanks,谢谢,

Ian伊恩

If you look at the exception message, there is this line:如果您查看异常消息,则有以下行:

Reference assemblies should not be loaded for execution.不应为执行加载引用程序集。

That means you haven't installed the SkiaSharp NuGets into the app projects.这意味着您尚未将 SkiaSharp NuGets 安装到应用程序项目中。 Make sure all the apps have the SkiaSharp , SkiaSharp.Views and SkiaSharp.Views.Forms NuGets installed.确保所有应用程序都安装了SkiaSharpSkiaSharp.ViewsSkiaSharp.Views.Forms NuGets。 The core project only needs the SkiaSharp and SkiaSharp.Views.Forms NuGets.核心项目只需要SkiaSharpSkiaSharp.Views.Forms NuGets。

Also, Windows 8.x is not currently supported due to a limitation in Skia: https://github.com/mono/SkiaSharp/issues/20此外,由于 Skia 的限制,目前不支持 Windows 8.x: https : //github.com/mono/SkiaSharp/issues/20

Okay, I've managed to get Android working by taking the Android project from the SkiaSharp FormsSample and replacing the call to好的,我通过从 SkiaSharp FormsSample 获取 Android 项目并替换对

LoadApplication(new SkiaSharpSample.FormsSample.Platform.App());

with

LoadApplication(new MyPortable.XamarinForms.App());

My original project definitely included all the same NuGets as this one, and I haven't yet identified they key difference which meant that this one worked and mine didn't, but at least I now have a solution which works in both Android and UWP.我的原始项目肯定包含与此相同的所有 NuGet,我还没有确定它们的主要区别,这意味着该项目有效而我的无效,但至少我现在有一个适用于 Android 和 UWP 的解决方案.

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

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