我有二进制文件和所有已解析的 Qt 依赖项,它们都打包在 tar.gz 中。我正在使用下一个 yaml 文件进行 snap:
name: sample_name_lol_1
base: core18
version: '1.0.0'
summary: sample_summary_lol_2
description: |
sample_desc_lol_3
grade: devel
confinement: devmode
parts:
sample_name_lol_1:
plugin: dump
source: MyApp.tar.gz
stage-packages: [
ffmpeg,
x264,
x265,
libopencv-core-dev,
libopencv-imgproc-dev,
libopencv-calib3d-dev,
libblas-dev,
liblapack-dev,
libfontconfig1-dev,
fonts-freefont-ttf,
ttf-ubuntu-font-family
]
apps:
MyApp:
command: MyApp
environment:
LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/usr/lib/x86_64-linux-gnu/blas:$SNAP/usr/lib/x86_64-linux-gnu/lapack
常规应用程序运行(例如从常规解压 tar.gz)将为我提供有关系统上所有可用字体的信息。但是 snap run(sample_name_lol_1.MyApp)看不到系统字体,只有少数字体(准确地说只有 3 种 - sans、sans-serif、等宽字体)。安装后,我找到了路径 /snap/sample_name_lol_1/x1/usr/share/fonts 和 /snap/sample_name_lol_1/x1/etc/fonts。这些位置是只读的,我不知道到底应该怎么做,这样 Qt 应用程序才能看到至少标准的 Ubuntu 字体。
答案1
我必须使用 snap 创建的用户配置文件夹。
- 创建包装器并用作主应用程序。包装器将调用实际应用程序。
- 在启动应用程序之前,包装器将把文件从
$SNAP/etc/fonts/fonts.conf
复制到$SNAP_USER_DATA/.config/fontconfig/fonts.conf
。 - 此外,应用程序将使用“sed -i”命令修改新复制的文件,其中目录已更改为 $SNAP 位置。例如:
<dir>/usr/fonts
... 将变为<dir>/snap/your_app/version/
...
这似乎不是一个干净的解决方案,但是对于我来说这是一个可以接受的解决方案。
name: sample_name
base: core18
version: '1.0.0'
summary: Sample Summary
description: |
Sample Desc
grade: devel
confinement: devmode
parts:
sample_name:
plugin: dump
source: sample_name.tar.gz
stage-packages: [
ffmpeg,
x264,
x265,
libopencv-core-dev,
libopencv-imgproc-dev,
libopencv-calib3d-dev,
libblas-dev,
liblapack-dev,
ttf-ubuntu-font-family
]
fix-fontconfig:
plugin: nil
override-build: |
mkdir $SNAPCRAFT_PART_INSTALL/bin
echo "mkdir \$SNAP_USER_DATA/.config" >> $SNAPCRAFT_PART_INSTALL/bin/sample-wrapper.sh
echo "mkdir \$SNAP_USER_DATA/.config/fontconfig" >> $SNAPCRAFT_PART_INSTALL/bin/sample-wrapper.sh
echo "cp \$SNAP/etc/fonts/fonts.conf \$SNAP_USER_DATA/.config/fontconfig/fonts.conf" >> $SNAPCRAFT_PART_INSTALL/bin/sample-wrapper.sh
echo "sed -i \"s#<dir>/usr#<dir>\$SNAP/usr#g\" \$SNAP_USER_DATA/.config/fontconfig/fonts.conf" >> $SNAPCRAFT_PART_INSTALL/bin/sample-wrapper.sh
echo "\$SNAP/sample_name" >> $SNAPCRAFT_PART_INSTALL/bin/sample-wrapper.sh
after: [sample_name]
apps:
sample_name:
command: sh $SNAP/bin/sample-wrapper.sh
environment:
LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/usr/lib/x86_64-linux-gnu/blas:$SNAP/usr/lib/x86_64-linux-gnu/lapack