Building and deploying Kanzi Connect applications to embedded devices

Building and deploying Kanzi Connect applications to an Android device

To learn how to set up the Android build environment, in the Kanzi framework documentation see Working with > Android > Requirements.

To learn how to build and deploy your Kanzi Connect application to an Android device, in the Kanzi framework documentation see Working with > Android > Deployment.

Building Kanzi Connect applications from the command line

Before you can build a Kanzi application for your target platforms, you must set up and configure the Kanzi build environment for those platforms. The build environment includes the tools that the Kanzi build system uses to build your application for your target platforms.

On all platforms, Kanzi Connect build scripts rely on the KANZI_HOME and KANZI_CONNECT_SDK system environment variables, which:

  • On Windows, are set by the installation process of Kanzi Connect. See Installing Kanzi Connect on Windows.

  • On Linux, when you build platform linux_x11_glx, you can set with the helper script <KanziConnectInstallation>/SDK/setup_env.sh.

Some platforms also require you to set specific environment variables. For example, Kanzi Connect scripts for building applications for Android require ANDROID_SDK_HOME to be set, while scripts for building for QNX require QNX_HOST to be set.

To learn about the Kanzi build environment, in the Kanzi framework documentation see Working with > Deploying Applications > Deploying Kanzi applications to <target platform>.

Building Kanzi Connect applications using a Python script

To build Kanzi Connect applications using a Python script:

  1. In Kanzi Studio main menu select File > Open Kanzi Command Prompt or open the terminal on Linux.

  2. In the Kanzi Connect SDK directory run the script build_app.py.

    Syntax

    build_app.py [--config [Build configuration]]
                 [--gfx_api [Graphics system API]]
                 [--project-name [Name of module to build]]
                 [--gradle_archs [Gradle architectures to build]]
                 [-jobs [N]]
                 [-v]
                 [--dynamic]
                 <path>
                 <platform>
    

    Parameters

    <path>

    The path to the Application directory of the application that you want to build.

    <platform>

    The platform for which you want to build the application.

    --config

    (Optional) The build configuration type:

    • Release, GL_vs2019_Release_DLL and GL_vs2017_Release_DLL build the application with compiler optimizations enabled. This option builds smaller files than the Debug option. Use this option for production purposes. The default value is GL_vs2019_Release_DLL.

    • Debug, GL_vs2019_Debug_DLL and GL_vs2017_Debug_DLL build the application with disabled compiler optimizations and contains full debug information that you can use with a debugger. This option builds larger files and debug applications run slower. Use this option for development purposes.

    --gfx_api

    (Optional) The graphics system to use:

    • ES3 builds the application with OpenGL ES 3.0

    • GL builds the application with OpenGL

    --project_name

    (Optional) The name of the module to build. Case sensitive.

    --gradle_archs

    (Optional) The Gradle architectures to build. If you pass more than one architecture name, the script sequentially builds all architectures that you select. These architectures are available:

    • arm

    • aarch64

    • x86

    • x86_64

    --jobs

    (Optional) The number of concurrent build jobs. The default is 2.

    -v

    (Optional) Print what the script is doing.

    --dynamic

    (Optional) Build dynamic libraries. For most platforms Kanzi Connect requires dynamically linked libraries. The build scripts by default use static linking. Android ANT workflow and Integrity OS builds use static linking in Kanzi Connect applications.

    Examples

    To build the Cluster example application with the Debug configuration for Android Gradle workflow.

    build_app.py --config Debug examples/Cluster/Application android_gradle
    

    To build the IVI example application with the GL_vs2019_Release_DLL configuration for Windows.

    build_app.py --config GL_vs2019_Release_DLL examples/IVI/Application win64 --dynamic
    

    To build the HUD example application with the Release configuration for QNX 7.0, using the dynamic libraries.

    build_app.py --config Release examples/Cluster/Application qnx700_screen_aarch64 --dynamic
    

    To build the Android Kanzi Connect server with the Release configuration for the Android gradle with the aarch64 eabi.

    build_app.py --config Release examples/Server/Demo/Application android_gradle --gradle_archs arm64-v8a
    

    To build the Kanzi Connect server with the default (Release) configuration for Windows.

    build_app.py sources/Server win64
    

Building Kanzi Connect applications using a Scons script

  1. In Kanzi Studio main menu select File > Open Kanzi Command Prompt or open a terminal on Linux.

  2. In the directory of your Kanzi Connect application configuration directory, run the scons command with the build parameters.

    Syntax

    scons <gfx_api> <type> project_name=<name> <--dynamic>

    Parameters

    gfx_api

    (Optional) The graphics system to use:

    • ES3 builds the application with OpenGL ES 3.0

    • GL builds the application with OpenGL

    type

    (Optional) The build configuration type:

    • Release builds the application with compiler optimizations enabled. The release option builds smaller files than the debug option. Use this option for production purposes. Default value.

    • Debug builds the application with disabled compiler optimizations and contains full debug information you can use with a debugger. The debug option builds larger files and debug applications run slower. Use this option for development purposes.

    name

    (Optional) The name of the module to build. Case sensitive.

    --dynamic

    (Optional) Build dynamic libraries. For most platforms Kanzi Connect requires dynamically linked libraries. The build scripts by default use static linking. Integrity OS build uses static linking in Kanzi Connect applications.

    Examples

    To build an application with the default settings as specified in config.py and SConstruct configuration files.

    scons
    

    To build the Release version of an application with the OpenGL ES 3.0 graphics library.

    scons ES3 Release
    

    To build the Debug version of an application with the OpenGL graphics library and dynamic libraries.

    scons GL Debug --dynamic
    

    Builds the Debug version of an application with the OpenGL ES 2.0 graphics library from the Kanzi Studio project named MyProject.

    scons ES2 Debug project_name=MyProject
    

    Scons builds the Kanzi application source code and binary files in the <ProjectName>/Application/lib directory.

Configuring Kanzi Connect application to connect to a Kanzi Connect Server running on another device

Kanzi Connect applications read the connection parameters from the connection.xml in the working directory of the application. On Windows, if that file is not available, Kanzi Connect creates it automatically. On all the other platforms, the file must be present when a Kanzi Connect application runs.

On Android, when you build a Kanzi Connect application, Kanzi Connect includes in the APK the connection.xml file from the <ProjectName>/Application/bin directory. You can override the settings set by the connection.xml in APK by using another connection.xml file on the Android device. For other platforms, Kanzi Connect uses the configuration files from the application installation directory.

Kanzi Connect applies the parameters you set in the connection.xml file in this order:

  1. The connection.xml on the device storage in the $SECONDARY_STORAGE/Connect directory

  2. The connection.xml on the device SD card in the $EXTERNAL_STORAGE/Connect directory

  3. The connection.xml in the apk file

For example, to configure on Android a Kanzi Connect application to connect to a Kanzi Connect Server which is running on another device:

  1. Create a connection.xml file where you configure the parameters you want your Kanzi Connect application to use.

    For example, in the connection.xml file set the IP address of the computer which is running Kanzi Connect Server to which you want your application to connect.

    <root>
        <connection_adapter>
            <!-- The name by which a Kanzi Connect server recognizes a client -->
            <name>My Kanzi Connect application</name>
            <!-- The Kanzi Connect server provided by this connection adapter -->
            <server_name>Server</server_name>
            <!-- Connection details, bearer name, and its attributes -->
            <bearer>connect.bearer.tcp</bearer>
            <attribute name="host_ip" value="10.20.30.40"/>
            <attribute name="host_port" value="2002"/>
            <attribute name="alt-addresses" value=""/>
            <attribute name="connection_timeout" value="5000"/>
        </connection_adapter>
    </root>
    
  2. Connect your Android device to your computer and set the connection type to Transfer Files.

    This way you can access the device file system with Windows Explorer.

  3. Copy the connection.xml file to your Android device to the Internal Storage/Connect directory. If the directory does not exist, create it.

    When you run your Kanzi Connect application on your Android device, the application uses the parameters you set in the connection.xml file.

Running a Kanzi Connect application

To run a Kanzi Connect application on an embedded device:

  1. Copy the application binary to the target device:

    • During runtime, the application requires Kanzi Connect libraries. Depending on the integration, Kanzi Connect applications can share libraries. If the platform does not allow this, copy the Kanzi Connect libraries to the same directory where the application binary is.

    • The platform library loader must know the location of the library.

      On Windows, the libraries in the application directory are loaded automatically.

      On most Linux-like platforms, you must add the application directory to the loader path. The Kanzi Connect SDK contains the <KanziConnectInstallation>/SDK/build/create_target_device_bundle.sh utility that collects all the libraries and example binaries for an embedded platform supported by Kanzi Connect. Run this script under <KanziConnectInstallation>/SDK.

    • On Windows, it is recommended that you keep the Kanzi Connect directory structure created by the installer. However, you can copy and run a Kanzi Connect server on another computer, but you must maintain the relative locations of these configuration directories:

      • <KanziConnectInstallation>/certs

      • <KanziConnectInstallation>/configs

      • <KanziConnectInstallation>/ContentPack

      • <KanziConnectInstallation>/SDK/lib/win64

      To use the kzb Player, copy all the libraries (*.dll) for the matching kzb Player configuration (<KanziConnectInstallation>/SDK/lib/win64/GL_vs2019_Release_DLL or <KanziConnectInstallation>/SDK/lib/win64/GL_vs2019_Debug_DLL) to the KzbPlayer directory.

      To use the kzb Player, the Kanzi Engine plugins and connection.xml must be in the same directory, like any Kanzi application.

    • Using kzb Player for Kanzi Connect applications on embedded platform is not recommended. Kanzi Connect application template on Kanzi Studio contains platform required adjustments for the Kanzi Connect and Kanzi libraries and avoids the need for advanced troubleshooting.

  2. Start the Kanzi Connect Server on your computer or another device in the subsystem.

  3. Start your Kanzi Connect application on the device to which you deployed the application. On Android device you can launch the application using the device application launcher or adb. On other embedded targets use either shell or a start-up script.