ros android ndk,android_ndk/Tutorials/Building The Example Applications using the Binary Distributio...

本文介绍了如何使用预构建的ROS NDK模块简化Android应用开发过程,包括配置路径、ANT编译和安装测试步骤。通过示例应用展示如何避免繁琐的交叉编译,适合初学者。

Note: This tutorial assumes that you have completed the previous tutorials: building native ROS packages.

6da015a8d37b40830bd0ceda913832f2.png Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Building Sample Application using Binary Distribution

Description: This tutorial presents an example Android application which uses the binary distribution of the cross compiled ROS libraries for Android. It is based on the ANT build system and is intended to serve a starting point for a custom application.

Keywords: Native Activity

Tutorial Level: BEGINNER

Next Tutorial: android_ndk/Tutorials/How to cross-compile any ROS package

Using the Android NDK ROS binary distribution

If you followed the previous tutorial, you must have realized that cross compiling the ROS packages to Android is a very resource and time consuming task. For that reason, the build scripts can generate a stand alone binary distribution of the cross compiled libraries.

This distribution is formed by a single directory which can act as an Android NDK module, that is, a series of libraries which can be set as build dependencies for an Android NDK project.

In this tutorial will use a sample Android Native application configured to use the pre built ROS NDK module.

Prerequisites

Before being able to build the application we need to have the Android development tools installed. We recommend following this rosjava tutorial which explains how to install the required Java software and the Android Studio SDK package.

Using the Android SDK Manager, included in the Android Studio package, make sure that the following items are installed:Android 1.5 (API 3) -> SDK Platform

Android 4.0 (API 14) -> SDK Platform

Tools -> Android SDK Build-Tools 21, (19.1 also works)

Install ant on your system:$ sudo apt-get install ant

You will also need to download the Android NDK. This demo code was tested using the r8e and r10c versions. For a different application, the exact version of the NDK that you need to use will depend on the requirements of your application. After downloading, for newer versions (which are a .bin file) follow the installation instructions. For older versions (.tar.gz), just untar it somewhere.

Get the files

sample_app. Sample app with ANT configuration.

roscpp_android_ndk Android NDK module contains all the cross compiled ROS packages(big download, aprox 600M)

Save both files in the same directory and untar them. Take into account that the NDK module will expand into a 3GB directory.

Modify the paths for your system

We need to modify 3 paths that are specified in two different files in the sample_app directory.

The first two are the location of the NDK binaries and the ROS NDK module. Both things are configured in the custom_rules.xml file. Let's look at one example configuration:1

2

3

4

5

6

7

Line 3 states the path to the ndk-build binary, which will be inside the NDK installation.for example :install ndk from android-stuido 2.2 you can set up as($sdk path)/ndk-bundle/build/ndk-build

Line 4 states the path of the directory that contains the roscpp_android_ndk directory.do not need to add roscpp_android_ndk in it.

The last thing that we need to configure is the path to the Android SDK, which is specified in the local.properties file:(Ignore the warnings in lines 1 to 6)

7 # location of the SDK. This is only used by Ant

8 # For customization when using a Version Control System, please read the

9 # header note.

10 sdk.dir=/opt/sdk

Line 10 should be modified to point to the location where the Android SDK was installed, which may not be necessarily along with the Android Studio package.

Build

After the paths are configured, you just need to compile the app using ANT. Run the following command from inside the sample_app directory.$ ant debug

The resulting APK will be located in the bin directory inside the sample_app directory.

Installing and Testing

To install the new application on a device and test it, please follow the last two steps found in this tutorial

colcon build --packages-select example_topic_rclpy --event-handlers console_direct+ --cmake-args -DCMAKE_VERBOSE_MAKEFILE=ON Starting >>> example_topic_rclpy running egg_info writing ../../build/example_topic_rclpy/example_topic_rclpy.egg-info/PKG-INFO writing dependency_links to ../../build/example_topic_rclpy/example_topic_rclpy.egg-info/dependency_links.txt writing entry points to ../../build/example_topic_rclpy/example_topic_rclpy.egg-info/entry_points.txt writing requirements to ../../build/example_topic_rclpy/example_topic_rclpy.egg-info/requires.txt writing top-level names to ../../build/example_topic_rclpy/example_topic_rclpy.egg-info/top_level.txt reading manifest file '../../build/example_topic_rclpy/example_topic_rclpy.egg-info/SOURCES.txt' writing manifest file '../../build/example_topic_rclpy/example_topic_rclpy.egg-info/SOURCES.txt' running build running build_py running install running install_lib running install_data running install_egg_info removing '/home/syf/dev_ws/install/example_topic_rclpy/lib/python3.10/site-packages/example_topic_rclpy-0.0.0-py3.10.egg-info' (and everything under it) Copying ../../build/example_topic_rclpy/example_topic_rclpy.egg-info to /home/syf/dev_ws/install/example_topic_rclpy/lib/python3.10/site-packages/example_topic_rclpy-0.0.0-py3.10.egg-info running install_scripts Installing see_choice script to /home/syf/dev_ws/install/example_topic_rclpy/lib/example_topic_rclpy writing list of installed files to '/home/syf/dev_ws/build/example_topic_rclpy/install.log' Finished <<< example_topic_rclpy [0.74s] Summary: 1 package finished [0.98s]
最新发布
05-14
<think>嗯,用户遇到了ROS 2中example_topic_rclpy包的构建和运行时错误,具体是AttributeError,提示类型对象没有'_TYPE_SUPPORT'属性。这个问题通常和消息类型支持有关。我需要一步步分析可能的原因,并给出解决方案。 首先,用户提到错误信息中的'_TYPE_SUPPORT'缺失。在ROS 2中,消息类型生成后会自动生成对应的Python模块,其中包含_TYPE_SUPPORT等元数据。如果这些元数据不存在,可能是因为消息没有正确生成或导入。 接下来,我需要考虑消息类型定义是否正确。用户需要检查.msg文件的结构,确保字段类型和名称正确。例如,是否有拼写错误或者不支持的字段类型?比如,在ROS 2中,某些旧的消息类型可能不再适用,需要确认是否使用了正确的语法。 然后是构建过程中的问题。用户是否正确配置了package.xml和CMakeLists.txt?在ROS 2中,使用ament作为构建系统,需要确保在package.xml中添加了必要的依赖,比如rclpy、std_msgs等,并且有<build_depend>和<exec_depend>。同时,CMakeLists.txt应该包含查找依赖和安装指令,比如ament_package(),以及可能的ament_auto_find_build_dependencies(),但具体要看用户使用的构建方式。 另外,工作区是否正确source也是一个关键点。用户可能在构建后没有source install/setup.bash,导致系统找不到新生成的消息类型。这时候,即使生成了消息,如果没有正确source环境变量,节点运行时还是会找不到类型支持。 依赖项的安装也需要验证。用户是否安装了所有必需的ROS 2包?比如,如果消息依赖于其他自定义接口,是否在package.xml中声明,并且这些接口已经正确编译?此外,使用rosdep检查依赖是否安装完全,避免缺少某些包导致生成失败。 还有可能的问题是Python包的路径问题。如果消息生成在Python包的子模块中,用户是否正确导入了消息类型?例如,应该使用from example_topic_rclpy.msg import CustomMessage而不是直接引用顶层模块。 另外,代码中的导入和构造是否正确?在ROS 2中,发布者需要明确指定消息类型和话题名称,比如在创建发布者时使用self.publisher_ = self.create_publisher(CustomMessage, 'topic', 10),这里的CustomMessage必须正确导入,并且其_TYPE_SUPPORT属性存在。 用户可能需要按照步骤逐一检查:首先确认消息文件正确,然后检查构建配置,接着确保工作区已正确构建和source,再验证依赖项,最后检查代码中的导入和使用。如果问题仍然存在,可能需要手动重新编译或清理构建缓存,比如删除build和install目录后重新编译。 总结一下,可能的解决步骤包括:验证消息定义、检查构建配置、正确source工作区、安装依赖、确认代码中的导入,以及清理和重新构建。需要指导用户一步步排查这些方面,确保每个环节都正确无误。</think>在ROS 2中解决`AttributeError: type object 'type' has no attribute '_TYPE_SUPPORT'`错误需要系统性检查消息类型的工作流。以下是分步解决方案: --- ### 一、验证消息类型定义 1. **检查`.msg`文件格式** - 确保消息文件位于`msg/`目录 - 验证字段类型与ROS 2兼容,例如: ```msg # 正确示例 string name int32[] data ``` 2. **检查消息生成状态** ```bash # 在包目录下检查生成结果 ls install/example_topic_rclpy/lib/python3.8/site-packages/example_topic_rclpy/msg ``` 应包含`_<message_name>.py`和`__init__.py`文件 --- ### 二、配置构建系统 1. **package.xml关键配置** ```xml <buildtool_depend>ament_cmake</buildtool_depend> <buildtool_depend>rosidl_default_generators</buildtool_depend> <exec_depend>rosidl_default_runtime</exec_depend> <member_of_group>rosidl_interface_packages</member_of_group> ``` 2. **CMakeLists.txt核心设置** ```cmake find_package(rosidl_default_generators REQUIRED) rosidl_generate_interfaces(${PROJECT_NAME} "msg/CustomMessage.msg" ) ``` --- ### 三、工作区环境配置 1. **完整构建流程** ```bash cd ~/ros2_ws colcon build --symlink-install --packages-select example_topic_rclpy source install/setup.bash # 必须执行此操作 ``` 2. **环境验证** ```bash printenv | grep ROS_PACKAGE_PATH ros2 interface show example_topic_rclpy/msg/CustomMessage ``` --- ### 四、依赖项检查 1. **显式安装接口依赖** ```bash sudo apt install ros-<distro>-rosidl-generator-py ``` 2. **使用rosdep验证** ```bash rosdep check example_topic_rclpy ``` --- ### 五、代码层验证 1. **正确导入消息类型** ```python from example_topic_rclpy.msg import CustomMessage # 必须来自包命名空间 ``` 2. **消息构造规范** ```python msg = CustomMessage() msg.name = "test" ``` --- ### 六、高级调试技巧 1. **强制重建消息** ```bash rm -rf build/ install/ colcon build --force-cmake --packages-select example_topic_rclpy ``` 2. **检查接口支持** ```python print(CustomMessage.__module__) # 应显示example_topic_rclpy.msg ``` --- ### 典型错误场景解析 1. **未激活工作区环境**:未执行`source install/setup.bash`时,Python解释器无法找到消息类型[^1] 2. **跨包依赖缺失**:当消息依赖其他自定义接口时,需在`package.xml`添加`<depend>another_package</depend>` 3. **Python包结构错误**:未在`setup.py`中声明消息模块会导致安装失败 [^1]: ROS 2的包管理系统依赖环境变量定位资源,正确source工作区是类型解析的基础 [^2]: 构建系统配置错误会导致接口文件生成不完整,需严格遵循ROS 2的构建规范 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值