Chapter 5 Building and Running a Hello World Example with C/C++ or Java

This section will guide you through the steps required to successfully run an rtiddsgen-generated example application written in C/C++ or Java on an Android target, as an Android App (*.apk).

Note that the C and C++ Android App examples use a Java wrapper class with JNI. It is also possible to write pure C and C++ native code to build Android Apps; see the Android documentation for details (https://developer.android.com/tools/sdk/ndk/index.html).

  1. Compile the generated C/C++ or Java code. The auto-generated makefile will create the executables HelloWorld_publisher and HelloWorld_subscriber in the objs/<arch>/ directory for C/C++, or it will generate Java code and archive it into HelloWorld.jar. You should link with libc++_shared.so.
  2. See Chapter 4 Generating Example Code and a Makefile from IDL regarding the ANDROID_ PACKAGE_PREFIX variable; if you want to change this variable in the makefile, do so now.
  3. Create shared libraries (*.so) and build the Android projects with the resulting shared libraries. For example (all on one line):
  4. make -f makefile_HelloWorld_arm64Android12clang12.0.8ndkr23b
        HelloWorld.so

    The above command will do the following:

    • Generate separate shared libraries for the publisher and subscriber examples.
    • Generate separate JNI source code files for both the publisher and subscriber.
    • Compile and link the JNI code into separate JNI shared libraries, one for the publisher and one for the subscriber.
  5. Create the .apk files that will contain the applications. By running the following command, you will build an APK for the publisher and an APK for the publisher. These APKs will be used later to deploy the Apps:
    make -f makefile_HelloWorld_arm64Android12clang12.0.8ndkr23b HelloWorld.apks
  6. Install (via adb) the two Apps on a connected consumer device or an emulator.

    For example (all on one line):

    make -f makefile_HelloWorld_arm64Android12clang12.0.8ndkr23b
      HelloWorld.installapks
  7. Run the example on an emulator with a GUI (i.e., not started with the –no-window flag) or on a consumer device:
      1. Navigate to the Apps screen displaying icons, it should show HelloWorld_publisher and HelloWorld_subscriber.

      1. Touch (on a device) or click (on an emulator) the HelloWorld_subscriber icon.
      2. Optionally, enter a single number for the DDS Domain ID as a parameter.
      3. Touch or click Run.

      1. Navigate to the Apps icons (via the Home button) and launch HelloWorld_publisher.
      2. Optionally, for parameters, enter the DDS Domain ID (use the same ID you entered for the subscriber) as the first number. Optionally, you can enter the number of samples to be published as the second parameter.
      3. Touch or click Run.

      1. Navigate to the Apps icons and return to HelloWorld_subscriber. Note the samples received.

  1. An Android App will continue to run in the background when the focus is given to another App. How to stop a running Android App without uninstalling it depends on the device or the virtual device within the emulator. For example, on the emulator hold the Home button until a list of applications is shown. Stop an App by swiping it left or right. For example, on a Nexus 7 tablet, touch the Recent Apps button (a soft key with an overlapping rectangle) and swipe the App you want to stop. Alternatively, open Settings, choose Apps, in the subheadings swipe to Running, select Show cached processes, and lastly touch and Stop the App.

On an emulator, press the Home button to see a list of running Apps.

Touch the desired App, then select 'Remove from list'.

  1. If you want to see DDS log messages or values of the samples being printed on the subscriber, run adb logcat with a filter from a host machine shell. For example:
  2. adb logcat -v tag RTIConnextLog:I *:S
  3. Uninstall (via adb) the two Apps on the connected consumer device or emulator. For example (all on one line):
  4. make -f makefile_HelloWorld_arm64Android12clang12.0.8ndkr23b
       HelloWorld.uninstallapks