Show EOL distros:
Expected in hydro.
Android Development Environment
This information is out of date and probably has some issues, but is kept around for posterity. Move to hydro for a cleaner development environment with the new gradle and android studio tools for android. |
This installation procedure is intended for Ubuntu Linux systems. It has been developed and tested on Ubuntu 12.04 (precise) with ROS Groovy. Updates may be needed for other Ubuntu or ROS distributions.
Prerequisites
Before developing with rosjava or the android_core library, both ROS and Android SDK must be installed.
To install ROS, follow the usual instructions, and install at least the following (these packages specifically are needed to get message and service definitions that we'll be using):
$ sudo apt-get install ros-groovy-multimaster-experimental ros-groovy-pr2-power-drivers ros-groovy-turtlebot
Note: you may want to install other ROS packages at this point; specifically any packages that contain messages you want to use in Android apps.
- If you are running with a 64bit machine, these 32bit libs were found necessary to be installed on some machines:
$ sudo apt-get install lib32z1 lib32gcc1 lib32stdc++6 ia32-libs
Install some tools that we'll need:
$ sudo apt-get install -y ant python-pip python-six mercurial git openjdk-6-jre openjdk-6-jdk lib32ncurses5
Note: It appears that you must use openjdk-6, not openjdk-7; using the latter version leads to Java compiler crashes in some cases. Use update-alternatives to see which one you're using:
update-alternatives --config java
You want to see something like:
There is only one alternative in link group java: /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java Nothing to configure.
OrThere are 2 choices for the alternatives java (providing /usr/bin/java).
If you can see the latter line, you should select openjdk-6,so use update-alternatives to choose version 6 (or use apt-get to remove the version 7 packages).
Install rosinstall, which we'll use to retrieve the Java source files:
Ubuntu:
$ sudo apt-get install python-rosinstall
Other Linuxen:
$ sudo pip install --upgrade rosinstall
Install the Android Developer Tools (ADT) bundle. Start here.
Download the ADT bundle; on Linux it's named something like adt-bundle-linux-x86_64.zip
Unpack the ADT bundle, e.g.:
$ unzip adt-bundle-linux-x86_64.zip
Add the sdk/tools and sdk/platform-tools directories to your system PATH, e.g.:
$ export PATH=`pwd`/adt-bundle-linux-x86_64/sdk/tools:`pwd`/adt-bundle-linux-x86_64/sdk/platform-tools:$PATH
Note: Be sure to do this every time you start doing development with this software.
Install the latest API (at the time of writing, it's 17) using the android manager
$ android
This may take several minutes to complete.
Installation
Make a place to work, e.g.:
$ mkdir work $ cd work
Get the source:
$ rosinstall . /opt/ros/groovy https://bitbucket.org/osrf/rosandroid/raw/default/rosjava-android.rosinstall
Source the setup file that rosinstall created:
$ . setup.bash
Note: Be sure to do this every time you start doing development with this software.
Compile rosjava:
$ roscd rosjava_core $ ./gradlew install
Compile some libraries from android_core:
$ roscd android_core # Note: you may need to adjut the argument to the `--target` option based # which Android API version you're using. # You may have to kill gradle if it's already running. $ android update project --path ./android_gingerbread_mr1/ --target android-17 $ android update project --path ./android_honeycomb_mr2/ --target android-17 $ cd android_gingerbread_mr1 $ ../gradlew debug $ cd ../android_honeycomb_mr2 $ ../gradlew debug
Trying out the tutorials
Preparation
- Connect your Android device (make sure that USB Debugging is enabled on the device).
- Make sure that your Android device is connected to the same network as your Linux machine (e.g., on the same wifi network).
On the your Linux machine, start roscore:
$ roscore
Building and loading a tutorial app
We'll take as an example the android_tutorial_camera app. The procedure is the same for the other apps.
Configure the app:
$ roscd android_core $ android update project --path ./android_tutorial_camera/ --target android-17
Compile it:
$ cd android_tutorial_camera $ ../gradlew debug
Load it onto your device:
# You will enable developer mode on your device $ adb -d install -r ./bin/MainActivity-debug.apk
Running a tutorial app
To launch the camera tutorial app, on your Android device, touch "CameraTutorial" on your app list.
When prompted, enter the URI for the roscore that's running on your Linux machine, e.g., http://192.168.2.4:11311) and touch "OK". You should see the camera view fill the screen.
On your Linux machine, run image_view:
$ rosrun image_view image_view image:=camera/image _image_transport:=compressed
You should see the camera feed from the Android device in a window on your Linux machine.
Trying out the new apps
The old apps are currently being ported to the new rosjava and android_core APIs. You can try them like so:
Get to the directory containing the apps:
$ roscd osrf_rosandroid
If it's your first time using this working copy, configure it:
$ ./tools/configure.py
This script simply runs the android command on each project to configure it to know where the necessary android_core library projects are. In future versions of the Android tools, those library projects will become .jars and this step will no longer be needed.
To build all the apps:
$ ./gradlew debug
You can build one app by invoking the gradlew wrapper from within that directory, e.g.:
$ cd teleop_video $ ../gradlew debug
The old way
The old apps are currently being ported to the new rosjava and android_core APIs. You can try them like so:
Get to the directory containing the apps:
$ roscd osrf_rosandroid
If it's your first time using this working copy, configure it:
$ make conf
To build:
$ make
(Optional) To load all built apps onto a connected Android device:
$ make load
Creating your own collection of apps
If you want to create your own collection of apps (instead of adding a new app to existing collection):
Create a place to work, e.g.:
$ mkdir myapps cd myapps
More often, you'll create this directory by cloning a repository.Create a build.gradle file with the the following content:
task wrapper(type: Wrapper) { gradleVersion = '1.0-milestone-9' } allprojects { group 'com.mydomain' version = '0.0.0-SNAPSHOT' } subprojects { repositories { mavenLocal() mavenCentral() } configurations.add('compile') { exclude group: 'junit' exclude group: 'xml-apis' } task deployLibs(type: Copy) { from { configurations.compile } into "${projectDir}/libs" } task clean << { ant.delete file: "${projectDir}/local.properties" ant.delete file: "${projectDir}/proguard-project.txt" ant.delete file: "${projectDir}/build.xml" ant.delete dir: "${projectDir}/bin" ant.delete dir: "${projectDir}/gen" ant.delete dir: "${projectDir}/libs" } task debug(type: Exec) { dependsOn deployLibs commandLine 'ant', 'debug' } }
Create an empty settings.gradle file. You'll add an include line for each project that you create.
Create a gradle wrapper by running the existing gradle wrapper from android_core (it's important to run the right version of the wrapper), e.g.:
../android_core/gradlew wrapper
You should commit the newly created gradlew, gradlew.bat, and gradle files/directories to your repository.
Now you're ready to add apps, following the instructions in the next section.
If you accumulate a lot of apps, you may find it convenient to copy the `configure.py` helper script from osrf_rosandroid. You would run this script each time you do a fresh checkout of your apps.
Writing a new app
Get to the directory where you want to create your Android app. Here we'll assume that you're adding an app to the osrf_rosandroid repo:
$ roscd osrf_rosandroid
If instead you want to create your own directory of apps, copy build.gradle and settings.gradle from osrf_rosandroid into your directory, then edit settings.gradle to enumerate your projects.
Create an Android app in the standard way, e.g.:
$ android create project --target android-17 --path ./myproject --package com.mydomain.myproject --activity MainActivity
Add the required android_gingerbread_mr1 library project (see android_core), e.g.:
$ android update project -p ./myproject --library ../../android_core/android_gingerbread_mr1
Note that the path to the library project must be relative to `myproject`'s directory.
Add other library projects as needed, e.g.:
$ android update project -p ./myproject --library ../../android_core/android_honeycomb_mr2
Again, the path to the library project must be relative to `myproject`'s directory.
Add your new project to the list that gradle will build by editing settings.gradle and adding an include line, e.g.:
include 'myproject'
Build your app:
$ cd myproject $ ../gradlew debug
The old way
Use the create-app.py tool to create a skeleton to work from (much easier than creating all the needed files yourself):
roscd osrf_rosandroid $ ./tools/create-app.py MyNewApp
You'll now have a directory called mynewapp containing a basic app that includes a text widget subscribed to the chatter topic.
Add it to the list of projects to be built in Makefile.
Because you added a new project, do the configure step again
$ make conf
Build:
make
Eclipse configuration
- Run through the installation instructions above, including building with gradle.
Set a workspace in eclipse launches and asks you to do so, example:
/home/myusername/rosjava_workspace
- If requried, click the "Go to Workbench" icon.
Install the ADT plugin: http://developer.android.com/sdk/installing/installing-adt.html
If you didn't, install Platforms and Packages for the ADT plugin: http://developer.android.com/sdk/installing/adding-packages.html
Import the required android_gingerbread_mr1 package:
File->Import->Android->Existing Android Code Into Workspace->[Root directory of android_core]->Finish
Click on MasterChooser folder (This step is optional):
File->Rename->"Android Gingerbread MR1"->OK
Import your apps:
File->New->Android->Android Project from Existing Source->[Root directory of mynewapp]->Finish
- Rename your app if you wish.
- Make changes and click the "Run" button to build and deploy to an Android device or an emulator.
Android Development Environment
Contents
Overview
The new android development (hydro and beyond) is based on google's Android Gradle Plugin & Android Studio which will be replacing the ADT & Eclipse.
The following instructions get you set up with the rosjava_core and android_core stacks in a ros environment. Adding additional stacks is simply a matter of extending the rosinstallers or chaining a new catkin workspace.
Installation
Android Studio & SDK
Download and install the new android studio+sdk.
Debs
You'll need catkin, ros (for the setup.bash variables) and a few message packages to ensure it all compiles. Ensure you include any other msg packages you are likely to use in your android applications.
> sudo apt-get install ros-hydro-catkin ros-hydro-ros ros-hydro-common-msgs
You will also need wstool.
> sudo apt-get install python-wstool
or when that is not possible, fall back to pip:
> sudo pip install -U wstool
Sources
Set up some chained catkin workspaces to modularise the builds and save some compile times.
The stacks have been very simply catkinized - essentially all the catkinizing is doing is sequencing the progress of stack builds correctly so you can do it in one shot. Under the hood it is just calling out to gradle in each stack.
Once everything is compiled, you can then simply dive into the sources and just call on gradle from the command line OR utilise android studio (it imports native gradle projects and couples with them well) itself for further compiles.
Make sure you have a clean shell with no previous ROS environment variables set. If you don't it will confuse the chained catkin workspaces, which will ultimately fail when trying to compile.
> mkdir -p ~/rosjava > wstool init -j4 ~/rosjava/src https://raw.github.com/rosjava/rosjava/hydro/rosjava.rosinstall > source /opt/ros/hydro/setup.bash > cd ~/rosjava > catkin_make
Now the source android workspace:
> mkdir -p ~/android > wstool init -j4 ~/android/src https://raw.github.com/rosjava/rosjava/hydro/android_core.rosinstall # or if you want the android_apps/android remocons repos as well: # wstool init -j4 ~/android/src https://raw.github.com/rosjava/rosjava/hydro/android_apps.rosinstall > source ~/rosjava/devel/setup.bash > cd ~/android > catkin_make
Now import your projects into android studio and use the IDE from here!
Testing an App
Android
Install the android_tutorial_camera app via Android Studio to your device. Refer to the Android Studio notes for instructions on how to do this and other things that will mercilessly coerce Android Studio into aligning your evil plans. Feel free to add to these.
Launch the app and connect to a pc master configured in the following way.
PC
> source ~/android/devel/setup.bash
- Start a roscore on your machine
- Launch the app on your device and enter your machine's ip when prompted
- Start the image viewer on your machine
> rosrun image_view image_view image:=camera/image _image_transport:=compressed
Creating an App
Use rosjava_tools/hydro, it has a couple of catkin_create_xxx scripts which are useful.