1. 程式人生 > >Build rosjava Library Sources in ROS w/ Android Studio

Build rosjava Library Sources in ROS w/ Android Studio

Here we go! This post highlights building rosjava source libraries (specifically android_core) and uploading to a forked maven directory for use in Android Studio. Most of the information I used to compile this post comes from the following two links: Uploading to Maven on Github and Updating Maven Artifacts

. These two links are fairly outdated and useROS Hydro. Everything I am going to go over will correspond withROS Indigo so keep that in-mind if you are using a different ROS version.

Alright lets see what we need before we start!

Pre-Requirements:

  • Your preferred ROS version (I used Indigo on Ubuntu 14.04)
  • A GitHub account
  • Android Studio
  • Celebratory beverage(s) for Part 1
  • Celebratory beverage(s) for Part 2

Part 1

Update Dependencies

Lets update all of your ROS dependencies to ensure we have the latest messages, install tools and build dependencies.

>sudo apt-get update
>sudo apt-get install --only-upgrade
ros-indigo-* >sudo apt-get install python-wstool >sudo apt-get install ros-indigo-rosjava-build-tools >sudo apt-get install ros-indigo-warehouse-ros

Fork Repos

Now that we have all of our dependencies updated, lets fork all the official rosjava repositories we need for modifying our android_core code and uploading our modified artifacts. If you need help on forking check out thislittle bugger.

This is the button you are looking for…

Fork Icon

  • Forkrosjava (These are metapackages that contain rosinstall files)

Environmental Variables

We need to modify our environmental variables so that the catkin build scripts can find our local rosjava_mvn_repo. I am going to put these variables in my .bashrc file because I am really bad at remembering which terminal has specific environmental variables set. Just an FYI: if you export a variable in a specific terminal and open a new terminal, that variable is no longer set…as I said, it can cause some headache if you are not careful.

Anyways…add the following lines to your ~/.bashrc file

export ROS_MAVEN_REPOSITORY=file://home/<username>/rosjava_mvn_repo
export ROS_MAVEN_DEPLOYMENT_REPOSITORY=/home/<username>/rosjava_mvn_repo

Tell your current terminal about the new variables by sourcing your bashrc file.

> source ~/.bashrc

Locally Clone Forks

From your linux terminal:

> cd ~
> git clone https://github.com/<username>/rosjava_mvn_repo
> mkdir repos
> cd repos
> git clone -b indigo-devel https://github.com/<username>/rosjava
> git clone -b indigo https://github.com/<username>/android_core

Note: The -b indigo-devel specifies that I want the “indigo-devel” branch of the specified repository. You might need to change this if you are on a different flavor of ROS.

You local rosjava clone contains the necessary rosinstall files for installing your android_core code.

Modifying and Push android_core.rosinstall

Now lets modify the android_core.rosinstall file to point to our forked and now cloned android_core repository.

{'git': {'local-name': 'android_core', 'version': 'indigo', 'uri':'https://github.com/<username>/android_core'}},

Lets commit and push these changes to our forked rosjava repository.

>git add android_core.rosinstall
>git commit -m "My Commit Message"
>git push origin indigo-devel

If you dont get git…see what I did there? Then you should checkout some git tutorials online. I added a few links to the support documents section below.

Installing android_core (Catkin style)

Now that we have our rosinstall file updated with the correct repository, lets install android_core source code so that we can modify and build our code.

> mkdir -p ~/android
> wstool init -j4 ~/android/src https://raw.githubusercontent.com/<username>/rosjava/indigo-devel/android_core.rosinstall

Before We Build

Before we build the android_core source code we need to make sure we have the necessary Android SDK(s) and libraries. This is covered in the next part of the post.

You can now enjoy your part 1 celebratory beverage(s).

Part 2

Downloading Android SDKs

Before we start lets verify that you have Android Studio correctly installed.Hereare some good tutorials on installing Android Studio on Ubuntu 14.04.

  • Open Android Studio
  • Click Configure->SDK Manager

SDK Manager

  • Check the API Level 15 and 10 Boxes

SDK

  • Click Apply

Building android_core Source

Before we build the android_core source code, we need to add a few variables to the end of our local .bashrc file.

#Android Specific
export ANDROID_HOME=/<your_path_to>/android-sdk
export PATH=$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH

Where <your_path_to> is location path of your android-sdk folder. If you need help finding that path, trythis.

Lets build this thing!

cd ~/android
. /opt/ros/indigo/setup.bash
catkin_make

You should see a BUILD SUCCESSFUL in the terminal window…don’t open your celebratory beverage yet.

BuildTerminal

update_maven_repo Script

Your new android_core packages have automatically been copied to your local maven repository (If you remember…~/rosjava_mvn_repo). Now we need to add, commit and push them to our github remote maven repository.

The developers of rosjava are smarter than myself and have built a script to help out with this.

From a terminal:

cd ~/rosjava_mvn_repo
./update_maven_repo

Here is the kicker…I noticed that a few of my packages/artifacts that I modified were not listed by the script as upgraded or new artifacts. I then dove into the script to see what it was doing and found that in-order for a package to be labeled as “updated” the generated maven-metadata.xml file (from running catkin_make) must contain at least one difference (from the previous version). See code snippet below for details.

git diff --exit-code --quiet -Sversion ${metadata}
  if [ $? -ne 0 ]; then
    packages+=(${package})
  fi
...

The maven-metadata.xml file for each package is created when catkin_make is called from the top level source directory (ex. ~/android/) and uses information from each package’s package.xml file.

If I “bump” the version number in the package.xml file and re-run catkin_make I see the artifacts as “updated” by the update_maven_repo script.

Upgraded Artifacts

Anyways…follow the script prompts to commit, add and upload the new artifacts to your forked remote maven repository.

You can now enjoy your part 2 celebratory beverage(s).

Next Steps

Now that you have your new artifacts what do you do with them? I will be posting a tutorial on how to import and utilize rosjava maven artifacts in a Android Studio project.

I will also be posting instructions on how to import the android_core project into Android Studio for source editing.

Check back soon for links to these new posts!

Additional Resources

Questions

If you have questions please write a comment below and I will try and answer them as soon as I have time!