ROS Android

ROS Setup in Android Project

To create application for ROS in android we need to setup ROS library in our project. So we can operate robot using the android application and transfer data between android and robot. To build ros android application, does not require the ROS installation in your computer.

Requirements Android Studio installed in your computer.

Before we add library in our project let me explain little bit about the library. This library is build on top of the rosJava for access the functionality of the ROS. It provides different core component for the ROS integration that easier to use in android. For example, RosActivity, RosTextView, RosImageView etc.

Step 1: Setup Gradle for the ROSjava Setup.

First Remove buildscript block from the project level build.gradle file and add below block in the gradle file.

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

Then Add this block anywhere in that same gradle file and sync the gradle file.

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"
            }
        }
    }
}

Step 2: Add dependency in the Module level build.gradle file and sync this file.

 implementation "org.ros.android_core:android_core_components:0.4.0"

After successful syncing process you will be able to access core functionality of the ROS. if you are getting “Manifest merger failed” error in gradle sync then add below line in menifests file.

Error Details

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_core_components:0.4.0] AndroidManifest.xml:20:9-36 value=(@mipmap/icon).
	Suggestion: add 'tools:replace="android:icon"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.

Resolve by adding android:icon attribute in application tag and import the package that require using Atl+Enter

 tools:replace="android:icon"

manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.hoemtech.rossetup">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        tools:replace="android:icon"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.RosSetup">

 </application>

</manifest>

After solving above error click Build -> Make Project to check the error is solve.

Now try typing RosTextView on the class if you can add without any errors that means you successfully configure the ros in your android project.

Gradle File (Project Level)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    apply from: "https://github.com/rosjava/android_core/raw/kinetic/buildscript.gradle"
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.0-beta02'

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

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"
            }
        }
    }
}

allprojects {
    group "org.ros.android_core"
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

If you found any difficulty in integrating ROS in android don’t worry I created the project with ROS integration in android studio. You can download project from below links and import as a project in android studio.

DOWNLOAD PROJECT

Leave a comment