To create a built-in native app, you must write the source code and prepare the required configuration files.
For easier understanding, the process to create a built-in native app is explained using a sample app in Sample Code Repository. The sample app has the following features:
Displays a “Hello, Native Qt Application!!” message on screen.
Line(7) : Set the surface type of MyOpenGLWindow to OpenGLSurface. The type can be OpenGLSurface or RasterGLSurface.
ServiceRequest.h
Define a class that can register to luna-service2 and call registerApp method of System and Application Manager (SAM). This header file has the function declaration.
Line(3~18) : Create pbnjson utility functions, which convert String to Json and Json to String based on pbnjson library. pbnjson is a JSON engine, implemented as a pair of libraries with APIs for easier C and C++ abstraction.
Line(20~38) : Define constructor and destructor of ServiceRequest class.
Line(40~69) : Define functions to register and unregister com.example.app.nativeqt to and from luna-service. For more details about luna-service functions, see the luna-service2 Library API Reference.
Line(71~112) : Implement the callback function of registerApp.
Line(82~85) : When the app first calls the method, the value of event in response is “registered”.
Line(86~100) : When the app is already running and SAM’s launch method is called, the value of event comes up as “relaunch”.
Line(89~92) : Call the showFullScreen function to change the app’s state from background to foreground.
Line(94~99) : If the user gives a parameter of params when calling launch, the app can get the value of params with the property “parameters” in response.
Line(101~104) : When the app is closed by SAM’s closeByAppId method, the value of event comes up as “close”.
Line(114~135) : Call the registerApp method of SAM.
Line(1) : Include MyOpenGLWindow.h header file which has OpenGLSurface type window class.
Line(2) : Include ServiceRequest.h header file which has member functions that can call services based on luna-service2.
Line(3~6) : Include Qt header files.
Line(11) : argv[1] holds the value that SAM gives to the native app when the app is first launched. The value passed as “params” in SAM’s launch method call can be received as “parameters”, and the lifecycle “event” of the native app comes up as “launch”.
Line(13~14) : Get the DISPLAY_ID property from the environment variable so that the app can be launched on the display corresponding to the displayAffinity value passed as a launch parameter.
Line(16~20) : Create a MyOpenGLWindow object. Set the window’s size and display the text on the screen.
Line(22~23) : Create a ServiceRequest object and call the registerApp() function.
Line(25~26) : Use QWindow::Handle() to get QPlatformWindow from MyOpenGLWindow. Set “appId” and “displayAffinity” to the window.
Line(28) : Enters the main event loop and waits until exit() is called, then returns the value that was set to exit(): 0 if exit() is called via quit().
This file provides general information of the native app.
Caution
If the README.md file is missing, a build error occurs.
Make sure the ‘Summary’ section is a single line. Even any whitespace at the line above the ‘Description’ section is considered a part of the summary and can cause the build to fail.
Sample README.md
Summary
-------
native app sample
Description
-----------
native app sample
How to Build on Linux
---------------------
## Dependencies
Below are the tools and libraries (and their minimum versions) required to build sample program:
* qmake
## Building
$ cd build-webos
$ source oe-init-build-env
$ bitbake com.example.app.nativeqt
Copyright and License Information
=================================
Unless otherwise specified, all content, including all source code files and
documentation files in this repository are:
Copyright (c) 2020 LG Electronics, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
Step 2: Configure the Native App
This section describes how to prepare the configuration files required to build and test the native app.
appinfo.json
Apps are required to have metadata before they can be packaged. This metadata is stored in a file called appinfo.json, which is used by the webOS device to identify the app, its icon, and other information that is needed to launch the app.
Line(8) : The icon to be shown on the Launchpad and App Bar. Make sure the icon file is available in the project root directory. You can use your own icon.png (80*80) file or attached icon.png.
Line(9) : Specify the group to which the external service’s method called by the app belongs. Because SAM’s registerApp method belongs to “application.operation” group, put “application.operation” in this property. To check the group of each method, use ls-monitor command with “-i” option.
Line(10) : This field is required to use SAM’s registerApp method.
This file specifies the application name and the qmake template to be used for generating the project, as well as the source, header, and UI files included in the project.
TARGET= nativeqt
CONFIG+= qt
QT+= core gui-private
# if you use QT 6.x , you should include opengl. because opengl is not included by default.# but if you use QT 5.x under, opengl is included by default so you do not include opengl.greaterThan(QT_MAJOR_VERSION, 5){QT+= opengl
}CONFIG+= link_pkgconfig
PKGCONFIG+= luna-service2 glib-2.0 pbnjson_cpp PmLogLib
SOURCES+= ServiceRequest.cpp MyOpenGLWindow.cpp main.cpp
HEADERS+= ServiceRequest.h MyOpenGLWindow.h
INSTALL_APPDIR=$${WEBOS_INSTALL_WEBOS_APPLICATIONSDIR}/com.example.app.nativeqt
target.path =$${INSTALL_APPDIR}icon.path =$${INSTALL_APPDIR}icon.files = icon.png
appinfo.path =$${INSTALL_APPDIR}appinfo.files = appinfo.json
INSTALLS+= target icon appinfo
A brief explanation of the above file:
Line(1) : Set TARGET name. It must be an executable file name of the app.
Line(3) : The CONFIG variable is a special variable that ‘qmake’ uses when generating a Makefile. qt is added to the list of existing values contained in CONFIG.
Line(4) : Link against the QtCore Module. Add ‘gui-private’ to use private GUI include directories.
Line(11~12) : ‘qmake’ can configure the build process to make use of external libraries that are supported by pkg-config, such as the luna-service2, glib, pbnjson, and PmLog libraries.
Line(14) : A list of source code files to be used when building the project.
Line(15) : A list of filenames of header (.h) files used when building the project.
Line(17) : Set installed directory on the target board. INSTALL_APPDIR would be /usr/palm/applications/com.example.app.nativeqt on the target.
Line(19~25) : *.files specifies a path in project directory and *.path specifies the path to the file system to be installed on the target.
Line(27) : Add targets, icons, and appinfo files from the INSTALLS list.
After implementing and configuring the native app, you must build the app.
Add the Recipe File
webOS OSE uses OpenEmbedded of Yocto Project to build its components. OpenEmbedded needs a recipe file that configures the build environment. For more details about the recipe, see Yocto Project Reference Manual.
You must move the recipe file into webOS OSE project directory.
Line(6) : Version of the component. For the webOS OSE component, this field is mandatory.
Line(7) : Revision version of the recipe. Each recipe requires a counter to track its modification history. Make sure that you increment the version when you edit the recipe, unless you only change the value of the WEBOS_VERSION field or comments.
Line(9) : A list of a recipe’s build-time dependencies.
Line(11) : Instruct OpenEmbedded to use the WEBOS_VERSION value as the component version number. If you develop your component on a local repository, this entry is required.
Line(12) : Instruct OpenEmbedded that the component uses QMake for configuration, which is the preferred choice for webOS components.
Line(13) : Inherit webos_app, because the component is an app.
Line(14) : For the component that uses pkg-config at build time or installs a pkg-config file (.pc), this entry is required.
Line(16) : Put OE_QMAKE_PATH_HEADERS = "${OE_QMAKE_PATH_QT_HEADERS}" so that Qt header files can be included at compile time.
Line(18) : ${webos_applicationsdir} indicates /usr/palm/applications. ${PN} is the package name, which is set to webos.example.app.nativeqt.
Configure the Local Source Directory
To build a component that is located on the local system, you must specify the directory information.
You must move the configuration file into webOS OSE project directory.
Line(2) : The local source directory. The syntax of the property is EXTERNALSRC:pn-<component>. For the value, input "<absolute path of the project directory>"
Line(3) : The local build directory. The syntax of the property is EXTERNALSRC_BUILD:pn-<component>. For the value, input "<absolute path of the project directory>/build/"
Line(4) : The appended revision version (PR) for building local source files. The syntax of the property is PR:append:pn-<component>. This property is optional.
Note We recommend that you add a trailing slash (/) at the end of all local directory paths, as in Line(2) and Line(3).
Build the App
To build the component on the OpenEmbedded environment, enter the following commands on the shell.
After building the app, you must verify its functionality.
Copy the IPK to the target.
When the build is successful, oe-related directories are created under the project root directory. These directories are linked to the directory where the build output is generated from the actual build-webos sub-directory.
Copy the IPK file to the target device using the scp command.
com.example.app.nativeqt/oe-workdir/deploy-ipks/raspberrypi4_64$ scp com.example.app.nativeqt_1.0.0-r0.local0_raspberrypi4_64.ipk root@<target IP address>:/media/internal/downloads/
Install the app on the target.
Connect to the target using the ssh command and install com.example.app.nativeqt_1.0.0-r0.local0_raspberrypi4_64.ipk.
$ ssh root@<target IP address>
root@raspberrypi4-64:/sysroot/home/root# cd /media/internal/downloads/
root@raspberrypi4-64:/media/internal/downloads# opkg install com.example.app.nativeqt_1.0.0-r0.local0_raspberrypi4_64.ipk
Installing com.example.app.nativeqt (1.0.0) on root.
Configuring com.example.app.nativeqt.
Discover the LS2 configuration files.
To make LS2 daemon scan the LS2 configuration files of the app, use the ls-control command as follows.
root@raspberrypi4-64:/media/internal/downloads# ls-control scan-services
telling hub to reload setting and rescan all directories
Note For the native app, LS2 configuration files are generated during the build process. To run the app properly, you must make the system scan the newly generated configuration files.
Scan the app.
To make System and Application Manager (SAM) scan the app, restart SAM using the systemctl command. This step is required so that the app can be added to the app list, which in turn makes the app appear on the Launchpad.
root@raspberrypi4-64:/# systemctl restart sam
Note Rebooting the target after installing the app will have the same effect as running the ls-control and systemctl commands. However, using the commands allows you to continue testing without rebooting.
Run the native app.
Drag the mouse cursor upward from the bottom of the screen (or swipe up from the bottom of the screen if you’re using a touch display).
Note On webOS OSE 1.x, press the Windows key.
Click the Launchpad icon.
Click the app icon to see the window titled “Native qt app” with the following page: