Compile from Source File for Flatpak
~2 minutes read
Compiling from Source File for Flatpak.
First, we need to install flatpak-builder
: sudo apt install flatpak-builder
Then, the steps will be:
- Create a metainfo file (xml): This file will give additional information regarding the bundled application (such as name, version, released date, etc.).
- Create a manifest file (yml): This file will give information about the build instructions.
The Metainfo File
<?xml version="1.0" encoding="UTF-8"?>
<component type="runtime">
<id>org.freedesktop.Sdk.Extension.{{my_extension_name}}</id>
<metadata_license>CC0-1.0</metadata_license>
<name>{{my_extension_name}} Sdk extension</name>
<summary>{{my_extension_name}} packages and tools</summary>
<project_license>AGPL-3.0-only</project_license>
<url type="homepage">https://github.com/developer/{{packagename}}-downloads/releases</url>
<developer id="@user@example.org">{{developer_name}}
<name>{{developer_name}}</name>
</developer>
<releases>
<release version="11.08.2" date="2025-10-13" />
</releases>
</component>
Here above is a small metainfo file example. For the full list of tags that can be used, check the AppStream catalog metadata on freedesktop.org.
Note: The quality of the metainfo file is as important as the manifest file since warnings or errors can prevent the build process from being successful. Check the Flatpak MetaInfo guidelines.
The Manifest File
id: org.freedesktop.Sdk.Extension.{{my_extension_name}}
branch: '24.08'
runtime: org.freedesktop.Sdk
build-extension: true
sdk: org.freedesktop.Sdk
runtime-version: '24.08'
sdk-extensions: []
separate-locales: false
appstream-compose: false
build-options:
prefix: /usr/lib/sdk/{{my_extension_name}}
modules:
- name: {{my_extension_name}}
sources:
- type: archive
url: https://github.com/developer/{{packagename}}-downloads/releases/download/{{xyz/package-11.08.2.tar.gz}}
sha256: {{insert_sha256_hash_for_the_package}}
- name: appdata
buildsystem: simple
build-commands:
- mkdir -p ${FLATPAK_DEST}/share/metainfo
- cp ${FLATPAK_ID}.metainfo.xml ${FLATPAK_DEST}/share/metainfo
- appstreamcli compose --components=${FLATPAK_ID} --prefix=/ --origin=${FLATPAK_ID} --result-root=${FLATPAK_DEST} --data-dir=${FLATPAK_DEST}/share/app-info/xmls ${FLATPAK_DEST}
sources:
- type: file
path: org.freedesktop.Sdk.Extension.{{my_extension_name}}.metainfo.xml
Next, we can compile the application with: flatpak-builder ./{{my_extension_name}}-build org.freedesktop.Sdk.Extension.{{my_extension_name}}.yml
Then, start the installation with: `$ flatpak-builder --user --install --force-clean ./{{my_extension_name}}-build org.freedesktop.Sdk.Extension.{{my_extension_name}}.yml
Finally, to make the new Flatpak bundle available to a program, we need to edit the environment variables of the program and include the new bundle name.
FLATPAK_ENABLE_SDK_EXT=my_extension_name
Resources
- MetaInfo guidelines (docs.flathub.org)
- Catalog Metadata (freedesktop.org)
- How do I set the version string of my flatpak application? (StackOverflow)
- Manifests (docs.flathub.org)