build libusb for Android

crazy_baoli發表於2019-01-10

平臺

libusb版本:libusb-1.0.20

Ubuntu: 14.04

NDK:android-ndk-r9d

測試手機:三星S4

開發板:GD32

==================

 

Building:

---------

 

To build libusb for Android do the following:

 

1. Download the latest NDK from:

http://developer.android.com/tools/sdk/ndk/index.html

 

2. Extract the NDK.

 

3. Open a shell and make sure there exist an NDK global variable

set to the directory where you extracted the NDK.

 

4. Change directory to libusb's "android/jni"

 

5. Run "ndk-build".(需要設定環境變數或者使用絕對路徑)

 

The libusb library, examples and tests can then be found in:

"android/libs/$ARCH"

 

Where $ARCH is one of:

armeabi(測試使用此架構,armeabi-v7a未測試)

armeabi-v7a

x86

 

Installing:

-----------

For a rooted device it is possible to install libusb into the system

image of a running device:

 

1. Connect the device to a machine running ADB.

 

2. Execute the following commands on the machine

running ADB:

 

# Make the system partition writable

adb shell su -c "mount -o remount,rw /system"

 

# Install libusb

adb push obj/local/armeabi/libusb1.0.so /sdcard/

adb shell su -c "cat > /system/lib/libusb1.0.so < /sdcard/libusb1.0.so"

adb shell rm /sdcard/libusb1.0.so

 

 

Test:

-----------

1. new project file

1) 任意目錄下mkdir libusb_for_android

2) 在libusb_for_android/ 新增libusb1.0.so、libusb.h、usbtest2.0.c,並且新建jni目錄

3) 在jni/ 新建Android.mk和Application.mk

 

2. 在jni/下執行:/opt/android_ndk/android-ndk-r9d/ndk-build

在libusb_for_android/libs/armeabi/下即可找到產生的可執行檔案usbtest

 

3. 將usbtest adb push到手機的sdcard/

 

4. 將開發板和手機相連,然後再手機的超級終端下執行:./usbtest

 

相關文章