Mars Alucard
unread,Mar 11, 2009, 12:10:42 PM3/11/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to android-platform
Hi,
In my Android application, I need to use IOCTL() to do I2C R/W
operations.
My native C application could do it successfully, no matter by
standalone or dynamically linking .so, but...
ioctl() returns -1 when Android application loads shared library (.so)
and calls the function including ioctl() via JNI.
Could Android application directly use ioctl() in shared library (.so)
thruogh JNI with any tips?
Or, if Android application needs to use ioctl() in native C code,
could some methods help to do this?
(Like Service Manager, Binder, Android source code, or something
else?)
I've tried to find articles for several days to solve this issue, but
still get no ideas now.
(Followings are the environment and testing steps for my trials.)
1. Testing Steps for Native C Application on Android (Successful)
(1) Chiefly I want to execute the two statements below on Android:
unsigned int hI2C = open("/dev/i2c-2", O_RDWR);
int retI2C = ioctl(hI2C, I2C_SLAVE, 0x0C);
(2) A native C application is compiled on Ubuntu, and then put to
Beagle/G1.
(3) The native C application could work well to open I2C and bind/read/
write I2C slave address 0x0C.
(4)
Even more, the native C application could dynamically link the shared
library (.so) in 2. (1) below,
and then call JNI function to execute the statements in 1. (1) above
successfully.
2. Testing Steps for Android Application with JNI + Shared Library .so
(Unsuccessful)
(1) I make a shared library (.so) with JNI, including the statements
in 1. (1) above, by the commands below:
~/arm-2007q3/bin/arm-none-linux-gnueabi-gcc -I/usr/lib/jvm/java-6-sun/
include -I/usr/lib/jvm/java-6-sun/include/linux -fpic -c XXX.c
~/arm-2007q3/bin/arm-none-linux-gnueabi-ld -rpath /system/lib -rpath ~/
OMAP_ROOTFS/system/lib -L ~/OMAP_ROOTFS/system/lib -lc -lm -T ~/
arm-2007q3/arm-none-linux-gnueabi/lib/ldscripts/armelf_linux_eabi.xsc -
shared -o libXXX.so XXX.o
(2) An Android application is compiled by Eclipse on WIN32, with a few
system-level permission. (enabled by "uses-permission")
(3) Then put the Android application (.apk) and shared library (.so)
to Beagle/G1, with chmod 777.
(4) Run the Android application, to load the shared library and call
JNI function to execute the statements in 1. (1) above.
(5) The Android application could load the shared library, call JNI
functions, and execute almost all statements well, BUT...
(6) When the Android application call JNI function to execute ioctl(),
ioctl() return -1, which means FAILED.
3. Environment
(1) Platform: Android @ T1 OMAP Beagle Board & Google Phone
(2) WIN32: JDK v1.60_12 & Eclipse v3.42 (with a few system-level
permissions enabled by "uses-permission")
(3) Linux: Ubuntu & JDK v1.60_10 & arm-2007q3 ( with arm-non-linux-
gnueabi-gcc/ld)
Many thanks,
Mars Alucard