libusb: android上集成libusb库
1. 下载libusb库。
可以到libusb库的官网(https://libusb.info/)或者是其官方的github仓库(https://github.com/libusb/libusb/releases)上下载最新的libusb库源码。
2. 添加libusb库到android studio项目中。
这里以源码编译的方式添加,使用的仍然是ndk-build的方式,而非cmake,使用源码编译的好处在于,可以随时调试libusb库的源码,方便加log。
2.1 在app/src/main目录下新建一个jni目录,用于存放libusb库的源代码。
2.2 打开app目录下的build.gradle文件,指定JNI目录:

2.3 在jni目录下新建libusb-support目录和makefile文件,libusb-support目录用于存放libusb库的源代码。
这里单独新建一个libusb-support目录的目的在于,将来可能会有很多个第三方模块,比如libusb,libyuv, sdl,分目录存放可以划分得更清楚,可以直接把libusb的代码放到jni目录下,只要makefile能找到就行。
Android.mk
#
# Copyright (c) Realsil.Inc. All rights reserved.
#
include $(call all-subdir-makefiles)
Application.mk
#
# Copyright (c) SEP.Inc. All rights reserved.
# APP_ABI := all APP_LDFLAGS := -llog
最终目录结构如下:
2.3 拷贝libusb库的源代码到libusb-support目录
打开下载的libusb库源代码,找到libusb文件夹,将整个文件拷贝到libusb-support目录下,我下载的是1.0.23版本:
打开android文件夹,拷贝config.h文件到libusb-support目录下
打开jni文件夹,拷贝Android.mk、libusb.mk文件到libusb-support目录下:
最终目录结构如下:

接下来修改Android.mk和libusb.mk文件,默认编译出来的库会包含一些测试用例和示例代码,我们不需要它。
修改Android.mk, 注释掉example.mk和tests.mk
# Android build config for libusb, examples and tests
# Copyright © - RealVNC Ltd. <toby.gray@realvnc.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., Franklin Street, Fifth Floor, Boston, MA - USA
# LOCAL_PATH:= $(call my-dir) include $(LOCAL_PATH)/libusb.mk # include $(LOCAL_PATH)/examples.mk
# include $(LOCAL_PATH)/tests.mk
修改libusb.mk, 更新当前源代码的位置:
# Android build config for libusb
# Copyright © - RealVNC Ltd. <toby.gray@realvnc.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., Franklin Street, Fifth Floor, Boston, MA - USA
# LOCAL_PATH:= $(call my-dir)
LIBUSB_ROOT_REL:= .
LIBUSB_ROOT_ABS:= $(LOCAL_PATH) # libusb include $(CLEAR_VARS) LIBUSB_ROOT_REL:= .
LIBUSB_ROOT_ABS:= $(LOCAL_PATH) LOCAL_SRC_FILES := \
$(LIBUSB_ROOT_REL)/libusb/core.c \
$(LIBUSB_ROOT_REL)/libusb/descriptor.c \
$(LIBUSB_ROOT_REL)/libusb/hotplug.c \
$(LIBUSB_ROOT_REL)/libusb/io.c \
$(LIBUSB_ROOT_REL)/libusb/sync.c \
$(LIBUSB_ROOT_REL)/libusb/strerror.c \
$(LIBUSB_ROOT_REL)/libusb/os/linux_usbfs.c \
$(LIBUSB_ROOT_REL)/libusb/os/poll_posix.c \
$(LIBUSB_ROOT_REL)/libusb/os/threads_posix.c \
$(LIBUSB_ROOT_REL)/libusb/os/linux_netlink.c \
$(LIBUSB_ROOT_REL)/libusb/realsil_usb_audio.c \
$(LIBUSB_ROOT_REL)/libusb/jnihelp.cpp LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/ \
$(LIBUSB_ROOT_ABS)/libusb \
$(LIBUSB_ROOT_ABS)/libusb/os LOCAL_EXPORT_C_INCLUDES := \
$(LIBUSB_ROOT_ABS)/libusb LOCAL_LDLIBS := -llog LOCAL_MODULE := usb include $(BUILD_SHARED_LIBRARY)
其中的 realsil_usb_audio.c 和 jnihelp.cpp是我自己添加的调用libusb库的code, 可不用在意。
3. 编译链接
在任意文件夹下右击,选择“Link C++ Project with Gradle”
在Build System的下拉列表中选择ndk-build的编译方式,并指定所有模块的makefile文件位置:

点OK, 此时编译系统就会自动开始构建,注意到此时文件夹的目录颜色已修改,且app目录下的build.gradle文件也进行了更新。

接下来就可以在相应的C代码里编写调用libusb库的相应逻辑了。
参考链接:
1. Android从USB声卡录制高质量音频-----USB API测试
2. Android从USB声卡录制高质量音频-----使用libusb读取USB声卡数据
libusb: android上集成libusb库的更多相关文章
- Android中集成第三方库的方法和问题
Android中集成第三方库的方法和问题 声明: 1. 本文參考了网上同学们的现有成果,在此表示感谢,參考资料在文后有链接. 2. 本文的重点在第三部分,是在开发中遇到的问题及解决的方法.第一,第二部 ...
- 最牛逼android上的图表库MpChart(三) 条形图
最牛逼android上的图表库MpChart三 条形图 BarChart条形图介绍 BarChart条形图实例 BarChart效果 最牛逼android上的图表库MpChart(三) 条形图 最近工 ...
- 最牛逼android上的图表库MpChart(二) 折线图
最牛逼android上的图表库MpChart二 折线图 MpChart折线图介绍 MpChart折线图实例 MpChart效果 最牛逼android上的图表库MpChart(二) 折线图 最近工作中, ...
- 最牛逼android上的图表库MpChart(一) 介绍篇
最牛逼android上的图表库MpChart一 介绍篇 MpChart优点 MpChart是什么 MpChart支持哪些图表 MpChart效果如何 最牛逼android上的图表库MpChart(一) ...
- Android上安装第三方库
在Android sdk中安装预安装第三方的(动态,静态)库,到系统中,方便模块无差别的使用. Android.mk include $(CLEAR_VARS) LOCAL_MODULE_TAGS : ...
- 系列篇|编译可在Android上运行的依赖库(一):glib库
前言 这是系列文章,它们由<编译可在Android上运行的glib库>及其他4篇文章组成,这4篇文章在“编译依赖库”一节中列出.由于glib库依赖于其他第三方库,所以需要先将依赖的第三方库 ...
- Kotlin与Android SDK 集成(KAD 05)
作者:Antonio Leiva 时间:Dec 19, 2016 原文链接:https://antonioleiva.com/kotlin-integrations-android-sdk/ 使用Ko ...
- 59.Android开源项目及库 (转)
转载 : https://github.com/Tim9Liu9/TimLiu-Android?hmsr=toutiao.io&utm_medium=toutiao.io&utm_so ...
- FFmpeg在Android上的移植之第一步
http://blog.sina.com.cn/s/blog_69a04cf40100x1fr.html 从事多媒体软件开发的人几乎没有不知道FFmpeg的,很多视频播放器都是基于FFmpeg开发的. ...
随机推荐
- Spark实现二次排序
一.代码实现 package big.data.analyse.scala.secondsort import org.apache.log4j.{Level, Logger} import org. ...
- 【函数】wm_concat包的订制
[函数]wm_concat包的订制 1 BLOG文档结构图 2 前言部分 2.1 导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道 ...
- jar - 操作jar包的工具
jar - Manipulates Java Archive (JAR) files. jar命令是一种通用的存档和压缩工具,基于ZIP和ZLIB压缩格式. 常用格式: * 创建jar文件 jar c ...
- rsa公钥和私钥到底哪个才是用来加密,哪个用来解密?
本文转自:91博客:原文地址:http://www.9191boke.com/138589019.html 公钥和私钥在一些银行系统.第三方支付系统SDK中经常会遇到,刚接触公钥私钥的朋友们估计很难区 ...
- 12.基于vue-router的案例
案例分析 用到的路由技术要点: 路由的基础用法 嵌套路由 路由重定向 路由传参 编程式导航 根据项目的整体布局划分好组件结构,通过路由导航控制组件的显示 1.抽离并渲染 App根组件 2.将左侧菜 单 ...
- crc计算工具推荐
比较好的crc计算工具,32位64位系统都可以用的.crc的校验方法也很多.推荐使用 下载地址
- python的程序运行时间
import time start =time.clock() sum= ,): sum=sum+i print(sum ) end = time.clock() print('Running tim ...
- 初学FWT(快速沃尔什变换) 一点心得
FWT能解决什么 有的时候我们会遇到要求一类卷积,如下: Ci=∑j⊕k=iAj∗Bk\large C_i=\sum_{j⊕k=i}A_j*B_kCi=j⊕k=i∑Aj∗Bk此处乘号为普通乘法 ...
- LeetCode 842. Split Array into Fibonacci Sequence
原题链接在这里:https://leetcode.com/problems/split-array-into-fibonacci-sequence/ 题目: Given a string S of d ...
- LeetCode 919. Complete Binary Tree Inserter
原题链接在这里:https://leetcode.com/problems/complete-binary-tree-inserter/ 题目: A complete binary tree is a ...