Port of RXTX library to Android platform

Just ported a google RXTX library to the Android platform.    Check out the picture below, it shows the Motorola Droid phone talking to the FreeNAS device over the serial port.


Testing android with serial


More information and binaries are here http://v-lad.org/projects/gnu.io.android/.   The source code of port is here  https://github.com/vladistan/gnu.io.android/ .

If you have any questions, comments or support request post them below.




  1. A Said,

    March 28, 2011 @ 4:00 am

    Hi I have Only Usb to serial adaptor and i am checking on my window Machine with cygwin tool .
    now Application is runinig and getting toast messages like Got ttyS0 & Got ttyS1 but after that its get error message
    Can’t find USB Serial Port

    Whats the problem In my case I am not getting
    Actually What is happening In my Case i m getting port Name like /dev/ttyS0 And /dev/ttyS1 and In GNUIOTest.java code written for Checking
    if(pid.getPortType() == CommPortIdentifier.PORT_SERIAL &&
    portId = pid;
    So in pid.getName is Not Eqauls to the /dev/ttyUSB4
    so thats the problem i m getting How can i Solve this?
    Please Reply ASAP

  2. Ali Naddaf Said,

    April 5, 2011 @ 6:14 pm

    Hi Vlad.

    I was looking for a solution to access the serial port on my Android device and I came across your port of the rxtxSerial. I am running into some issues so let me explain my set up. I have a ViewSonic tablet that is running Android 2.2; I put a cutom ROM there (TNT Lite 4.4) and it is pretty nice. It has a regular size USB plug so I connected a serial device to it and sure enough, the log on the Android device shows the Serial device over usb was recognized, the driver was loaded and /dev/ttyUSB0 was created. I then added your code, namely I put your shared library in /system/lib and then had to compile your android app since it was complaining about the lack of certificates. When I install and run your test app, the log shows that it is trying to read the ttyUSB0 but the “testRead” method (native code) fails. First it was complaining about not being able to write the lock file; I guess the /data/local/tmp was not writable so I changed the permissions there and that error went away but the read is still failing. It doesn’t seem to be writing any extra messages from the native code to see what is failing (I have set “debug” to true in the Android app but I don’t know if there is a simple way to turn on the debug mode for the native library).

    If you could help me figure out what is happening, I would greatly appreciate it. If so, please let me know what you suggest me to do to debug the issue; I am a java developer and am not much into C/C++ code.

    Many thanks

  3. ej Said,

    May 17, 2011 @ 12:34 pm

    I am trying to use your library on an embedded system running android 2.1. I am using Eclipse on my Windows PC, and I need to communicate to a s3c6410 via serial port. So far the sample application and the librxtxSerial compile and run. I changed the type of port from ttyUSB4 to ttyS0 in GNUIOTest.java and the properties file, but I get the message “Can’t find USB Serial Port”. It looks like the testRead(portname, porttype) function call is returning false, and thus the serial port is not being added to the enumeration. Is there anything else I should do so the serial port ttyS0 gets recognized? Any insight is greatly appreciated. Thanks for sharing your serial library.

  4. ej Said,

    May 17, 2011 @ 12:44 pm

    Maybe the Logcat output could be useful:

    01-01 09:05:21.610: INFO/System.out(2327): static CommPortIdentifier:getPortIdentifiers()
    01-01 09:05:21.610: INFO/System.out(2327): RXTXCommDriver:initialize()
    01-01 09:05:21.610: INFO/GNU.IO(2327): entering RXTXCommDriver:getDeviceDirectory
    01-01 09:05:21.615: INFO/System.out(2327): checking for system-known ports of type 1
    01-01 09:05:21.615: INFO/System.out(2327): checking registry for ports of type 1
    01-01 09:05:21.615: INFO/System.out(2327): RXTXCommDriver:addSpecifiedPorts()
    01-01 09:05:21.615: INFO/GNU.IO(2327): TestREAD.
    01-01 09:05:21.615: INFO/GNU.IO(2327): /dev/ttyS0
    01-01 09:05:21.615: INFO/GNU.IO(2327): entering RXTXPort:testRead
    01-01 09:05:21.620: INFO/GNU.IO(2327): leaving RXTXPort:testRead
    01-01 09:05:21.620: INFO/System.out(2327): checking for system-known ports of type 2
    01-01 09:05:21.620: INFO/System.out(2327): checking registry for ports of type 2
    01-01 09:05:21.625: INFO/System.out(2327): scanning device directory /dev/ for ports of type 2
    01-01 09:05:21.670: INFO/System.out(2327): scanning for parallel ports for os Linux
    01-01 09:05:21.670: INFO/System.out(2327): Entering registerValidPorts()

    then a very long list of Candidate devices which does show ttyS0.

    then the following:
    01-01 09:05:21.995: INFO/System.out(2327): Leaving registerValidPorts()
    01-01 09:05:22.005: INFO/NotificationService(1979): enqueueToast pkg=gnu.io.test callback=android.app.ITransientNotification$Stub$Proxy@43cb4780 duration=100
    01-01 09:05:22.005: INFO/System.out(2327): true
    01-01 09:05:22.015: INFO/NotificationService(1979): enqueueToast pkg=gnu.io.test callback=android.app.ITransientNotification$Stub$Proxy@43cac530 duration=100
    01-01 09:05:22.100: INFO/ActivityManager(1979): Displayed activity gnu.io.test/.GNUIOTest: 565 ms

    Any help in why the ttyS0 port is not recognized or read is very much appreciated.
    Thanks in advance.

  5. salacc Said,

    June 24, 2011 @ 2:54 am

    Hey vlad, thanks for all effort for bringing USB->serial to the world of Android.

    Can you port this to the honeycomb? I tried to follow your instructions but it just doesnt work (actually, i cannot even install your gnuiotest.apk on honeycomb tablet).

    Tnx in advance!

  6. Dirk Said,

    June 28, 2011 @ 4:38 pm

    I am trying the rxtx lib on a Archos 101 with urukdroid 1.0.

    But when running the GnuIOTest app ( i recompiled it, the downloaded one complained about signing). it outputs:

    Requesting ports.. Cant find USB serial port.

    I have a FTDI usb to serial adapter connected to the usb host port wich gives /dev/ttyUSB0 you state the props file should contain:

    gnu.io.rxtx.SerialPorts=/dev/ttyUSB3:/dev/ttyUSB4 , should it not be changed to /dev/ttyUSB0 ?

    Should i also recompile the shared lib ? (with the NDK = ?)

    I would love to get this working..

  7. Pier Aisa Said,

    July 4, 2011 @ 2:59 am

    Dear Vlad,
    thank you very much for this very nice work. I followed all the steps, to use RXTX with tablet WonderMedia WM8650 with Android OS 2.2, kernel 2.6.32, Build V1.3.0 but at runtime I have a crash when loading the librxtxSerial.so.
    I attach the logcat part with the debug info. Can you advise on this ? It seems tha the lib rxtxSerial.so is not good for my platform. In this case what shall I do ? Shall I recomplie librxtxSerial.so. An answer is very appreciated, you are the only guy that is focused on this —> very nice and useful for java developments on serial ports with Android.

    Logcat dump

    D/BounceVertcalScrollView( 1510): com.android.bouncescroller.SpiritIcon@45e04b88is onClicked

    I/ActivityManager( 1379): Starting activity: Intent { act=android.intent.action.MAIN cmp=osmosys.control/.OsmosysRemoteControl }

    I/ActivityManager( 1379): Start proc osmosys.control for activity osmosys.control/.OsmosysRemoteControl: pid=2077 uid=10059 gids={1015}

    I/ActivityManager( 1379): Displayed activity osmosys.control/.OsmosysRemoteControl: 524 ms (total 524 ms)

    I/ActivityManager( 1379): Starting activity: Intent { cmp=osmosys.control/.Acquisition }

    I/ActivityManager( 1379): Displayed activity osmosys.control/.Acquisition: 202 ms (total 202 ms)

    I/DEBUG ( 1190): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

    I/DEBUG ( 1190): Build fingerprint: ‘generic/generic/generic/:2.2/Froyo/v1.2.0-20110506.140714:eng/’

    I/DEBUG ( 1190): pid: 2077, tid: 2077 >>> osmosys.control <<<

    I/DEBUG ( 1190): signal 4 (SIGILL), fault addr 818033b6

    I/DEBUG ( 1190): r0 0000aa00 r1 00000000 r2 000000f8 r3 0000037c

    I/DEBUG ( 1190): r4 00006d50 r5 0000ccc8 r6 818033b1 r7 002059c8

    I/DEBUG ( 1190): r8 80c13b00 r9 0000ccc8 10 4208bc0c fp 00000000

    I/DEBUG ( 1190): ip 80c88090 sp bea47678 lr 80c42ed3 pc 818033b6 cpsr 40000030

    I/DEBUG ( 1190): #00 pc 000033b6 /system/lib/librxtxSerial.so

    I/DEBUG ( 1190): #01 pc 00042ed0 /system/lib/libdvm.so

    I/DEBUG ( 1190): #02 pc 0005b0aa /system/lib/libdvm.so

    I/DEBUG ( 1190): #03 pc 00018714 /system/lib/libdvm.so

    I/DEBUG ( 1190): #04 pc 0001e8c4 /system/lib/libdvm.so

    I/DEBUG ( 1190): #05 pc 0001d790 /system/lib/libdvm.so

    I/DEBUG ( 1190): #06 pc 00053eec /system/lib/libdvm.so

    I/DEBUG ( 1190): #07 pc 00054102 /system/lib/libdvm.so

    I/DEBUG ( 1190): #08 pc 0005f198 /system/lib/libdvm.so

    I/DEBUG ( 1190): #09 pc 0005fb96 /system/lib/libdvm.so

    I/DEBUG ( 1190): #10 pc 00058d30 /system/lib/libdvm.so

    I/DEBUG ( 1190): #11 pc 0005af0c /system/lib/libdvm.so

    I/DEBUG ( 1190): #12 pc 00018714 /system/lib/libdvm.so

    I/DEBUG ( 1190): #13 pc 0001e8c4 /system/lib/libdvm.so

    I/DEBUG ( 1190): #14 pc 0001d790 /system/lib/libdvm.so

    I/DEBUG ( 1190): #15 pc 00053eec /system/lib/libdvm.so

    I/DEBUG ( 1190): #16 pc 00054102 /system/lib/libdvm.so

    I/DEBUG ( 1190): #17 pc 0005f198 /system/lib/libdvm.so

    I/DEBUG ( 1190): #18 pc 00060a6c /system/lib/libdvm.so

    I/DEBUG ( 1190): #19 pc 00015768 /system/lib/libdvm.so

    I/DEBUG ( 1190): #20 pc 0001e8c4 /system/lib/libdvm.so

    I/DEBUG ( 1190): #21 pc 0001d790 /system/lib/libdvm.so

    I/DEBUG ( 1190): #22 pc 0005408e /system/lib/libdvm.so

    I/DEBUG ( 1190): #23 pc 0005bde2 /system/lib/libdvm.so

    I/DEBUG ( 1190): #24 pc 00018714 /system/lib/libdvm.so

    I/DEBUG ( 1190): #25 pc 0001e8c4 /system/lib/libdvm.so

    I/DEBUG ( 1190): #26 pc 0001d790 /system/lib/libdvm.so

    I/DEBUG ( 1190): #27 pc 00053eec /system/lib/libdvm.so

    I/DEBUG ( 1190): #28 pc 0004072c /system/lib/libdvm.so

    I/DEBUG ( 1190): #29 pc 00034454 /system/lib/libdvm.so

    I/DEBUG ( 1190): #30 pc 0002cbe0 /system/lib/libandroid_runtime.so

    I/DEBUG ( 1190): #31 pc 0002db0c /system/lib/libandroid_runtime.so

    I/DEBUG ( 1190):

    I/DEBUG ( 1190): code around pc:

    I/DEBUG ( 1190): 81803394 4905a200 4602189b 1859b510 f7ff2004

    I/DEBUG ( 1190): 818033a4 bd10e8c6 00006d74 ffffd4ef 4c08b510

    I/DEBUG ( 1190): 818033b4 bf004a08 1864a100 58a34907 18606018

    I/DEBUG ( 1190): 818033c4 ffe4f7ff 18204805 ffe0f7ff bd104804

    I/DEBUG ( 1190): 818033d4 00006d50 000000f8 ffffd529 ffffd53d

    I/DEBUG ( 1190):

    I/DEBUG ( 1190): code around lr:

    I/DEBUG ( 1190): 80c42eb0 9902e02f 1c286eeb 210766e9 f0039304

    I/DEBUG ( 1190): 80c42ec0 9005ff67 22df4827 58210093 210058c8

    I/DEBUG ( 1190): 80c42ed0 990547b0 1c281c06 ff5af003 4b229804

    I/DEBUG ( 1190): 80c42ee0 429e66e8 3b02d015 d012429e 429e3304

    I/DEBUG ( 1190): 80c42ef0 4813d00f 9d024a1d 18a21821 1c332005

    I/DEBUG ( 1190):

    I/DEBUG ( 1190): stack:

    I/DEBUG ( 1190): bea47638 8180122c /system/lib/librxtxSerial.so

    I/DEBUG ( 1190): bea4763c 818005dc /system/lib/librxtxSerial.so

    I/DEBUG ( 1190): bea47640 00000000

    I/DEBUG ( 1190): bea47644 b0004a48 /system/bin/linker

    I/DEBUG ( 1190): bea47648 b0014df4

    I/DEBUG ( 1190): bea4764c 818033b1 /system/lib/librxtxSerial.so

    I/DEBUG ( 1190): bea47650 000089ac /system/bin/app_process

    I/DEBUG ( 1190): bea47654 002059c8 [heap]

    I/DEBUG ( 1190): bea47658 80c13b00 /system/lib/libdvm.so

    I/DEBUG ( 1190): bea4765c 0000ccc8 [heap]

    I/DEBUG ( 1190): bea47660 4208bc0c

    I/DEBUG ( 1190): bea47664 b00031b5 /system/bin/linker

    I/DEBUG ( 1190): bea47668 00000001

    I/DEBUG ( 1190): bea4766c b0010b4c

    I/DEBUG ( 1190): bea47670 df002777

    I/DEBUG ( 1190): bea47674 e3a070ad

    I/DEBUG ( 1190): #00 bea47678 80c87fc4 /system/lib/libdvm.so

    I/DEBUG ( 1190): bea4767c 80c42ed3 /system/lib/libdvm.so

    I/DEBUG ( 1190): #01 bea47680 ad112a4d /system/lib/libnativehelper.so

    I/DEBUG ( 1190): bea47684 000007ff

    I/DEBUG ( 1190): bea47688 45ff6188 /dev/ashmem/mspace/dalvik-heap/2 (deleted)

    I/DEBUG ( 1190): bea4768c 00207a28 [heap]

    I/DEBUG ( 1190): bea47690 00000000

    I/DEBUG ( 1190): bea47694 00000001

    I/DEBUG ( 1190): bea47698 00207a34 [heap]

    I/DEBUG ( 1190): bea4769c 00207a38 [heap]

    I/DEBUG ( 1190): bea476a0 4208bc20

    I/DEBUG ( 1190): bea476a4 bea47710 [stack]

    I/DEBUG ( 1190): bea476a8 002059c8 [heap]

    I/DEBUG ( 1190): bea476ac 45ff6188 /dev/ashmem/mspace/dalvik-heap/2 (deleted)

    I/DEBUG ( 1190): bea476b0 40054b70 /dev/ashmem/mspace/dalvik-heap/zygote/0 (deleted)

    I/DEBUG ( 1190): bea476b4 80c5b0af /system/lib/libdvm.so

    D/Zygote ( 1191): Process 2077 terminated by signal (4)

    I/ActivityManager( 1379): Process osmosys.control (pid 2077) has died.

    I/WindowManagerService( 1379): WIN DEATH: Window{460808b0 osmosys.control/osmosys.control.OsmosysRemoteControl paused=false}

    I/WindowManagerService( 1379): WIN DEATH: Window{4604cdb0 osmosys.control/osmosys.control.Acquisition paused=false}

    I/ActivityManager( 1379): Start proc osmosys.control for activity osmosys.control/.OsmosysRemoteControl: pid=2085 uid=10059 gids={1015}

    I/BootReceiver( 1379): Copying /data/tombstones/tombstone_01 to DropBox (SYSTEM_TOMBSTONE)

    D/dalvikvm( 1379): GC_FOR_MALLOC freed 13878 objects / 713528 bytes in 175ms

    I/UsageStats( 1379): Unexpected resume of osmosys.control while already resumed in osmosys.control

    D/dalvikvm( 1379): GC_FOR_MALLOC freed 837 objects / 41160 bytes in 171ms

    I/dalvikvm-heap( 1379): Grow heap (frag case) to 6.891MB for 50448-byte allocation

    D/dalvikvm( 1379): GC_FOR_MALLOC freed 802 objects / 53776 bytes in 117ms

    D/dalvikvm( 1379): GC_FOR_MALLOC freed 397 objects / 22568 bytes in 115ms

    I/dalvikvm-heap( 1379): Grow heap (frag case) to 6.843MB for 25232-byte allocation

    D/dalvikvm( 1379): GC_FOR_MALLOC freed 0 objects / 0 bytes in 108ms

    D/dalvikvm( 1379): GC_FOR_MALLOC freed 53 objects / 52480 bytes in 110ms

    I/dalvikvm-heap( 1379): Grow heap (frag case) to 6.889MB for 100880-byte allocation

    D/dalvikvm( 1379): GC_FOR_MALLOC freed 0 objects / 0 bytes in 113ms

    D/dalvikvm( 1379): GC_FOR_MALLOC freed 20 objects / 139384 bytes in 111ms

    W/InputManagerService( 1379): Got RemoteException sending setActive(false) notification to pid 2077 uid 10059

    I/ActivityManager( 1379): Displayed activity osmosys.control/.OsmosysRemoteControl: 1561 ms (total 1561 ms)

    W/GTalkService( 1673): [GTalkConnection.15] doConnect: caught XMPPError connecting to mtalk.google.com:5228.: (502)

    W/GTalkService( 1673): — caused by: java.net.SocketException: Network unreachable

  8. vlad Said,

    July 6, 2011 @ 11:08 am

    Looks like the machine code compiled by GCC for Motrolla Droid is not compatible with WonderMedia chip. I just checked and it seems that WonderMedia has developed their own ARM chip, which might have slightly different ISA. You need to recompile the libRxTx for the device. For that you need a tool chain, and the AOSP source modified for your platform, which might or might not be available for your device given the sad state of GPL violations in the Android World.

    Usually the best way to see if your device is suitable for low level development is to consult the Cyanogen’s supported device list here if device is on the list, it is pretty much guaranteed that you can do whatever you want with the device ( also pay attention to the bottom chart that gives you the status of the Google Apps for that devices, of course if you care about those.

  9. KasiRao Said,

    July 12, 2011 @ 3:38 am

    I am doing a project controlling some hardware device (like RFID kit) from
    Android Emulator which is installed in a PC… But i am not getting
    how to control the external hardware which is connected to PC from
    Android Emulator…. Can u help me on this topic??? Is it same doing
    project under windows and Linux??

    I have written some code using android.hardware.usb package (which is
    available in Android 3.1) … but it is not detecting the hardware
    devices attached over USB

    can i use the javax.comm package or RXTX in android to read the data from serial port???

  10. Sabit Said,

    August 16, 2011 @ 12:08 am

    Hi Vlad,

    Can you please post a how to compile rxtx for Android?

    Your library is for armv7, and apparently armv7 is not compatible with armv6.

    It would “complete” this library.


  11. Martin Gebov Said,

    September 20, 2011 @ 11:59 am

    I’m sorry for the stupid question, but where can i find this properties file ?

  12. Sonia Said,

    October 19, 2011 @ 2:53 am

    Hi Vlad.
    I just saw your post and I think it’s what I’m looking for. I need to check a COM port for a specific bluetooth device paired to my Android, but until now, I haven’t found any trustable information about that. Do you think your code will help me to discover the COM port to establish a Socket between my Android mobile and my bluetooth device? I need it to be a Socket instead of a BluetoothScoket because I need to handle timeouts on reading and writings actions on the socket.

    Can you explain a bit more specific how to install your library?

    Please, send me an email for more specifin information, please.

  13. Bwyyoung Said,

    January 31, 2012 @ 4:49 am

    Dear Mr. Vlad,

    I refer to the question asked by Pier Aisa on http://rxtx.qbang.org/wiki/index.php/Main_Page, and am currently facing the same problem with the library on WM8650

    I have read your response about recompiling for WM8650. I have NDK for compiling the JNI, and I have the kernel source code for WM8650. I have searched online for how to compile the JNI with respect to WM8650, but have not gotten any results. What are the steps that I should take in order to do a recompilation? Could you please tell me step by step on how to do the compilation?


    Brian Young

  14. Ian James Said,

    February 28, 2012 @ 5:38 am


    I tried your app on an Android 4.0 (Icecream) Tablet and it fails to install – I am not that surprised!

    Any ideas what I would need to do to get it to work?


    Ian James

  15. Icarusfactor - Daniel Yount Said,

    July 15, 2012 @ 7:06 pm

    I have a Viewsonic 10.1 tablet with Android 4.0.3 the kernel has usbserial compiled in it but does not have libserial. Will this lib work on a 2.6.39 kernel and where is the source , is it just the standard source or does it need to be from another source base?

  16. Kevin Lambert Said,

    January 18, 2013 @ 9:07 am

    I built rxtx for an arm processor and have a jar file that uses it and a class with a test main() that opens “/dev/ttyS8″ which is runnable and tests out fine from the command line when terminal is given SU permissions but when I use this jar file in an android application I end up getting NoSuchPortException thrown for that com port (/dev/ttyS8). Do you have any idea why it works from the command line but not from an apk?

  17. Rathan Said,

    March 12, 2014 @ 2:59 am

    Hi v-lad, I need to fetch serial port weighing machine values (byte format) into the android device using rxtx.
    Any helpful solution?

  18. Numan Said,

    March 25, 2014 @ 5:12 am

    Your code is send method?I will make to get rs 232 port in android app.How to make this example.?

Leave a Comment