Building ROS 2 enabled Android �apps with C++

Shane Loretz, ROSCon 2022
Android is a trademark of Google LLC.

Overview●Why Android and ROS?
● Comparison with existing projects● How to build Apps with only C++?
● What are the downsides?

Why Android + ROS?

Because Android is useful to Robots

Spot
TabletBostonDynamics

Pepper
SoftBank
Robotics

AstrobeeNASA

Spot image: Web Summit, CC BY 2.0 <https://creativecommons.org/licenses/by/2.0>, via Wikimedia Commons (edited)
Pepper Image: Softbank Robotics Europe, CC BY-SA 4.0 <https://creativecommons.org/licenses/by-sa/4.0>, via Wikimedia Commons (edited)Because Android is useful to Robots

Android is used by●Ast robee t o enable GuestScience apps
● Pepper t o show relevant
informat ion t o users● Spot Tablet t o cont rol Spot
Spot image: Web Summit, CC BY 2.0 <https://creativecommons.org/licenses/by/2.0>, via Wikimedia Commons (edited)
Pepper Image: Softbank Robotics Europe, CC BY-SA 4.0 <https://creativecommons.org/licenses/by-sa/4.0>, via Wikimedia Commons (edited)Comparison withexisting projects

What already exists?
ROS projects usable on AndroidPurpose

ROS 1 orROS 2?

rosjava

Client Library

1

ROS-Mobile-Android

App1

ros2_java(aka rcljava)

Client Library2What already exists?
ROS projects usable on Android
PurposeROS 1 orROS 2?

Cross-compiles ROS
packages?

rosjava

Client Library

1

No

ROS-Mobile-AndroidApp1

No (uses rosjava)

ros2_java(aka rcljava)

Client Library2

Yes (up to rcl)

Sensors for ROS

App

2Everything(No Java or Kotlin)

What is Sensors for ROS?

It’s an Android app that publishes sensor
data to ROS 2 topics.

What is Sensors for ROS?
Supported sensors:●Acceleromet er● Baromet er● Camera(s)● Gyroscope● Illuminance● Magnet omet er

What is Sensors for ROS?
● It uses CMake, C++, and rclcpp● No J ava* or Kot lin!
$ mkdir build$ cd build$ cmake ../ -DANDROID_HOME=/path/to/android-sdk/...
$ make -j`nproc`...

* We won’t writ e any J ava, but we st ill have t oint eract wit h t he J VM.

How to build
Apps with onlyC++?

Android Native Development Kit“The Android NDK is a toolset that lets
you implement parts of your app innative code, using languages such as Cand C++. For certain types of apps, thiscan help you reuse code libraries written
in those languages. “What is an Android App?
●It ’s an .apk
● Zip archive cont aining:○ Compiled code
○ Resources■ App Icon
■ St rings○ A manifest

Steps to make an App
1. Create a manifest
2. Cross-compile code
3. Convert resources
4. Package it into an .apk

1. Creating the manifest
Create the manifest●Hand writ t en
● Describes what ’s in t he app○ Required permissions○ Activity (ies) in t he app

2. Cross-compiling everything
Cross compile everything from source●Anyt hing t hat runs on t he device○ ROS 2 Humble■ rcl_logging_android○ App specific code
● Not cross-compiling build t ool
dependencies

2. Cross-compiling everything
1. Get ROS source code withrosinstall_generator and vcstool
2. Use CMake toolchain provided by NDK

2a. Making a native Activity
An App needs an Activity●Ent ry point for an Android App● Apps have a “main” act ivit y● An Activity is a J ava class2a. Making a native Activity
ANativeActivity●C API provided by Android NDK● Using it requires:○ Creat ing shared library○ Implement ing an “on creat e” funct ion○ Implement ing Activity callbacks

3. Converting resources
Resources●The App icon
● Localized st rings● Use aapt2 t o convert t o Android format

4. Packaging an AppPackaging the .apk
●Creat e folder st ruct ure● Creat e a zip archive● use zipalign on it● sign it wit h apksigner

4. Packaging an AppTools needed to make APKs
●aapt 2● zipalign● apksigner

What are thedownsides?

What are the downsides?
ANativeActivity requires using OpenGL●Can’t use nat ive GUI widget s● Can’t use Android XML UI layout s● Sensors for ROS uses Dear ImGuiWhat are the downsides?
Some APIs aren’t in the NDK●Request ing CAMERA permissions○ Workaround: Call J ava APIs using
J ava Nat ive int erface (J NI)Building ROS 2 enabled Android apps with C++
Diagram text

https://github.com/sloretz/sensors_for_ros
ht t ps:/ / git hub.com/ sloret z/ rcl_logging_android