Ask Your Question

Implement custom message in Android Studio

asked 2019-04-20 09:53:50 -0500

MrNicolas3003 gravatar image


at the moment I am developing an Android application that publishes data into a ROS environment. For this, I use rosandroid-core which is included with Maven from the following repository:

By commands like

compile 'org.ros.rosjava_messages:std_msgs:0.5.11'

I am able to generate all standard messages that are defined in the repository. The String-message is defined like the following:

package std_msgs;

import org.ros.internal.message.Message;

public interface String extends Message {

public static final String _DEFINITION = "string data\n";

public static final String _TYPE = "std_msgs/String";

String getData();

void setData(String str);


Now I want to create my own message type. So I created a Java interfaces that extends the org.ros.internal.message.Message class.

When I initalize a message from the custom type in the code, everything is fine. But as soon as I want to publish a message from this custom message type, I get a NoClassFoundException.

Do you know where the error is? How can I include the compilation of my custom message type in the Gradle file?

Thanks and best regards.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-04-22 07:56:08 -0500

jubeira gravatar image

updated 2019-04-22 09:20:38 -0500


That's not how ROS messages work in Java. Note that those interfaces are just empty placeholders; the actual objects that you use to exchange data are generated in runtime.

Those interfaces are generated automatically if you source genjava when building inside a catkin workspace. The standard ROS tutorial to create messages applies.

You can check rosjava_messages repository for reference. It should help you creating custom messages. If you want to use the messages in Android Studio:

  • Create a ROS package with message definitions in your workspace. Configure your CMakeLists file to generate the workspace.
  • Generate the message artifacts by building the workspace. You will need to have genjava installed.
  • Source the workspace.
  • Launch Android Studio. The Maven paths will enable the IDE to find the artifacts you've just generated in the step above.

Hope it helps!

Extra: I don't have a complete example at hand for messages, but generating service interfaces is analogous. You can check how it's done for services here:

edit flag offensive delete link more



thank you for your fast answer! Is there also a way to generate custom ROS messages in Java without a ROS environment?

MrNicolas3003 gravatar image MrNicolas3003  ( 2019-04-23 12:11:57 -0500 )edit

Hmm not that I know of nor I would recommend... In any case you'll need genjava to translate the msg files to the interfaces.

jubeira gravatar image jubeira  ( 2019-04-23 12:45:32 -0500 )edit

Okay, I am going to install a ROS environment. Thank you very much!

MrNicolas3003 gravatar image MrNicolas3003  ( 2019-04-24 01:10:54 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-04-20 09:53:50 -0500

Seen: 366 times

Last updated: Apr 22 '19