Xamarin-macios: macOS/iOS can't build x86/x64 when NuGet has runtimes

Created on 12 Dec 2018  路  23Comments  路  Source: xamarin/xamarin-macios

Steps to Reproduce

  1. File | New Solution...
  2. Mac | App | Cocoa App
  3. Install SkiaSharp as a <PackageReference>
  4. Build

Expected Behavior

A successful build.

Actual Behavior

(_CompileToNative target) ->
MMP : error MM0009: Error while loading assemblies: /Users/matthew/.nuget/packages/skiasharp/1.68.0/runtimes/win-x86/native/libSkiaSharp.dll [/Users/matthew/Projects/SkiaSharpMacTest/SkiaSharpMacTest/SkiaSharpMacTest.csproj]

Workaround

I noticed that if I switch from x86 to Any CPU, the issue goes away. For some reason, if building for x86 or x64, it decides to bull in the Windows binaries. Interestingly, there is an osx runtime asset that is totally ignored - even if I am building for Any CPU.

Environment

=== Visual Studio Community 2019 Preview for Mac ===

Version 8.0 Preview (8.0 build 869)
Installation UUID: 3df57dfa-e4cc-43a1-9f16-046811852c10
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 5.0.0.0 ( / b40230c0)

    Package version: 516000221

=== Mono Framework MDK ===

Runtime:
    Mono 5.16.0.221 (2018-06/b63e5378e38) (64-bit)
    Package version: 516000221

=== NuGet ===

Version: 4.7.0.5148

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    2.1.6
    2.1.2
    2.1.1
    2.0.5
    2.0.0
SDK: /usr/local/share/dotnet/sdk/2.1.500/Sdks
SDK Versions:
    2.1.500
    2.1.302
    2.1.301
    2.1.4
    2.0.2
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.4
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 8

=== Xamarin.Android ===

Version: 9.1.4.2 (Visual Studio Community)
Android SDK: /Users/matthew/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
        2.3   (API level 10)
        4.0.3 (API level 15)
        4.1   (API level 16)
        4.3   (API level 18)
        4.4   (API level 19)
        5.0   (API level 21)
        5.1   (API level 22)
        6.0   (API level 23)
        7.0   (API level 24)
        7.1   (API level 25)
        8.0   (API level 26)
        8.1   (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.1
SDK Build Tools Version: 28.0.3

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/matthew/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.9
1.8.0-9
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android Device Manager ===

Version: 1.2.0.1
Hash: 99d7ff4
Branch: remotes/origin/d16-0-p2~1
Build date: 2018-12-03 21:56:10 UTC

=== Xamarin Designer ===

Version: 4.17.1.189
Hash: 0e3953bd9
Branch: remotes/origin/d16-0-p1
Build date: 2018-11-07 13:21:06 UTC

=== Apple Developer Tools ===

Xcode 10.1 (14460.46)
Build 10B61

=== Xamarin.Mac ===

Version: 5.2.1.12 (Visual Studio Community)
Hash: 65ec520f
Branch: 
Build date: 2018-12-05 12:06:09-0500

=== Xamarin.iOS ===

Version: 12.2.1.12 (Visual Studio Community)
Hash: 65ec520f
Branch: d15-9
Build date: 2018-12-05 12:06:09-0500

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 800000869
Git revision: 3c7c96b41ce6b823bf58bb89bda695448ccc97f5
Build date: 2018-12-03 21:59:44+00
Build branch: release-8.0
Xamarin extensions: 87c82bbb37a91ff539738267c414f0d6db88392c

=== Operating System ===

Mac OS X 10.13.6
Darwin 17.7.0 Darwin Kernel Version 17.7.0
    Thu Jun 21 22:53:14 PDT 2018
    root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64

Build Logs

msbuild.binlog.zip

Example Project (If Possible)

Broken: SkiaSharpMacTest.zip
Fixed: SkiaSharpMacTest-fixed.zip

bug macOS msbuild

Most helpful comment

This looks like this bugzilla bug - https://xamarin.github.io/bugzilla-archives/57/57229/bug.html - which has not been fixed.

A workaround is to add some NuGet runtime identifiers to the SkiaSharpMacTest project:

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

All 23 comments

I was able to reproduce that same MMP error with the broken project and the following environment.

The difference between the working and non working project is that:

  • In the non working case MMP is given: /assembly:/Users/vince/.nuget/packages/skiasharp/1.68.0/runtimes/win-x86/native/libSkiaSharp.dll (note that it's from win-x86)
  • In the working case MMP is not given libSkiaSharp.dll at all.

The runtime/osx folder has native/libSkiaSharp.dylib it's not a dll.

This looks like this bugzilla bug - https://xamarin.github.io/bugzilla-archives/57/57229/bug.html - which has not been fixed.

A workaround is to add some NuGet runtime identifiers to the SkiaSharpMacTest project:

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

@mrward @mattleibow thanks, do you happen to have a fix for a Xamarin.iOS build (using forms and SkiaSharp.Views.Forms (1.68.0)

Thanks.

This issue is becoming more and more apparent now that a lot of projects are using PackageReference instead of packages.config

As the issue also occurs for Xamarin.iOS, maybe the title should be changed to reflect that?

This looks like this bugzilla bug - https://xamarin.github.io/bugzilla-archives/57/57229/bug.html - which has not been fixed.

A workaround is to add some NuGet runtime identifiers to the SkiaSharpMacTest project:

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

A dummy question, but where do i have to add these two lines here?

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

in my App.Ios.scproj?

Yes, in the .csproj inside the first <PropertyGroup> element:

Here's the mono issue: https://github.com/mono/mono/issues/15569 (superseding the bugzilla issue)

It's the year 2020 and this is still a problem. Any hope of this getting fixed?

Is there a fix in the works that will let me use skiashark 1.68 with xamarin.ios? This issue seems to have been open a while now!

This may be related to my issue
https://github.com/mono/SkiaSharp/issues/1304
What do I need to add to a iOS project? , things above are for macos

This may be related to my issue
mono/SkiaSharp#1304
What do I need to add to a iOS project? , things above are for macos

Not sure if this helps, but what worked for me was sort of indicated above: In Visual Studio, for my Xamarin.iOS project, the settings under Build -> Compiler -> Platform target was set t x86, which resulted in that skiasharp build issue.I changed that to Any CPU, did a clean and rebuild, and it worked!

This may be related to my issue
mono/SkiaSharp#1304
What do I need to add to a iOS project? , things above are for macos

Not sure if this helps, but what worked for me was sort of indicated above: In Visual Studio, for my Xamarin.iOS project, the settings under Build -> Compiler -> Platform target was set t x86, which resulted in that skiasharp build issue.I changed that to Any CPU, did a clean and rebuild, and it worked!

there is no option for that, it's x86_64 or nothing, well not nothing as it makes you pick one.
I found if I downgraded both mono and monoios it started working again.

This may be related to my issue
mono/SkiaSharp#1304
What do I need to add to a iOS project? , things above are for macos

Not sure if this helps, but what worked for me was sort of indicated above: In Visual Studio, for my Xamarin.iOS project, the settings under Build -> Compiler -> Platform target was set t x86, which resulted in that skiasharp build issue.I changed that to Any CPU, did a clean and rebuild, and it worked!

For the record, this fixed the problem for me too. Was having exact same issue.

@comfr3ak see attached screenshots
Screenshot 2020-06-13 at 19 03 17
Screenshot 2020-06-13 at 19 04 19

Any body? , if I downgrade to Xamarin.iOS 13.16 it works, 13.18 & 13.20 fail

I also found that I had to remove the <PlatformTarget> elements from the iOS project file. For some reason, if this exists - and it might be x86/x64 - then the compiler suddenly thinks it is building for Windows. iOS does not use it anyway, it is AOT'ed.

I have no < PlatformTarget> elements in the ios project file.

Try adding one wit AnyCPU as a value? I haven't seen this error recently, which means nothing...

Adding the PlatformTarget tag with AnyCPU as a value doesn't work for me. My iOS .csproj file did not have any PlatformTarget prior to that.

It's fine on my machine, because it got the right framework. Automated builds are broken on AppCenter for my app because it insists on downloading the win-64 version. When I look at References in Visual Studio 2019 on my machine it doesn't show SkiaSharp, it shows the path to the DLL like this:

C:\Users\me\.nugetpackages\skiasharp\2.80.1\build\xamarinios1.0\libSkiaSharp.framework

Instead of the name of the reference like it does for every other package.

Just started seeing this again on all the latest bits. 馃槩

I might have to start adding warnings in my targets to catch this. Not sure what other issues this will cause...

Xamarin on iOS is just broke - I am actually buying a PC again just to get my work done, it's a total joke.

Was this page helpful?
0 / 5 - 0 ratings