Build from the command line

From AsteroidOS
Revision as of 15:02, 22 January 2026 by Beroset (talk | contribs) (→‎Tips and tricks: added section on examining an ipk file and added header to prev section)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This page describes how to build an app from the command line other than by using bitbake. As described in Creating an Asteroid app, the preferred method for building an app is to set up and use bitbake. However, if you are a beginner and want to try a lower resource method for building, this page documents how to do so from the command line. The other relatively low resource method is to Build with QtCreator.

Prerequisites

To build an app from the command line using this method you should:

  1. Have the SDK installed
  2. Be familiar with CMake and C++

It is technically possible, but not generally recommended to create new AsteroidOS applications in languages other than C++ and with build tools other than CMake.

Building from the command line

Generally, to build a CMake project from the command line, use this:

export CMAKE_PROGRAM_PATH=/usr/local/oecore-x86_64/sysroots/armv7vehf-neon-oe-linux-gnueabi/usr/bin/
source /usr/local/oecore-x86_64/environment-setup-armv7vehf-neon-oe-linux-gnueabi
cmake -B build
cmake --build build

If you're building for the Emulator, use this instead:

export CMAKE_PROGRAM_PATH=/usr/local/oecore-x86_64/sysroots/core2-32-oe-linux/usr/bin
source /usr/local/oecore-x86_64/environment-setup-core2-32-oe-linux
cmake -B build
cmake --build build

Example project

A example project, asteroid-helloworld is available as both an example and a template for new software. To fetch it from git and build it, use the following:

git clone https://github.com/AsteroidOS/asteroid-helloworld.git
cd asteroid-helloworld
export CMAKE_PROGRAM_PATH=/usr/local/oecore-x86_64/sysroots/armv7vehf-neon-oe-linux-gnueabi/usr/bin/
source /usr/local/oecore-x86_64/environment-setup-armv7vehf-neon-oe-linux-gnueabi
cmake -B build -DCMAKE_INSTALL_PREFIX:PATH=/usr
cmake --build build --target package

If everything was successful, you should now have a new library named asteroid-helloworld.so in the build directory. You should also have an .ipk file in the build directory. If the watch is connected via USB to the host computer, you can copy this to the watch and then install it with:

scp build/asteroid-helloworld*.ipk root@192.168.2.15:.
ssh root@192.168.2.15 "opkg install asteroid-helloworld*.ipk"

Note that we specify the CMAKE_INSTALL_PREFIX in the commands above. This is to assure that the package is built to install the software in /usr/lib/ rather than /usr/local/lib/ which would otherwise be the default. The --target package instructs CMake to build a package the .ipk file in our case.

Once the software is installed, it should show up as the last item on the launcher page. Pressing the icon should show an orange background with the words "Hello World!" in white. You should make sure all of this works before going further with development.

You can start by modifying occurrences of "asteroid-helloworld" to your app's name. Then you can change the *.desktop file which describes the icon on the apps launcher. Then modify main.qml to describe your UI. To get started with QML development you can read the official tutorial.

Translations

Within the AsteroidOS project, we use Qt Linguist and Weblate to enable Translating AsteroidOS and applications within it. If you're starting on "my-cool-project", you may want to add some language translations to it. This is done using the lupdate tool. Because Qt5 is nearing the end of support and Qt6 has been out for a while, the tool is named lupdate-qt5 to differentiate between the two tools on most Linux distributions.

Example: Let's say that you want to start with English, French, Spanish, German and Italian translations. You will have to create them before they can be translated. To do this, within your top level my-cool-project directory, execute the following command line code:

for lang in en fr es de it
do
  lupdate-qt5 -no-obsolete src/* i18n/*.h -ts i18n/my-cool-project.${lang}.ts
done

This creates a .ts file for each of those language within the i18n directory.

Once they are created, you or others who know the languages may use Qt Linguist to actually translate the strings. Note that AsteroidOS uses the id based translation mechanism which uses qsTrId rather than qsTr.

Qt and therefore AsteroidOS also supports national language variants, so if you want to create the Argentinian Spanish version or the Great Britain English version those would be named es_AR and en_GB respectively.

Updating language translation files

Once they are created, to update language translation files, and assuming you have all source files in src and translation files in i18n (which is short for "internationalization"), you can use this command to update the files.

lupdate-qt5 -no-obsolete src/* i18n/*.h -ts i18n/*.ts

Tips and tricks

Running your app

If you want to start your app from the command line, open a shell with SSH, connect to ceres and use the shell script which, in turn, calls invoker:

QT_QPA_PLATFORM=wayland asteroid-stopwatch

Or more generally, call invoker directly: QT_QPA_PLATFORM=wayland invoker --single-instance --type=qtcomponents-qt5 /usr/lib/asteroid-stopwatch.so

If you want to disable screen locking for easier development you can enable the demo mode of mce as root with:

mcetool -D on

Don't forget to turn it back off when you are done to avoid draining the battery.

Examining an .ipk file

On systems that have it, one can use opkg-cl or ipkg-deb to examine, extract or modify .ipk files. Without those, one can simply use ar and tar. Examples:

ar t path/to/package.ipk            # show members
ar x path/to/package.ipk control.tar.gz data.tar.gz
tar --zstd -tf data.tar.zst                # list files from package payload
tar --zstd -xf data.tar.zst -C /tmp/pkg-extract   # extract payload

We can also use one-liners to manipulate just the part of the .ipk file that contains data files (the package payload):

ar p path/to/package.ipk data.tar.zst | tar -tv --zstd    # show data files
ar p path/to/package.ipk data.tar.zst | tar -xv --zstd    # extract data files

Debugging

Debugging is described in detail in Debugging Applications