|
|
| (4 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| [[Category:Developers]] | | [[Category:Developers]] |
| Creating an AsteroidOS app can be fun and rewarding. Creating an app requires the installation of the Software Development Kit (SDK) as described in [[Installing the SDK]]. The rest of this page assumes that you already have the SDK installed. | | Creating an AsteroidOS app can be fun and rewarding. Creating an app requires the installation of the Software Development Kit (SDK) as described in [[Installing the SDK]] and/or installing the entire bitbake environment as described in [[Building AsteroidOS]]. Note that the process of creating a watchface is a different (and somewhat easier) process documented in [[Creating a Watchface]]. Many new users start by customizing an existing watchface before graduating to creating their own watchfaces and perhaps ultimately creating their own apps. |
|
| |
|
| = Building from the command line = | | === Build methods === |
| Generally, to build a CMake project from the command line, use this:
| | There are three ways that developers create or modify applications: |
|
| |
|
| <pre> | | # [[OpenEmbedded|Build with <code>devtool</code> or <code>bitbake</code>]] ('''recommended''') |
| export CMAKE_PROGRAM_PATH=/usr/local/oecore-x86_64/sysroots/armv7vehf-neon-oe-linux-gnueabi/usr/bin/
| | # [[Build from the command line]] |
| source /usr/local/oecore-x86_64/environment-setup-armv7vehf-neon-oe-linux-gnueabi
| | # [[Build with QtCreator]] |
| cmake -B build
| |
| cmake --build build
| |
| </pre>
| |
|
| |
|
| If you're building for the [[Emulator]], use this instead:
| | What AsteroidOS developers use is <code>devtool</code> and <code>bitbake</code>, but setting up the entire <code>bitbake</code> environment can be somewhat daunting to beginners and building the entire AsteroidOS uses a lot of resources (time, memory and disk space). The other two methods are a quick and low-resource (in terms of time, memory and disk space required) ways to begin, but have limitations. For this reason, it's recommended to move to using <code>bitbake</code> as soon as practical to avoid these limitations and their corresponding frustrations. |
| <pre> | |
| 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
| |
| </pre> | |
|
| |
|
| == Example project == | | {| class="wikitable" |
| A example project, asteroid-helloworld is available as both an example and a template for new software. To fetch it from <code>git</code> and build it, use the following:
| | |+ Build method table |
| | |- |
| | ! Method !! Advantages !! Drawbacks |
| | |- |
| | | command line || simple, fast, easy to set up || doesn't always create <code>.ipk</code> file, doesn't automatically handle dependencies |
| | |- |
| | | QtCreator || good for GUI development || difficult to set up, doesn't create <code>.ipk</code> file |
| | |- |
| | | <code>devtool</code> || creates <code>.ipk</code> file, correctly handles dependencies || relatively complex to set up, can be slow to compile |
| | |} |
|
| |
|
| <pre> | | Having a properly constructed <code>.ipk</code> file not only allows simplified installation on the watch, but also includes dependencies (other libraries on which the code might depend). All of the <code>.ipk</code> files on our [https://release.asteroidos.org/nightlies/ipk/ nightly builds] are created using the OpenEmbedded tool <code>bitbake</code>. |
| 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
| |
| </pre> | |
|
| |
|
| If everything was successful, you should now have a new library named <code>asteroid-helloworld.so</code> in the <code>build</code> directory. You should also have an <code>.ipk</code> 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:
| | The command-line version build of <code>asteroid-helloworld</code> creates a simple installable <code>.ipk</code> file by adding build instructions for that directly to the [https://github.com/AsteroidOS/asteroid-helloworld/blob/a3908a7c7d13491b189ca4c0767c43ed24ce0271/CMakeLists.txt#L31C1-L45C15 CMakeLists.txt file]. This works as a temporary fix, but is generally '''not''' done for AsteroidOS projects because it would interfere with the way <code>bitbake</code> builds and because it does not automatically include dependencies, as mentioned above. |
| | |
| <pre>
| |
| scp build/asteroid-helloworld*.ipk root@192.168.2.15:.
| |
| ssh root@192.168.2.15 "opkg install asteroid-helloworld*.ipk"
| |
| </pre> | |
| | |
| Note that we specify the <code>CMAKE_INSTALL_PREFIX</code> in the commands above. This is to assure that the package is built to install the software in <code>/usr/lib/</code> rather than <code>/usr/local/lib/</code> which would otherwise be the default. The <code>--target package</code> instructs CMake to build a package the <code>.ipk</code> 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.
| |
| | |
| = Using QtCreator =
| |
| | |
| QtCreator is an integrated development environment for making Qt QML applications. Previous versions of QtCreator allowed the use of passwords on the watch, but more recent versions require using SSH certificates. For this reason, the first thing to do is to prepare the watch to allow logging in using certificates.
| |
| | |
| ==Prepare the watch to use certificates==
| |
| By default, there are two configured users on the watch: <code>root</code> and <code>ceres</code> both without passwords. The first step in deploying is to set up passwords for both users. This can be done by logging into the watch as each user and then running the <code>passwd</code> command to change the password. Remember each password because they will be needed later.
| |
| | |
| The next step is to modify the <code>/etc/ssh/sshd_config</code> file on the watch. The two settings to modify are:
| |
| | |
| <pre>
| |
| PubkeyAuthentication yes
| |
| PermitEmptyPasswords no
| |
| </pre>
| |
| | |
| Once this is done, log out and then try to log back in via <code>ssh</code>. You should be asked for the password. If so, then type in the password you just set and verify that things work.
| |
| | |
| The next step is to generate and copy a public key from your Linux computer to the watch. Although this can, in theory, be done from within QtCreator, doing so can be difficult to debug if things don't work perfectly. For that reason, this guide will only describe the command-line method.
| |
| | |
| First generate a key pair *on the host Linux computer* if there isn't already one there. This is typically done by running <code>ssh-keygen</code>. Different kinds of keys may be generated, but this example assumes an RSA key is generated. Once the key pair is created, you can deploy the public key to the watch:
| |
| | |
| <pre>
| |
| ssh-copy-id -i ~/.ssh/id_rsa.pub ceres@192.168.2.15
| |
| </pre>
| |
| | |
| ==Install additional packages==
| |
| Two other software packages must be installed on the watch for QtCreator's "Test" to pass. They are <code>base64</code> and <code>rsync</code>. The <code>base64</code> software is part of the <code>coreutils</code> package and can be installed with this command as the <code>root</code> user on the watch:
| |
| | |
| <pre>
| |
| opkg install coreutils
| |
| </pre>
| |
| | |
| The <code>rsync</code> package is, at this time, not built as part of the packages, and so it must be built using <code>bitbake</code> as described [[https://wiki.asteroidos.org/index.php/Building_AsteroidOS]]. Instead of <code>bitbake asteroid-image</code>, one can just build the <code>rsync</code> package with <code>bitbake rsync</code>.
| |
| | |
| ==Configure QtCreator for cross compilation==
| |
| | |
| Before running QtCreator you must run the previously mentioned script and set up the <code>CMAKE_PROGRAM_PATH</code>.
| |
| | |
| <pre>
| |
| 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
| |
| qtcreator
| |
| </pre>
| |
| | |
| This can be done automatically by prepending <code>source /usr/local/oecore-x86_64/environment-setup-armv7vehf-neon-oe-linux-gnueabi</code> and the export command before <code>#!/bin/sh</code> in <code>/usr/bin/qtcreator.sh</code>
| |
| | |
| Now that you are in QtCreator go to <code>Edit</code> → <code>Preferences</code> → <code>Devices</code>
| |
| | |
| <ul>
| |
| <li>Add a new Remote Linux Device</li>
| |
| <li>Name it "AsteroidOS Watch"</li>
| |
| <li>Choose 192.168.2.15 as IP address</li>
| |
| <li>Choose 22 as the port</li>
| |
| <li>Use ceres as user</li>
| |
| </ul>
| |
| <br>
| |
| Under the <code>Kits</code> add a kit with the previously defined device:
| |
| <ul>
| |
| <li>Set <code>Device type</code> to Remote Linux Device</li>
| |
| <li>Set the <code>Device</code> to AsteroidOS Watch</li>
| |
| <li>Set the sysroot to <code>/usr/local/oecore-x86_64/sysroots/armv7vehf-neon-oe-linux-gnueabi/</code></li>
| |
| <li>In the CMake generator change the <code>Generator</code> to <code>Unix Makefiles</code></li>
| |
| <li>Change <code>Qt version</code> to <code>None</code></li>
| |
| <li>Change <code>C</code> compiler to <code><No compiler></code></li>
| |
| <li>Change <code>C++</code> compiler to <code><No compiler></code></li>
| |
| <li>Change <code>CMake Tool</code> to "AsteroidOS CMake" at <code>/usr/local/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/bin/cmake</code></li>
| |
| <li>Clear the <code>CMake Configuration</code> fields</li><li>Add a CMake variable: </li>
| |
| </ul><code>OE_QMAKE_PATH_EXTERNAL_HOST_BINS:STRING=%{Env:OE_QMAKE_PATH_HOST_BINS}</code>
| |
| | |
| Note that if these steps are not done *in this order*, QtCreator will not let you change both the <code>C</code> compiler and <code>C++</code> compiler to <code><No compiler></code>. Specifically, setting Qt version to <code>None</code> must be done first.
| |
| | |
| = First app=
| |
| | |
| [https://github.com/AsteroidOS/asteroid-helloworld Asteroid-helloworld] can act as a cool QML demo app to make your first steps into AsteroidOS development easier. You can clone it, build it, install it and then modify it to follow your needs: | |
| | |
| <pre>
| |
| git clone https://github.com/AsteroidOS/asteroid-helloworld
| |
| 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
| |
| qtcreator CMakeLists.txt
| |
| </pre>
| |
| | |
| Try to build and deploy the app. If it wasn’t already installed, a new icon should have already appeared on asteroid-launcher.
| |
| | |
| 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 [http://doc.qt.io/qt-5/qml-tutorial.html official tutorial].
| |
| | |
| ==Deploy an app from QtCreator==
| |
| | |
| Open the project as described in the previous sections.
| |
| <ul>
| |
| <li>Click on the <code>Projects</code> button on the left sidebar</li>
| |
| <li>Under the <code>Build & Run</code> section click on the <code>Run</code> configuration. This opens all run settings</li>
| |
| <li>Scroll down to the <code>Run</code> settings</li>
| |
| </ul>
| |
| | |
| | |
| Change the following <code>Run</code> settings:
| |
| <ul>
| |
| <li>Set the <code>Run configuration</code> to <code>Custom Executable (on AsteroidOS Watch)</code></li>
| |
| <li>Under "Files to deploy" select "Override deployment data from build system"</li>
| |
| <li>Set the <code>Remote executable</code> to <code>asteroid-helloworld</code><br></li></ul>Under <code>Environment</code> select "Fetch Device Environment"
| |
| <ul>
| |
| <li>Change <code>XDG_RUNTIME_DIR</code> and set its value to <code>/run/user/1000</code>. So that the invoker works under the root user</li>
| |
| <li>Add <code>QT_QPA_PLATFORM</code> and set its value to <code>wayland</code></li>
| |
| <li>(Optional) Add <code>QT_WAYLAND_DISABLE_WINDOWDECORATION</code> with value <code>1</code>to make the app full screen and hide the titlebar</li>
| |
| </ul>
| |
| Your app should now be able to run from the application when you click the start button in the bottom left sidebar. Make sure you have the display on to be able to see the app. If you have "Tap-to-wake" turned on in the "Display" settings on the watch, tapping the display to wake up the screen before running the application should work.
| |
| | |
| =Tips and tricks=
| |
| | |
| 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:
| |
| | |
| <code>
| |
| asteroid-stopwatch
| |
| </code>
| |
| | |
| If you want to disable screen locking for easier development you can enable the demo mode of mce as root with:
| |
| | |
| <code>
| |
| mcetool -D on
| |
| </code>
| |
| | |
| Don't forget to turn it back off when you are done to avoid draining the battery.
| |
| =Troubleshooting=
| |
| | |
| The most common problems stem from not following these directions *exactly*. QtCreator helpfully tries to find compilers and set variables, but tends to set things up for the desktop as the target rather than AsteroidOS, so it often gets things wrong. The first step for troubleshooting with QtCreator is to go very carefully over each of the steps listed above and verify that they all match exactly.
| |
| | |
| ==Could not find a package configuration file provided by "ECM" ==
| |
| | |
| This is most often caused not having the environment variables set up as shown above under the topic of [[#Configure QtCreator for cross compilation | configuring QtCreator]]. The environment variables must all be set and then you must lauch <code>qtcreator</code> *in the same shell*. If you're not sure you've done this, an easy way to check is to try this command from the command line:
| |
| | |
| <code> | |
| echo $CC
| |
| </code> | |
| | |
| This should result in a line like this:
| |
| <code>
| |
| arm-oe-linux-gnueabi-gcc -march=armv7ve -mfpu=neon -mfloat-abi=hard --sysroot=/usr/local/oecore-x86_64/sysroots/armv7vehf-neon-oe-linux-gnueabi
| |
| </code>
| |
| | |
| If instead you get an empty line or some other non-ARM compiler, you may have made an error. One common error is to run the script directly instead of running it using <code>source</code> (or <code>.</code> on some Linux distributions). Another common error that causes the error about not finding ECM is if, in the Kit, the system CMake is used instead of the one for the AsteroidOS SDK.
| |
| | |
| = warning: The project contains C++ source files, but the currently active kit has no C++ compiler. The code model will not be fully functional.
| |
| | |
| This is not really an error but a warning. It's the result of having correctly chosen <code><No compiler></code> as per the instructions above and may safely be ignored.
| |
| | |
| == file INSTALL cannot find ... .desktop==
| |
| | |
| This is probably the result of a missing <code>CMAKE_PROGRAM_PATH</code>. As mentioned above, this must be set in order for a script that generates the desktop file to be correctly found and uses.
| |
| | |
| ==Remote process crashed==
| |
| | |
| One possibility is that your software has a bug, but another is that the <code>XDG_RUNTIME_DIR</code> is not set to <code>/run/user/1000</code> as mentioned above.
| |
| | |
| =="I fixed it but I get the same error!"==
| |
| | |
| This most often happens when something was originally wrong with the configuration, but a CMake scan was made and a possibly faulty Makefile from an earlier attempt still exists. To fix this, choose <code>Build</code> from the menu, and then <code>Rescan project</code>. This will run CMake again, ignoring existing cached values and forcing the recreation of a Makefile.
| |