SkiaSharp
SkiaSharp copied to clipboard
[QUESTION] Unable to load shared library 'libSkiaSharp' or one of its dependencies.
Deploying my dot.net 5 app with skiasharp with docker on linux, with this in my docker file:
FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine AS final
...
RUN apk add --no-cache icu-libs fontconfig curl
Build on thuesday (April 12, 2022) works fine. Build next day causes container to build and run but with runtime error:
The type initializer for 'SkiaSharp.SKData' threw an exception. Unable to load shared library 'libSkiaSharp'
or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment
variable: Error loading shared library liblibSkiaSharp: No such file or directory
I can only assume that my apk add
is now installing new versions.
- Anyone else having this issue?
- Anyone already found the cause?
- What bould be a future proof way of installing the correct libraries?
Thanks!
Before arriving at above conclusion I used these references settings, none of them worked:
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.1" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.1" />
<PackageReference Include="SkiaSharp" Version="2.80.2" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.2" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.2" />
<PackageReference Include="SkiaSharp" Version="2.80.3" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.3" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.3" />
It looks like a change inFROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine AS final
is the culprit. It was last updated April 12: docker hub
It installed a new version of icu-libs
but I don't know if that causes the SkiaSharp exception.
For now I am fixing the runner image to FROM mcr.microsoft.com/dotnet/aspnet:5.0.15-alpine3.14 AS final
as this seems to be the version before last (according to the history)
hit the same issue today with aspnet:6 tho
You should not have both SkiaSharp.NativeAssets.Linux
and SkiaSharp.NativeAssets.Linux.NoDependencies
installed as they both have the same dlls, but different builds.
If you just use SkiaSharp.NativeAssets.Linux.NoDependencies
does it not work?
Often it is because there is a missing fontconfig. Maybe it was installed on older docker images but is now removed?
If you just use SkiaSharp.NativeAssets.Linux.NoDependencies does it not work?
sadly but it doesn't work :(
I'm using mcr.microsoft.com/dotnet/aspnet:6.0
and Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.3"
and it throws the same error.
And if you do readelf -d libSkiaSharp.so
on the libSkiaSharp.so, what dependencies is it missing?
Strange but it doesn't have the linux variant @mattleibow

oh? That is very interesting. It is in the package:
Do you not have some code somewhere that might exclude this?
Can you get a binlog of the build? That might show some more info as to why it left the building.
Nevermind I had a condition when referencing the package and this condition was wrong so I ended up with no package for linux.
So are we all good?
We good, it works, thanks for the help anyway :)
Nevermind I had a condition when referencing the package and this condition was wrong so I ended up with no package for linux.
What was the issue? I am trying to build/run an app using SkiaSharp + GTK# on linux as well, and getting the missing libSkiaSharp as well. The .dll (managed) and the .so are both in my /bin/debug/. I tried both the nativeAssets packages (with/without dependencies) with same results each time, and also with either package...
I am building in MonoDevelop on Ubuntu 22.04
"Unable to load library 'libSkiaSharp'."
at SkiaSharp.LibraryLoader.LoadLocalLibrary[T] (System.String libraryName) [0x0001b] in D:\a\1\s\binding\Binding.Shared\LibraryLoader.cs:32
at SkiaSharp.SkiaApi+<>c.<.cctor>b__1831_0 () [0x00000] in D:\a\1\s\binding\Binding\SkiaApi.cs:15
at System.Lazy`1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) [0x00043] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.Lazy`1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) [0x00022] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.Lazy`1[T].CreateValue () [0x00074] in <de882a77e7c14f8ba5d298093dde82b2>:0
at System.Lazy`1[T].get_Value () [0x0000a] in <de882a77e7c14f8ba5d298093dde82b2>:0
at SkiaSharp.SkiaApi.GetSymbol[T] (System.String name) [0x00000] in D:\a\1\s\binding\Binding\SkiaApi.cs:18
at SkiaSharp.SkiaApi.sk_picture_recorder_new () [0x00000] in D:\a\1\s\binding\Binding\SkiaApi.generated.cs:8954
at SkiaSharp.SKPictureRecorder..ctor () [0x00000] in D:\a\1\s\binding\Binding\SKPictureRecorder.cs:13
at Svg.Skia.SkiaModelExtensions.ToSKPicture (ShimSkiaSharp.SKPicture picture) [0x00011] in /_/src/Svg.Skia/SkiaModelExtensions.cs:930
at Svg.Skia.SKSvg.Load (System.IO.Stream stream) [0x0002d] in /_/src/Svg.Skia/SKSvg.cs:56
at Mapsui.UI.Forms.MapView..ctor () [0x00326] in <cb19876efc2b46dd9ea868b9137c89fc>:0
at Xforms.Linux.Demo.MapView..ctor () [0x00000] in /Xforms.Linux.Demo/Xforms.Linux.Demo/MapView.cs:11
at Xforms.Linux.Demo.App..ctor () [0x0000f] in /Xforms.Linux.Demo/App.xaml.cs:14
at Xforms.Linux.Demo.Gtk.Program.Main (System.String[] args) [0x0000e] in /Xforms.Linux.Demo.Gtk/Program.cs:16
Add Package SkiaSharp.NativeAssets.Linux or SkiaSharp.NativeAssets.Linux.NoDependencies.
I think the key here is the "or" because installing both packages results in 2 native binaries - and the build selects a random one and you get lucky.
Otherwise, for most general distros/flavors of linux, the packages should be working fine. Usually the OS installs the fontconfig files, but you can confirm by running:
readelf -d libSkiaSharp.so
If you have fontconfig or don't mind installing/depending on it, you can use the SkiaSharp.NativeAssets.Linux
package.
If you don't have/want to install fontconfig, you need to use the SkiaSharp.NativeAssets.Linux.NoDependencies
package instead.
I am closing this issue as I believe the issue is resolved. However, if this is still happening on linux, please open a new issue with specific details of the version of SkiaSharp, the version and distro of the linux used and any other dotnet and sdk versions related.