(!) 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.

Installation - Android Studio Development Environment

Description: Develop from Android Studio without a ROS Environment!

Keywords: android studio installation

Tutorial Level: BEGINNER

Build apps and libraries inside Android Studio - no ROS environment necessary!


This tutorial shows how to setup develop using Android Studio without a ROS environment. This means no installation of ros necessary, no sourcing of setup.bash, and no catkin packages. You can focus on a single app using just the studio, the Gradle backend and some gradle-groovy logic connecting you to our maven repository.

Useful for the non-ROS programmer!

Android Studio Project

You can skip this section if you already have an existing project you would like to add rosjava to.

Otherwise, create a new project as you would do normally: choose "Start a new Android Studio project", select the name and package of your choice, choose "Phone and Tablet" Android Target with Minimum SDK: API 15.

Including rosjava

Project-wide build script

Edit the top-level build.gradle file and replace this part:

buildscript {
    repositories {
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

with this:

buildscript {
  apply from: "https://github.com/rosjava/android_core/raw/kinetic/buildscript.gradle"

Then, add the following lines:

subprojects {
    apply plugin: 'ros-android'

    afterEvaluate { project ->
        android {
            // Exclude a few files that are duplicated across our dependencies and
            // prevent packaging Android applications.
            packagingOptions {
                exclude "META-INF/LICENSE.txt"
                exclude "META-INF/NOTICE.txt"

Android application (or library)

In the build.gradle file for each application or library where you want to include rosjava you should modify it as follows:

dependencies {
    // You now now add any rosjava dependencies, like so:
        implementation 'org.ros.android_core:android_core_components:0.4.0'

Known issues

Incompatibility with espresso

Conflict with dependency 'com.google.code.findbugs:jsr305'. Resolved versions for app (1.3.9) and test app (2.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

The version of rosjava_bootstrap:message_generation at the time of this writing uses a different version of guava than the one used by espresso 2.2.2, causing a compile error for instrumentation tests.

Merging of icon resources

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@icon value=(@mipmap/ic_launcher) from AndroidManifest.xml:7:9-43
        is also present at [org.ros.android_core:android_10:0.3.0] AndroidManifest.xml:19:9-36 value=(@mipmap/icon).
        Suggestion: add 'tools:replace="android:icon"' to <application> element at AndroidManifest.xml:5:5-18:19 to override.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

You can resolve this as indicated in the error message by adding a replace merge directive in your AndroidManifest.xml's application element:

    <application xmlns:tools="http://schemas.android.com/tools"

Next Steps

At this point your Android project is ready to start using ROS. You can continue on to the RosActivity tutorial to start learning how to add rosjava code to your application.

Wiki: android/Tutorials/kinetic/Installation - Android Studio Development Environment (last edited 2019-01-29 23:07:12 by MelvinWang)