SkiaSharp icon indicating copy to clipboard operation
SkiaSharp copied to clipboard

Xamarin 4.0 , FFImageLoading and SkiaSharp

Open HugoTruffe opened this issue 7 years ago • 14 comments

Hi People.

I am updating my project to Xamarin 4.0, and I am using FFImageLoading with skiaSharp, but with skiaSharp 1.68.0 I have this problem.

/Users/LALA/Projects/Clarika/Imperial-ClienteFiel/ClienteFiel.Forms.iOS/MTOUCH: Error MT0009: Error while loading assemblies: /Users/hugo/.nuget/packages/skiasharp/1.68.0/runtimes/win-x86/native/libSkiaSharp.dll (MT0009) (ClienteFiel.Forms.iOS)

My question.

Do support SkiaSharp the new version o Xamarin?

Thx!

HugoTruffe avatar May 31 '19 17:05 HugoTruffe

In other chat, I found

https://github.com/xamarin/xamarin-macios/issues/5265

HugoTruffe avatar May 31 '19 17:05 HugoTruffe

I'm having the same issue. Xamarin Forms 4.0.0, Visual Studio 2019 for Windows, SkiaSharp.Views.Forms 1.68.0. The workaround of # 5265 to switch from x64 to Any CPU temporally resolve the issue.

AndreaGobs avatar Jun 03 '19 12:06 AndreaGobs

I am having the same issue.

How would I change to Any CPU on VS for Mac?

amirvenus avatar Jun 11 '19 18:06 amirvenus

Any more info on this issue? I have the same problem. Can not make an iOS build with SkiaSharp 1.68.0.

bdgza avatar Jul 01 '19 12:07 bdgza

Any news on this issue ?

jeremymarabel avatar Aug 01 '19 13:08 jeremymarabel

I'm struggeling with this issue as well. As soon as I upgrade to 1.68.0 it cannot load the assemblie. I've tried many suggestions, none solved the problem so far.

GO74 avatar Sep 05 '19 15:09 GO74

I am facing the same issue with Xamarin Forms 4.2.0.848062 and SkiaSharp 1.68.0 Error Details : MTOUCH : error MT0009: Error while loading assemblies:

Is there any fix provided for this issue

NehaGawri avatar Oct 10 '19 10:10 NehaGawri

If you are still hitting this issue, it is likely due to a configuration on your csproj file for your iOS project that looks similar to the following.

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
    <DebugType>none</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\iPhone\Release</OutputPath>
    <DefineConstants>__IOS__;__MOBILE__;__UNIFIED__;Release;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <MtouchArch>ARM64</MtouchArch>
    <CodesignKey>iPhone Distribution</CodesignKey>
    <MtouchUseLlvm>true</MtouchUseLlvm>
    <MtouchFloat32>true</MtouchFloat32>
    <MtouchEnableSGenConc>true</MtouchEnableSGenConc>
    <MtouchLink>SdkOnly</MtouchLink>
    <MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
    <PlatformTarget>x86</PlatformTarget>
</PropertyGroup>

Remove the <PlatformTarget>x86</PlatformTarget> and you should be good to to go. Make sure that you do this for all of your iPhone release configurations, likely Release, Ad-Hoc and AppStore.

michaelstonis avatar Apr 03 '20 14:04 michaelstonis

If you are still hitting this issue, it is likely due to a configuration on your csproj file for your iOS project that looks similar to the following.

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
    <DebugType>none</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\iPhone\Release</OutputPath>
    <DefineConstants>__IOS__;__MOBILE__;__UNIFIED__;Release;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <MtouchArch>ARM64</MtouchArch>
    <CodesignKey>iPhone Distribution</CodesignKey>
    <MtouchUseLlvm>true</MtouchUseLlvm>
    <MtouchFloat32>true</MtouchFloat32>
    <MtouchEnableSGenConc>true</MtouchEnableSGenConc>
    <MtouchLink>SdkOnly</MtouchLink>
    <MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
    <PlatformTarget>x86</PlatformTarget>
</PropertyGroup>

Remove the <PlatformTarget>x86</PlatformTarget> and you should be good to to go. Make sure that you do this for all of your iPhone release configurations, likely Release, Ad-Hoc and AppStore.

Thanks! Works for me!

juanagu avatar Jun 01 '20 20:06 juanagu

I don't have that platform target line and still hitting this error

chrisfoulds avatar Jun 17 '20 15:06 chrisfoulds

I can build locally, because I do not have the PlatformTarget line, but I cannot build via App Center. It's pulling the win-64 version of SkiaSharp:

/Users/runner/work/1/s/iOS/myProject.iOS.csproj" (Rebuild target) (1) -> (_CompileToNative target) -> MTOUCH : error MT0009: Error while loading assemblies: /Users/runner/.nuget/packages/skiasharp/2.80.1/runtimes/win-x64/native/libSkiaSharp.dll [/Users/runner/work/1/s/iOS/myProject.iOS.csproj]

0 Warning(s)
1 Error(s)

Time Elapsed 00:05:49.82 ##[error]Xamarin.iOS task failed with error Error: /Library/Frameworks/Mono.framework/Versions/6_8_1/bin/msbuild failed with return code: 1. For guidance on setting up the build definition, see https://go.microsoft.com/fwlink/?LinkId=760847.

The link is about building apps with AppCenter. This was working great until I needed SkiaSharp for something and had to add it.

DeerSteak avatar Aug 19 '20 16:08 DeerSteak

I saw you posed here too: https://github.com/xamarin/xamarin-macios/issues/5265

I'll see what I can do, but maybe you can try adding ExcludeAssets="runtimes":

<PackageReference Include="SkiaSharp" Version="2.80.1" ExcludeAssets="runtimes" />

This should force the files to not even be loaded.

But, could you try out the v2.80.2 preview, that might fix it.

Also, make sure you add it to the final app project as well.

mattleibow avatar Aug 19 '20 17:08 mattleibow

Hello,

I'm having the same problem here after updating SkiaSharp from 1.60.3 to 2.80.2 Solution is Xamarin.Forms (shared) and an iOS project and Android project. Android works just fine.

Here's the error in iOS build: Severity Code Description Project File Line Suppression State Error Error while loading assemblies: /Users/[user]/Library/Caches/Xamarin/mtbs/builds/[mycompany].iOS/2b8bb42efaa82e056d0923743e8a2829/bin/iPhoneSimulator/Debug/libSkiaSharp.dll. [mycompany].iOS

2> /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch @/Users/[user]/Library/Caches/Xamarin/mtbs/builds/[mycompany].iOS/2b8bb42efaa82e056d0923743e8a2829/obj/iPhoneSimulator/Debug/response-file.rsp "--gcc_flags=-Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/[user]/Library/Caches/Xamarin/mtbs/builds/[mycompany].iOS/2b8bb42efaa82e056d0923743e8a2829/obj/iPhoneSimulator/Debug/Entitlements.xcent" 2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(885,3): error MT0009: Error while loading assemblies: /Users/[user]/Library/Caches/Xamarin/mtbs/builds/[mycompany].iOS/2b8bb42efaa82e056d0923743e8a2829/bin/iPhoneSimulator/Debug/libSkiaSharp.dll.

I have tried removin gthis from the iOS .proj file: <PlatformTarget>x86</PlatformTarget>

And I've tried adding this to the .proj file: ExcludeAssets="runtimes" in the skiaSharp reference(s).

If I regress to 1.60.3 it works just fine.

Any other potential fixes?

Thanks

blmiles avatar Oct 11 '20 21:10 blmiles

I ran into a similar problem with Visual Studio for Mac 8.9.2 (build 0) and early versions.

/Users/Neocriss/Documents/iLive.Mobile/ILive/ILive.iOS/MTOUCH: Error MT0009: Error while loading assemblies: /Users/Neocriss/.nuget/packages/harfbuzzsharp/2.6.1.7/runtimes/win-x86/native/libHarfBuzzSharp.dll. (MT0009) (ILive.iOS)

I added the following lines to the file 'ILive.iOS.csproj':

<RuntimeIdentifiers>osx;osx-x86;osx-x64</RuntimeIdentifiers>
<NuGetRuntimeIdentifier>osx</NuGetRuntimeIdentifier>

then the problem disappeared.

But now there is another problem. My app crashes at runtime with exception (when 'Linker behavior' set to 'Don't Link'):

System.MissingMethodException: Method not found: System.Span`1<uint16> SkiaSharp.SKRunBuffer.GetGlyphSpan()

And my app crashes at runtime with exception (when 'Linker behavior' set to 'Link SDK assemblies only'):

System.ExecutionEngineException: Attempting to JIT compile method 'void SkiaSharp.HarfBuzz.CanvasExtensions:DrawShapedText (SkiaSharp.SKCanvas,SkiaSharp.HarfBuzz.SKShaper,string,single,single,SkiaSharp.SKPaint)' while running in aot-only mode

And this is only reproduced in Visual Studio for Mac 8.9.1 (build 34) and 8.9.2 (build 0) versions.

neminush avatar Mar 17 '21 13:03 neminush