SkiaSharp3.116.1部署到Linux不工作,提示libSkiaSharp.so找不到的解决办法
问题:
项目在Windows下工作一切正常,发布Linux 64版本,部署到Ubuntu 24.04后,控制台看到错误提示:libSkiaSharp.so找不到。
解决方案:
Nuget安装下面的包即可解决,SkiaSharp.NativeAssets.Linux.NoDependecies
Visual studio 2019下操作路径:
菜单:工具-》Nuget包管理器-》管理解决方案的NuGet程序包
搜索SkiaSharp即可以看到,安装后,发布项目就会看到,已发布文件夹下有libSkiaSharp.so这个文件。
直接复制libSkiaSharp.so到已部署项目根目录使用也可以解决问题。
20250401更新
将.NET 升级到9.0.3后,出现以下问题:
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
An unhandled exception has occurred while executing the request.
System.TypeInitializationException: The type initializer for 'SkiaSharp.SKAbstractManagedStream' threw an exception.
---> System.DllNotFoundException: Unable to load shared library 'libSkiaSharp' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable:
libfontconfig.so.1: cannot open shared object file: No such file or directory
/usr/lib/dotnet/shared/Microsoft.NETCore.App/9.0.3/libSkiaSharp.so: cannot open shared object file: No such file or directory
/home/ubuntu/BKTBlogCore/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
/usr/lib/dotnet/shared/Microsoft.NETCore.App/9.0.3/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
/home/ubuntu/BKTBlogCore/libSkiaSharp: cannot open shared object file: No such file or directory
/usr/lib/dotnet/shared/Microsoft.NETCore.App/9.0.3/libSkiaSharp: cannot open shared object file: No such file or directory
/home/ubuntu/BKTBlogCore/liblibSkiaSharp: cannot open shared object file: No such file or directory
/usr/lib/dotnet/shared/Microsoft.NETCore.App/9.0.3/liblibSkiaSharp: cannot open shared object file: No such file or directory
解决办法:
sudo apt-get update
sudo apt-get install -y libfontconfig1 libfreetype6 libpng16-16 libjpeg-turbo8 libglib2.0-0
单安装libfongconfig1不能解决问题。干脆将依赖全安装了就好了。
复制libSkiaSharp.so到 /usr/lib/dotnet/shared/Microsoft.NETCore.App/9.0.3/libSkiaSharp.so,没有作用,不需要。后来好了以后,我删除了也一样不影响。