From 1329887a23fcdfcfb0002a3e5671a4c0d128e22c Mon Sep 17 00:00:00 2001 From: kneep Date: Mon, 11 Oct 2021 21:10:42 +0800 Subject: [PATCH] Add android support config (#396) Signed-off-by: Joel Cao Co-authored-by: Joel Cao (cherry picked from commit 967e7ad8e0993312d0c92eb4ff8fe28a9a243d70) --- README.md | 9 +++ config/android/dev_ros2_packages.txt | 9 +++ config/android/dev_uros_packages.repos | 1 + config/android/generic/build.sh | 61 +++++++++++++++++++ config/android/generic/client-colcon.meta | 49 +++++++++++++++ .../generic/client_uros_packages.repos | 52 ++++++++++++++++ config/android/generic/create.sh | 11 ++++ config/android/generic/flash.sh | 2 + config/android/generic/package.xml | 12 ++++ 9 files changed, 206 insertions(+) create mode 100644 config/android/dev_ros2_packages.txt create mode 100644 config/android/dev_uros_packages.repos create mode 100755 config/android/generic/build.sh create mode 100644 config/android/generic/client-colcon.meta create mode 100644 config/android/generic/client_uros_packages.repos create mode 100755 config/android/generic/create.sh create mode 100755 config/android/generic/flash.sh create mode 100644 config/android/generic/package.xml diff --git a/README.md b/README.md index c571d2c0..fdee5112 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ This package is the **official build system for micro-ROS**. It provides tools a | [Mbed](https://os.mbed.com/) | [ST B-L475E-IOT01A](https://os.mbed.com/platforms/ST-Discovery-L475E-IOT01A/) | v6.6 | `mbed disco_l475vg_iot01a` | | - | Static library (.a) and headers (.h) 3 | - | `generate_lib` | | Linux | *Host 2* | Ubuntu 18.04/20.04 | `host` | +| Android | [AOSP](https://source.android.com) 4 | Latest | `android generic` | *1 Community supported, may have lack of official support* @@ -44,6 +45,8 @@ This package is the **official build system for micro-ROS**. It provides tools a *3 a valid CMake toolchain with custom crosscompilation definition is required* +*4 Community supported, may have lack of official support* + ## Standalone build system tools micro-ROS also offers some other ways to crosscompile it for different platforms. These other options are secondary tools and may not have full support for all features. Currently micro-ROS is also available as: @@ -75,6 +78,12 @@ Some other prerequisites needed for building a firmware using this package are: ``` sudo apt install python3-rosdep ``` + +Building for Android needs [Latest Android NDK](https://developer.android.com/ndk/downloads) to be installed and the following environment variables to be set: +- ```ANDROID_ABI```: CPU variant, refer [here](https://developer.android.com/ndk/guides/abis) for details. +- ```ANDROID_NATIVE_API_LEVEL```: Android platform version, refer [here](https://developer.android.com/ndk/guides/cmake#android_native_api_level) for details. +- ```ANDROID_NDK```: root path of the installed NDK. + # Quick start Download [here](https://www.eprosima.com/index.php/downloads-all) the micro-ROS docker image that contains a pre-installed client and agent as well as some compiled examples. diff --git a/config/android/dev_ros2_packages.txt b/config/android/dev_ros2_packages.txt new file mode 100644 index 00000000..c04d6a17 --- /dev/null +++ b/config/android/dev_ros2_packages.txt @@ -0,0 +1,9 @@ +keep: + ament/ament_cmake + ament/ament_index + ament/ament_lint + ament/ament_package + ament/googletest + ament/osrf_pycommon + ament/uncrustify_vendor + ros2/ament_cmake_ros diff --git a/config/android/dev_uros_packages.repos b/config/android/dev_uros_packages.repos new file mode 100644 index 00000000..56f46b6f --- /dev/null +++ b/config/android/dev_uros_packages.repos @@ -0,0 +1 @@ +repositories: diff --git a/config/android/generic/build.sh b/config/android/generic/build.sh new file mode 100755 index 00000000..57941308 --- /dev/null +++ b/config/android/generic/build.sh @@ -0,0 +1,61 @@ +. $PREFIX/config/utils.sh + +if [ $# -ge 1 ]; then + TOOLCHAIN=$1 +else + echo "Syntax: ros2 run micro_ros_setup build_firmware.sh [Colcon meta file]" + exit 1 +fi + +if [ $# -ge 2 ]; then + COLCON_META=$2 + echo "Using provided meta: $COLCON_META" + +else + COLCON_META=$FW_TARGETDIR/mcu_ws/colcon.meta + echo "Using default meta: $COLCON_META" +fi + + +BUILD_DIR=$FW_TARGETDIR/build + +pushd $FW_TARGETDIR/mcu_ws >/dev/null + +# Set these variables according to your own environment. +if [ -z ${ANDROID_ABI+x} ]; then + ANDROID_ABI=arm64-v8a +fi +if [ -z ${ANDROID_NATIVE_API_LEVEL+x} ]; then + ANDROID_NATIVE_API_LEVEL=android-30 +fi +if [ -z ${ANDROID_NDK+x} ]; then + ANDROID_NDK=~/android-ndk-r23 +fi + +# rm -rf build install log + +colcon build --packages-up-to micro_ros_demos_rclc \ + --merge-install \ + --packages-ignore-regex=.*_cpp \ + --metas $COLCON_META \ + --cmake-args \ + "--no-warn-unused-cli" \ + -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=OFF \ + -DBUILD_SHARED_LIBS=ON \ + -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \ + -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \ + -DANDROID_FUNCTION_LEVEL_LINKING=OFF \ + -DANDROID_NATIVE_API_LEVEL=${ANDROID_NATIVE_API_LEVEL} \ + -DANDROID_STL=c++_shared \ + -DANDROID_ABI=${ANDROID_ABI} \ + -DANDROID_NDK=${ANDROID_NDK} \ + -DANDROID=ON \ + -DTHIRDPARTY=ON \ + -DBUILD_TESTING=OFF \ + -DBUILD_MEMORY_TOOLS=OFF \ + -DBUILD_MEMORY_TESTS=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON + +popd >/dev/null + diff --git a/config/android/generic/client-colcon.meta b/config/android/generic/client-colcon.meta new file mode 100644 index 00000000..50a94a56 --- /dev/null +++ b/config/android/generic/client-colcon.meta @@ -0,0 +1,49 @@ +{ + "names":{ + "microxrcedds_client":{ + "cmake-args":[ + "-DBUILD_SHARED_LIBS=ON", + "-DUCLIENT_PROFILE_MULTITHREAD=ON" + ] + }, + "microcdr":{ + "cmake-args":[ + "-DBUILD_SHARED_LIBS=ON" + ] + }, + "rosidl_typesupport_microxrcedds_c":{ + "cmake-args":[ + "-DBUILD_SHARED_LIBS=ON" + ] + }, + "rosidl_typesupport_microxrcedds_cpp":{ + "cmake-args":[ + "-DBUILD_SHARED_LIBS=ON" + ] + }, + "rclc_parameter":{ + "cmake-args":[ + "-DBUILD_SHARED_LIBS=ON" + ] + }, + "rcutils":{ + "cmake-args":[ + "-DENABLE_TESTING=OFF" + ] + }, + "rmw_microxrcedds":{ + "cmake-args":[ + "-DRMW_UXRCE_TRANSPORT=udp", + "-DRMW_UXRCE_DEFAULT_UDP_IP=127.0.0.1", + "-DRMW_UXRCE_DEFAULT_UDP_PORT=8888", + "-DRMW_UXRCE_MAX_NODES=15", + "-DRMW_UXRCE_MAX_PUBLISHERS=15", + "-DRMW_UXRCE_MAX_SUBSCRIPTIONS=15", + "-DRMW_UXRCE_MAX_SERVICES=15", + "-DRMW_UXRCE_MAX_CLIENTS=15", + "-DRMW_UXRCE_STREAM_HISTORY=32", + "-DRMW_UXRCE_MAX_HISTORY=10" + ] + } + } +} diff --git a/config/android/generic/client_uros_packages.repos b/config/android/generic/client_uros_packages.repos new file mode 100644 index 00000000..2be1f888 --- /dev/null +++ b/config/android/generic/client_uros_packages.repos @@ -0,0 +1,52 @@ +repositories: + eProsima/Micro-CDR: + type: git + url: https://github.com/eProsima/Micro-CDR.git + version: foxy + eProsima/Micro-XRCE-DDS-Client: + type: git + url: https://github.com/eProsima/Micro-XRCE-DDS-Client.git + version: foxy + +# MicroROS + uros/rcl: + type: git + url: https://github.com/micro-ROS/rcl + version: galactic + uros/rclc: + type: git + url: https://github.com/ros2/rclc + version: galactic + uros/micro_ros_utilities: + type: git + url: https://github.com/micro-ROS/micro_ros_utilities + version: main + version: galactic + uros/rcutils: + type: git + url: https://github.com/micro-ROS/rcutils + version: galactic + uros/micro_ros_msgs: + type: git + url: https://github.com/micro-ROS/micro_ros_msgs.git + version: galactic + uros/rmw_microxrcedds: + type: git + url: https://github.com/micro-ROS/rmw-microxrcedds.git + version: galactic + uros/rosidl_typesupport: + type: git + url: https://github.com/micro-ROS/rosidl_typesupport.git + version: galactic + uros/rosidl_typesupport_microxrcedds: + type: git + url: https://github.com/micro-ROS/rosidl_typesupport_microxrcedds.git + version: galactic + uros/tracetools: + type: git + url: https://gitlab.com/micro-ROS/ros_tracing/ros2_tracing.git/ + version: galactic + uros/micro-ROS-demos: + type: git + url: https://github.com/micro-ROS/micro-ROS-demos.git + version: galactic diff --git a/config/android/generic/create.sh b/config/android/generic/create.sh new file mode 100755 index 00000000..a94d7a67 --- /dev/null +++ b/config/android/generic/create.sh @@ -0,0 +1,11 @@ +pushd $FW_TARGETDIR >/dev/null + + # ignore broken packages + touch mcu_ws/ros2/rcl_logging/rcl_logging_log4cxx/COLCON_IGNORE + touch mcu_ws/ros2/rcl_logging/rcl_logging_spdlog/COLCON_IGNORE + touch mcu_ws/ros2/rcl/COLCON_IGNORE + touch mcu_ws/ros2/rosidl/rosidl_typesupport_introspection_cpp/COLCON_IGNORE + touch mcu_ws/uros/rcl/rcl_yaml_param_parser/COLCON_IGNORE + touch mcu_ws/uros/rclc/rclc_examples/COLCON_IGNORE + +popd >/dev/null diff --git a/config/android/generic/flash.sh b/config/android/generic/flash.sh new file mode 100755 index 00000000..5cfcdf5b --- /dev/null +++ b/config/android/generic/flash.sh @@ -0,0 +1,2 @@ +echo "No flash step" +echo "Please find library and includes inside firmware/build folder" \ No newline at end of file diff --git a/config/android/generic/package.xml b/config/android/generic/package.xml new file mode 100644 index 00000000..2e8fc221 --- /dev/null +++ b/config/android/generic/package.xml @@ -0,0 +1,12 @@ + + + + firmware + 0.0.0 + Micro-ROS dependecies for Android + Joel Cao + APL2 + + gperf + wget +