依赖#

Flatpak为应用程序如何依赖于其他软件提供了许多不同的选项。在首次开始使用Flatpak构建应用程序时,因此有必要决定如何组织应用程序依赖关系。

此页面概括了这些选项是什么和在何时使用他们。

运行时#

基本概念 中描述的,运行时提供了应用可以使用的基本依赖。他们提供了应用的运行环境。Flatpack要求每个应用需要指明一个运行时。因此,用Flatpack构建一个应用最先要确定的就是,应用要使用什么运行时。

我们可以在 可用的运行时 页面找到可用运行时的概览。有意地,只有少量运行时可供选择。通常,运行时是根据应用程序所需的依赖项来选择的。如果存在一个提供您计划使用的库的运行时,这通常是正确的运行时!

小技巧

运行时需要定期维护,应用程序开发人员通常不应该考虑创建自己的运行时。

Runtimes are automatically installed for users when they install an application, and build tools can also automatically install them for you (flatpak-builder’s --install-deps-from option is useful for this). However, if you do need to manually install your chosen runtime, this can be done in the same way as installing an application, with the flatpak install command. For example, the command to install the GNOME 43 runtime is:

$ flatpak install flathub org.gnome.Platform//43

构建#

Flatpak的关键优势之一是它允许应用程序作者捆绑任何他们想要的库或依赖。这意味着开发人员不受某些库只在特定Linux发行版可用的约束。

当首次构建应用的时候,你需要确定绑定哪些依赖。这包括:

  • 所选运行时不包含的库

  • 所选运行时库的另一版本

  • 打了补丁的库

  • 作为应用一部分的数据或者资源

可以看到,作为构建过程的一部分,捆绑的依赖关系可以自动下载。开发者也可以对他们打补丁,或者作其他的更改。

虽然捆绑非常强大和灵活,但它也给应用程序开发人员带来了更大的维护负担。因此,尽管可以尽可能多地进行打包,但通常建议尽量减少打包模块的数量。如果依赖项作为运行时的一部分并是可用的,通常最好使用该版本,而不是自己打包。

如何捆绑库的细节在 mainifests 可以找到。

框架应用#

Runtimes and bundling are the two main ways in which dependencies are handled with Flatpak. They allow applications to rely on stable collections of dependencies on the one hand, and to have flexibility and control on the other.

可是,在某些情况下,依赖是一个更大的框架或者工具集,它不适合放进运行时,但手工捆绑成一系列单独的模块也很麻烦。所以有了 base apps

Base apps contain collections of bundled dependencies which can then be bundled as part of an application. They don’t get rebuilt as part of the build process, which makes building faster (particularly when bundling large dependencies). And because each base app is only built once, it is guaranteed to be identical wherever it is used, so it will only be saved once on disk.

base apps是一个相对专业的概念,只有一些应用需要使用他们(最常用的base app是用于 Electron applications )。但是,如果你的应用使用一个巨大的,复杂的或者专用的框架,在开始构建的时候检查是否有可用的base apps是一个好主意。

Extensions#

Runtimes and applications can define extension points which allow optional additional runtimes to be mounted at a specified location inside the sandbox when they are present on the system. Typical uses for extensions include translations for applications, debuginfo for sdks, or adding more functionality to the application. Some software refers to these extensions as “Add-ons”.

For an extension to be loaded in the application or runtime, an extension point first needs to be defined in the application or runtime in question.

By convention, extension points follow the ID of the application or runtime in question, followed by a generic term for the extension. For example, the OBS Studio flatpak may define an extension point com.obsproject.Studio.Plugin, where “Plugin” is the generic term prefixed by the application ID.

To see available extension points, it’s best to look at the application or runtime manifest.

Any extension now choosing to be loaded inside the OBS Studio flatpak must prefix their ID by com.obsproject.Studio.Plugin for example com.obsproject.Studio.Plugin.Gstreamer.

Some extension names having special significance are discussed below.

  • .Debug is used for Debug extensions by applications, runtimes and SDKs. They are used for debugging purposes. Every application or runtime built with flatpak-builder produces a .Debug extension unless specifically disabled in the manifest.

    A .Debug extension will be needed when generating useful backtraces. This is explained more in 调试.

  • .Locale is used for Locale extensions by applications or runtimes. They add support for more languages to the parent application or runtime. These are usually partially downloaded by flatpak based on the configured system locale. Every application or runtime built with flatpak-builder produces a .Locale extension unless specifically disabled in the manifest.

  • .Sources is used for Sources extension by application or runtime. They are used to bundle sources of the modules used in the application or runtime in question. flatpak-builder will produce a .Sources extension prefixed by ID when --bundle-sources is used.

Please visit Extensions for a guide on how to create extension points and extensions.