ros2-java / ros2_java

Java and Android bindings for ROS2
Apache License 2.0
162 stars 91 forks source link

JNI ERROR of sensor_msgs.msg.Image on Android side but solved on ROS side #224

Open ShanPoon opened 1 year ago

ShanPoon commented 1 year ago

With reference to this issue https://github.com/ros2-java/ros2_java/issues/132

The crash message JNI ERROR (app bug): expected jbyte but got value of 206 as argument 1 to void java.lang.Byte.(byte)

The crash message on android side showed that the received data from ros is unsigned byte (0-255) but the byte of java is signed (-128, 127). Therefore, the proper way to solve this problem should be on android side to disable the check of data type.
https://android.googlesource.com/platform/art/+/master/runtime/reflection.cc line417

I have no idea to solve on android side but changed unit8[] data from http://docs.ros.org/en/noetic/api/sensor_msgs/html/msg/CompressedImage.html from to int8[] data and compile the ros2_java library again. The publish/subscribe of this message becomes normal without crash.

Is there alternative to solve this issue on Android side without changing the message type of CompressedImage?

YasuChiba commented 1 year ago

Hi, I'm currently working on porting ROS-Mobile-Android to ROS2 using rcljava. (https://github.com/YasuChiba/ROS2-Mobile-Android) I encountered this JNI Error problem while implementing the function to display std_msgs.msg.Image in the app. As a temporary workaround, I have confirmed that the error no longer occurs once I rewrite the msg.cpp.em file like this. (though performance is quite poor). In my understanding, the osrf/ros2_java repository has resolved this issue, but are there any plans to merge the changes into this repository?

@ivanpauno @jacobperron I'm really sorry to mention both of you. Could you please tell me if you are planning to update this repository? If not, I will try to implement it by my self :)