Note: This tutorial assumes that you have completed the previous tutorials: Installation - ROS Development Environment. |
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. |
Creating Android Packages
Description: Script wizards for conveniently creating android packages and projects.Keywords: rosjava android
Tutorial Level: BEGINNER
NOTE: Creating Android projects from the command line won't be supported with Build tools > 25.0.2. The tool supporting this command in Android's SDK has been officially deprecated, so to start a new project Android Studio has to be used. |
Overview
Use the catkin_create_rosjava_xx scripts to populate android packages and subprojects.
Note that your source repository for a new android studio/sdk workspace is simply a gradle multi-project workspace. Here we set up the package with the root gradle multi-project configuration with minimal catkin information (via package.xml), and the actual android project(s) underneath this.
Preparation
You will need a ros environment for your android installation to use these scripts.
Package Creation
Create an empty workspace and populate it with many gradle files!
> mkdir -p ~/myandroid/src > cd ~/myandroid/src # Create a package called android_foo that depends on android_core, rosjava_core, std_msgs > catkin_create_android_pkg android_foo android_core rosjava_core std_msgs # Note: the following steps rely on a deprecated command in Android Build Tools > 25.0.2 > cd android_foo > catkin_create_android_project -t 10 -p com.github.ros_java.android_foo.bar bar > catkin_create_android_library_project -t 13 -p com.github.ros_java.android_foo.barlib barlib > cd ../.. > catkin_make
Be sure to choose a unique package name. Also revise the min and target sdk versions in each individual project's build.gradle file.
Note: This way of creating packages relies on commands provided by Android Build Tools that have been deprecated since version 25.3.1. You can manage Build Tools version from Android Studio from Tools --> Android --> Sdk Manager --> SDK Tools tab. Select Android SDK Build-Tools and check Show Package Details at the bottom of the menu. Another option is to downgrade the build tools manually downloading v 25.2.5 and replacing the folder $ANDROID_HOME/tools with its contents.
The current recommended workaround is to create an Android package using the command line, and populate it with a copy of https://github.com/rosjava/android_core/android_tutorial_pubsub. Then, remove what you don't need from that example (it's almost empty) and start building your app on top of it.
Adding Dependencies
Each individual android subproject's build.gradle file needs to be populated with the dependencies you need for your application.
Internal Dependencies
Dependencies to subprojects in the same android_foo package can be added to bar's build.gradle:
... dependencies { //add dependency linking to subproject barlib compile project(':barlib') } ...
External Dependencies
Dependencies on an external Maven repository (locally on the PC or on a server) can be added to bar and barlib's build.gradle as follows:
... repositories { maven { url 'https://github.com/me/myjava_mvn_repo/raw/master' } } dependencies { // some artifacts do not need a maven repo set - these can be found // from the official maven repos defined by the ros-android gradle plugin. compile('org.ros.android_core:android_10:[0.3, 0.4)') { exclude group: 'junit' exclude group: 'xml-apis' } // this might be found in the maven repo listed above compile 'com.github.me.lovely.lady:[1.2,1.3)' } ...