Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old August 12th, 2011, 10:47 AM   #1 (permalink)
New Member
 
Join Date: Aug 2011
Posts: 6
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compiling LibUSB for Android

Hey Guys,
I'm writing an application that requires a custom USB driver, and i need LibUSB to be able to do it. I downloaded the following:

android.git.kernel.org Git - platform/external/libusb.git/summary

My problem is that when i try to cross compile using ./configure this lib, i get the error: unsupported operating system. I've been trying to configure like this:

Code:
./configure --host=arm-eabi CC=arm-linux-androideabi-gcc CPPFLAGS="-I$NDK_ROOT/platforms/android-3/arch-arm/usr/include/" CFLAGS="-nostdlib" LDFLAGS="-Wl,-rpath-link=$NDK_ROOT/platforms/android-3/arch-arm/usr/lib/ -L$NDK_ROOT/platforms/android-3/arch-arm/usr/lib/" LIBS="-lc"
The main aim is to be able to use the library with the Android NDK. If anybody has managed this - or could help me with this, it would be most appreciated! (Also - i am using Ubuntu)

Cheers, Tony.

t.elimpus is offline  
Reply With Quote
Sponsors
Old August 24th, 2011, 11:13 AM   #2 (permalink)
New Member
 
Join Date: Aug 2011
Posts: 1
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by t.elimpus View Post
Hey Guys,
I'm writing an application that requires a custom USB driver, and i need LibUSB to be able to do it. I downloaded the following:

android.git.kernel.org Git - platform/external/libusb.git/summary

My problem is that when i try to cross compile using ./configure this lib, i get the error: unsupported operating system. I've been trying to configure like this:

Code:
./configure --host=arm-eabi CC=arm-linux-androideabi-gcc CPPFLAGS="-I$NDK_ROOT/platforms/android-3/arch-arm/usr/include/" CFLAGS="-nostdlib" LDFLAGS="-Wl,-rpath-link=$NDK_ROOT/platforms/android-3/arch-arm/usr/lib/ -L$NDK_ROOT/platforms/android-3/arch-arm/usr/lib/" LIBS="-lc"
The main aim is to be able to use the library with the Android NDK. If anybody has managed this - or could help me with this, it would be most appreciated! (Also - i am using Ubuntu)

Cheers, Tony.

Hi Tony,

I have to do a similar stuff with android NDK using Libusb. Please can you help via sharing how did you get on with the libusb and did you achieved the communication?

Highly appreciated and thanks in advance.

-Arsalan
arsalan.haqs is offline  
Reply With Quote
Old September 15th, 2011, 09:53 AM   #3 (permalink)
New Member
 
Join Date: Aug 2011
Posts: 6
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Arsalan,
Sorry about the late reply. I managed to build the library in the same makefile that you build your C native library in. I took out all the C/header files from the uncompiled libusb folder which is the link i provided in my first post, and put them in the jni folder of the App's root folder. In the makefile, i included all the .c files in the jni folder as LOCAL_C_INCLUDES. This is the way that has worked for me, hope it helps you too.

Tony.
t.elimpus is offline  
Reply With Quote
Old September 15th, 2011, 11:01 PM   #4 (permalink)
Senior Member
 
Join Date: Jul 2010
Posts: 977
 
Device(s): Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Thanks: 52
Thanked 199 Times in 144 Posts
Default

When compiling libraries using android, you need to do the following:

1) Make sure the files are all in the jni folder
2) Create an Android.mk file for each library to be compiled
3) OPTIONAL: Create an Application.mk file that sets various compilation flags
4) compile using the ndk-build shell script. Configuration/Make files will not work correctly because an alternate toolchain is used for android.
jonbonazza is online now  
Reply With Quote
Old November 10th, 2011, 09:35 AM   #5 (permalink)
New Member
 
Join Date: Nov 2011
Posts: 3
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by t.elimpus View Post
This is the way that has worked for me, hope it helps you too.
Tony.
Tony -- I got lsusb working, but when I attempt to write anything to the USB peripheral, the application restarts. Were you able to send commands to the USB peripheral without having to first get root access?
-Matt
ndnfan is offline  
Reply With Quote
Old February 8th, 2012, 11:04 AM   #6 (permalink)
New Member
 
Join Date: Nov 2011
Posts: 3
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is how I got libusb working in Android without rooting the phone.
1) In Java, enumerate the USB and find the device you want. Reference this URL: USB Host | Android Developers
2) Once you find the device, get the file descriptor to it. Reference this method:UsbDeviceConnection | Android Developers
3) Pass the file descriptor to the ported libusb code. I had to change the libusb code slightly to accept a file descriptor instead of trying to open its own descriptor.

Once that's complete, I was able to make use of libusb w/o issue. As far as I know, this is the only way to get isochronous USB support on Android.
ndnfan is offline  
Reply With Quote
Old February 8th, 2012, 05:11 PM   #7 (permalink)
Senior Member
 
Join Date: Jul 2010
Posts: 977
 
Device(s): Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Thanks: 52
Thanked 199 Times in 144 Posts
Default

Please note that USB Host capabilities were not added until Android 4.0, so if your application requires those capabilities, you will need to either (a) purchase an android 4.0 device for testing, or (b) root your current device and find a functional Android 4.0 ROM to install on it.
jonbonazza is online now  
Reply With Quote
Old April 2nd, 2012, 02:25 PM   #8 (permalink)
New Member
 
Join Date: Apr 2012
Posts: 1
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by ndnfan View Post
Here is how I got libusb working in Android without rooting the phone.
1) In Java, enumerate the USB and find the device you want. Reference this URL:
2) Once you find the device, get the file descriptor to it. Reference this method:
3) Pass the file descriptor to the ported libusb code. I had to change the libusb code slightly to accept a file descriptor instead of trying to open its own descriptor.

Once that's complete, I was able to make use of libusb w/o issue. As far as I know, this is the only way to get isochronous USB support on Android.
Can you explain a bit better what changes were made to libusb to make this work? Or better yet, source? Thanks!
jazzatar is offline  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 11:44 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo