ILMerge SkiaSharp?

I tried to build class library for Xamarin.iOS and use SkiaSharp internally. I used ILMerge to merge SkiaSharp with my dll, but the final dll does not work for some reason. I get the following exception.

{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 }

Here is the command I used to merge dll

ILMerge.exe /log:C:\Temp\merge.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

Any suggestions?

Best Answer

  • AlexNoskAlexNosk UA
    Accepted Answer

    Matthew, thank you for your attention to my problem. 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

  • mattleibowmattleibow Xamurai ZAXamarin Team Xamurai

    I think this may be possible, however there may be other ways. What are you trying to achieve exactly? The linker and the compiler will probably merge everything anyway.

    To see what has changed, we will need the detailed build logs for the app with separate assemblies and then again for the merged assembly. For some reason, the native library is not being managed correctly. It may not be included in the merged assembly.

  • AlexNoskAlexNosk UAMember

    Matthew, thank you for your answer. I posted more details and steps to reproduce the problem on stackoverflow
    https://stackoverflow.com/questions/45275372/dllnotfoundexception-is-thrown-after-ilmerge-skiasharp-into-my-xamarin-ios-dll

  • mattleibowmattleibow Xamurai ZAXamarin Team Xamurai

    Are you able to share build logs? I think it may just be an issue with the resources not being preserved during the merge.

  • AlexNoskAlexNosk UAMember
    Accepted Answer

    Matthew, thank you for your attention to my problem. 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

  • mattleibowmattleibow Xamurai ZAXamarin Team Xamurai

    Ah, that makes sense.

Sign In or Register to comment.