Packaging the Application¶
The app
directory contains a com.example.simple_weather.json
manifest file for use with Flatpak. This describes where the application
source code can be obtained from, how the application is built, the
dependencies that need to be built with it, and the permissions it needs when
it is run.
Writing the Manifest¶
The manifest for this simple application is short, so we include the whole file here to provide an overview before looking at the details:
{
"app-id": "com.example.simple_weather",
"runtime": "org.gnome.Platform",
"runtime-version": "3.38",
"sdk": "org.gnome.Sdk",
"command": "simple-weather",
"finish-args": [
"--socket=wayland",
"--share=network"
],
"modules": [
{
"name": "python3-setuptools",
"buildsystem": "simple",
"build-commands": [
"pip3 install --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} setuptools"
],
"sources": []
},
{
"name": "python3-setuptools_scm",
"buildsystem": "simple",
"build-commands": [
"pip3 install --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} setuptools_scm"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/ad/d3/e54f8b4cde0f6fb4f231629f570c1a33ded18515411dee6df6fe363d976f/setuptools_scm-4.1.2-py2.py3-none-any.whl",
"sha256": "69258e2eeba5f7ce1ed7a5f109519580fa3578250f8e4d6684859f86d1b15826"
}
]
},
{
"name": "python3-python-dateutil",
"buildsystem": "simple",
"build-commands": [
"pip3 install --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} python-dateutil"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl",
"sha256": "8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl",
"sha256": "75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a"
}
]
},
{
"name": "python3-requests",
"buildsystem": "simple",
"build-commands": [
"pip3 install --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} requests"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/45/1e/0c169c6a5381e241ba7404532c16a21d86ab872c9bed8bdcd4c423954103/requests-2.24.0-py2.py3-none-any.whl",
"sha256": "fe75cc94a9443b9246fc7049224f75604b113c36acb93f87b80ed42c44cbb898"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/56/aa/4ef5aa67a9a62505db124a5cb5262332d1d4153462eb8fd89c9fa41e5d92/urllib3-1.25.11-py2.py3-none-any.whl",
"sha256": "f5321fbe4bf3fefa0efd0bfe7fb14e90909eb62a48ccda331726b4319897dd5e"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl",
"sha256": "fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/5e/c4/6c4fe722df5343c33226f0b4e0bb042e4dc13483228b4718baf286f86d87/certifi-2020.6.20-py2.py3-none-any.whl",
"sha256": "8fc0819f1f30ba15bdb34cceffb9ef04d99f420f68eb75d901e9560b8749fc41"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/a2/38/928ddce2273eaa564f6f50de919327bf3a00f091b5baba8dfa9460f3a8a8/idna-2.10-py2.py3-none-any.whl",
"sha256": "b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"
}
]
},
{
"name" : "libhandy",
"buildsystem" : "meson",
"builddir": true,
"config-opts": [
"-Dglade_catalog=disabled",
"-Dexamples=false",
"-Dtests=false",
"-Dvapi=false"
],
"sources" : [
{
"type" : "git",
"url" : "https://gitlab.gnome.org/GNOME/libhandy/"
}
]
},
{
"name": "simple_weather",
"buildsystem": "meson",
"builddir": true,
"sources": [
{
"type": "dir",
"path": "."
}
]
}
]
}
We examine the three main parts of the manifest individually.
Application Information¶
In the manifest we record information about the application, including its ID and the command used to run it:
{
"app-id": "com.example.simple_weather",
"runtime": "org.gnome.Platform",
"runtime-version": "3.38",
"sdk": "org.gnome.Sdk",
"command": "simple-weather",
The runtime
and runtime-version
values define precisely which
collection of libraries the application needs to run. The corresponding sdk
value tells Flatpak which SDK is needed to build the application. When building
applications for a GNOME-based platform the corresponding SDK is required.
Permissions¶
The finish-args
list is typically used to state which permissions the
application needs. In this case it will need access to the Wayland display
server to be able to show a window:
"finish-args": [
"--socket=wayland",
"--share=network"
],
The applications also requires access to the network. Other permissions will be required if you want to store and modify settings for your application, access peripherals, and perform other tasks that require the user’s consent.
Modules¶
The modules
list describes the application components (or modules),
including any dependencies that need to be bundled with it, in a list of
dictionaries. The application’s module follows the entries for the other dependencies:
"name": "simple_weather",
"buildsystem": "meson",
"builddir": true,
"sources": [
{
"type": "dir",
"path": "."
}
]
The name
of the application should be unique in the list of modules but can
be otherwise freely assigned. We indicate that we are using the Meson build
system and instruct Flatpak to use a separate build directory.
After this, we describe where the sources of the application should be obtained from. For many applications we would describe the location of a repository. However, to make things simple, we indicate that the sources are in the same directory as the manifest.
Building the Application¶
Following the instructions in Cross-Building an Application, we use
flatpak-builder
to build a flatpak for the application. To do this we need
to install the runtime and SDK that the application depends on. These are the
same as those mentioned in Setting up Flatpak for GNOME Development except that we need the
ones for the aarch64 architecture:
flatpak --user install flathub org.gnome.Platform/aarch64/45 org.gnome.Sdk/aarch64/45
After installing these, build the application with flatpak-builder
:
flatpak-builder --arch=aarch64 --repo=myrepo _flatpak com.example.simple_weather.json
The result is stored in the myrepo
directory, which is a local repository.
It can be exported from the repository as a binary bundle for deployment on
the target device. We do this by running flatpak
with the build-bundle
command, passing the repository, the name of the bundle to create and the
application ID:
flatpak build-bundle --arch=aarch64 myrepo app.flatpak com.example.simple_weather
In this case the bundle is written to the app.flatpak
file. This can be
copied to the phone or development board for installation.
Installing the Application¶
One way to install the application is to use the flatpak
tool on the
command line to install the binary bundle. Other more user-friendly ways are
also possible.
First of all, copy the bundle to the target device and make it readable by the
purism
user. Then, log in to the device and ensure that the flathub
remote is registered for the user:
flatpak --user remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
Assuming that the app.flatpak
file is in the current directory, install it
for the user by running the install
command:
flatpak --user install app.flatpak
Flatpak will resolve the dependencies of the bundle using the remote we registered and ask you if you want to install them if they are not already present. It will then install the application itself.
You can run the application using flatpak
in the usual way:
flatpak run com.example.simple_weather
When you are finished with the application and want to uninstall it, use the following command:
flatpak uninstall com.example.simple_weather
You can also uninstall the runtime needed by the application, but it may be useful to keep it installed for future use.