Building libusb for Android

Setting Environment Variables

Open a shell and make sure there exist an NDK global variable set to the directory where you extracted the NDK.

1
2
3
4
5
sudo gedit ~/.bashrc

export ANDROID_SDK=<path to Android SDK directory>
export ANDROID_NDK=<path to Android NDK directory>
export PATH=$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$ANDROID_NDK
1
2
3
4
5
6
7
8
9
source ~/.bashrc
ndk-build --version

GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Building
1
cd /libusb/android/jni

ndk-build 的默认值为 none。 您可以使用 Application.mk 文件中的 APP_STL 变量指定 c++_shared、c++static、> none 或 system。例如: APP_STL := c++_shared ndk-build 仅允许为您的应用选择一个运行时,并且只能在 Application.mk 中进行选择。

由于我们希望使用c++_shared,所以我修改/libusb/android/jni/Application.mk文件,添加APP_STL := c++_shared

1
ndk-build