ILMerge with SkiaSharp.

Hi all,

I have a very weird problem when use ILMerge to merge SkiaSharp.dll into final dll, I get System.DllNotFoundException: @rpath/libSkiaSharp.framework/libSkiaSharp error in runtime.
Here are steps to reproduce:

  1. Create a simple Xamarin.iOS class library and add reference to SkiaSharp.dll.
  2. Add some simple code to use SkiaSharp, for example:

using SkiaSharp;

namespace TestMerge
{
public class TestClass
{
public static void TestMethod(string imageFile)
{
SKBitmap bmp = SKBitmap.Decode(imageFile);
}
}
}

  1. Compile project and then use ILMerge or ILRepack to merge it using the following command

ILMerge.exe /log:C:\Temp\ILMerge.log /internalize /ndebug /targetplatform:v4,"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0" /out:C:\Temp\TestMerge.dll C:\Temp\TestMerge\TestMerge\bin\Debug\TestMerge.dll C:\Temp\TestMerge\TestMerge\bin\Debug\SkiaSharp.dll

Dll is successfully merged.

  1. Create Xamarin.iOS application (I used unit test application) and add reference to the produced dll. make a call to TestMethod, as the result application crashes. The exception is

{System.DllNotFoundException: @rpath/libSkiaSharp.framework/libSkiaSharp
at (wrapper managed-to-native) SkiaSharp.SkiaApi:sk_filestream_new (string)
at SkiaSharp.SKFileStream..ctor (System.String path) [0x00000] in <9d222c42d8aa4f729033b25ddebc012a>:0
at SkiaSharp.SKBitmap.Decode (System.String filename) [0x00011] in <9d222c42d8aa4f729033b25ddebc012a>:0
at TestMerge.TestClass.TestMethod (System.String imageFile) [0x00001] in <9d222c42d8aa4f729033b25ddebc012a>:0
at Tests.Xamarin.Tests.Test001 () [0x00002] in /Users/mac1/Projects/awxamarin/Xamarin.Tests/Tests.Xamarin/Tests.cs:19 }

Any ideas why this occurs and how to resolve this. By the way if do the same for Xamarin.Android everything works fine.

I tried to decompile final dll and libSkiaSharp.framework is there in dll Resources just like in SkiaSharp.dll.

Thank you in advance,
Alexey.

Best Answer

  • AsposeAsposeAsposeAspose US
    Accepted Answer

    I finally get it worked. The solution was simple as always :). To make it work it is required to add the following attribute into the AssemblyInfo.cs of the main class library project:

    [assembly: ObjCRuntime.LinkWith("libSkiaSharp.framework", SmartLink = true)]

    Hope this will be useful for others

Answers

  • AsposeAsposeAsposeAspose USMember
    Accepted Answer

    I finally get it worked. The solution was simple as always :). To make it work it is required to add the following attribute into the AssemblyInfo.cs of the main class library project:

    [assembly: ObjCRuntime.LinkWith("libSkiaSharp.framework", SmartLink = true)]

    Hope this will be useful for others

Sign In or Register to comment.