NeuronRobotics / nrjavaserial

A Java Serial Port system. This is a fork of the RXTX project that uses in jar loading of the native code.
Other
344 stars 143 forks source link

Android Support #192

Closed doit-ceo closed 4 years ago

doit-ceo commented 4 years ago

OK , after 3 days, I finally managed to get this compiled with NDK, the jar didn't work (native biding never worked in Android with Jar) , then I used the legacy RXTX jar, this seems to get at least the native version printed, but nothing else work !

Does this lib really support Android, if so, can someone help in this ?

madhephaestus commented 4 years ago

It only works on rooted Android builds since Android 3.x

The linux kernel under android mounts serial ports with permission

root:root

There are 2 ways to allow the Dalvik system to access that, either run the application as root, or modify the sub system with a udev rule telling the kernel to mount the devices as owned by some some group the user is already a member of.

Basically, the easy use case was removed in Android 4.x

Moving forward the USB api is recommended for accessing usb connected serial devices. You can ask for permission to access usb devices from Android.

doit-ceo commented 4 years ago

@madhephaestus thanks for your replies, I do confirm that my device is rooted, yet this doesn't work ! and we have a call for root just before rxtx calls

        try {
            Process px = Runtime.getRuntime().exec("su");
        } catch (Exception e) {
            e.printStackTrace();
        }
        //rxtx here 
madhephaestus commented 4 years ago

rooting is step one.

Your application needs to be run as root, or you need to mount the serial port with a udev rule mounting serial ports as 777

Open a root terminal and do ls -al on the port you want to access.

Make a udev rule to mount the serial port with permissions 777

SUBSYSTEM=="tty", MODE="0777"