Treasure
This example aims to show how to integrate various features into a working application, including translations, icons, user interface files, settings and resources.
The application can be built in two ways:
- Using the Meson build system. This enables the application to be installed on the user's system, either in a standard location or in a custom installation directory.
- Using Flatpak to create a package for installation locally or for publication in a repository.
Build dependencies
The build process requires various tools and libraries to be installed on the development system. For Debian-based systems, such as PureOS, install the required packages using this command:
sudo apt install gnome-devel meson
If you also want to create flatpaks for distribution and installation, install the relevant packages for building and testing:
sudo apt install flatpak flatpak-builder
The following sections describe building the application using Meson and creating flatpaks.
Building using Meson
The application can be configured using the Meson and Ninja build systems.
To configure the build, run meson
and specify the source and build
directories, in this case from within the application directory itself,
and optionally pass an installation prefix with the --prefix
command line
option:
meson . _build
# or, for example
meson --prefix /tmp . _build
Build the application using ninja
, passing the build directory as an
argument so that the build occurs within that directory:
ninja -C _build
The default rule is to build the application.
Finally, install the application to either a standard location or to the
location specified if the --prefix
option was passed to meson
earlier:
ninja -C _build install
Installing to a standard system location will generally require sudo
to be
used.
Creating a flatpak package
Assuming that you have already installed flatpak
and flatpak-builder
,
you can build a package for the Treasure application in the following way.
Ensure that you have added the gnome-nightly repository to those available on your system:
flatpak remote-add --if-not-exists gnome-nightly https://sdk.gnome.org/gnome-nightly.flatpakrepo
Then install the latest org.gnome.Platform
and org.gnome.Sdk
runtimes from the repository:
flatpak install gnome-nightly org.gnome.Platform
flatpak install gnome-nightly org.gnome.Sdk
Quick build
A quick way to build a package to test:
flatpak-builder --repo=myrepo --force-clean _flatpak com.example.treasure.json
flatpak build-bundle myrepo treasure.flatpak com.example.treasure
flatpak install --user treasure.flatpak
flatpak run com.example.treasure
More detailed build
A more detailed build process can be performed by following the guide in the Flatpak documentation.
We build a package in a temporary _flatpak
directory and run it to test
that it works:
flatpak-builder _flatpak com.example.treasure.json
flatpak-builder --run _flatpak/ com.example.treasure.json treasure
Next, we install the application in a local repository for testing:
flatpak-builder --repo=myrepo --force-clean _flatpak com.example.treasure.json
flatpak --user remote-add --no-gpg-verify my-tutorial-repo myrepo
flatpak --user install my-tutorial-repo com.example.treasure
flatpak run com.example.treasure
The application can be extracted from the repository as a single-file-bundle if required, and installed in this way:
flatpak build-bundle myrepo treasure.flatpak com.example.treasure
flatpak install --user treasure.flatpak
Finally, when no longer required, the application can be uninstalled:
flatpak uninstall com.example.treasure
The local repository can also be deleted:
flatpak remote-delete my-tutorial-repo