porting lib 還是和以前一樣,要先run ./configure. 產生 config.h,然後再自己改成 for android 的配置。
然後加入 Android.mk (兩個)
再修改一下 build error 的 file
我的 config.h:
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* Default visibility */
#define API_EXPORTED __attribute__((visibility("default")))
/* Debug message logging */
/* #undef ENABLE_DEBUG_LOGGING */
/* Message logging */
#define ENABLE_LOGGING 1
/* Define to 1 if you have the header file. */
#define HAVE_DLFCN_H 1
/* Define to 1 if you have the header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the `rt' library (-lrt). */
#define HAVE_LIBRT 1
/* Define to 1 if you have the header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the header file. */
#define HAVE_UNISTD_H 1
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#define LT_OBJDIR ".libs/"
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
/* #undef NO_MINUS_C_MINUS_O */
/* Darwin backend */
/* #undef OS_DARWIN */
/* Linux backend */
#define OS_LINUX /**/
/* Name of package */
#define PACKAGE "libusb"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME "libusb"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "libusb 1.0.8"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "libusb"
/* Define to the home page for this package. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "1.0.8"
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Backend handles timeout */
/* #undef USBI_OS_HANDLES_TIMEOUT */
/* timerfd headers available */
/* #undef USBI_TIMERFD_AVAILABLE */
/* Version number of package */
#define VERSION "1.0.8"
/* Use GNU extensions */
#define _GNU_SOURCE /**/
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
/* #undef inline */
#endif
我的 external/libusb-1.0.0.8/Android.mk:
LOCAL_PATH := $(call my-dir)
subdirs := $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \
libusb \
examples \
))
include $(subdirs)
我的 external/libusb-1.0.0.8/libusb/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS:= tests
LOCAL_PRELINK_MODULE:= false
LOCAL_SRC_FILES:= \
core.c \
descriptor.c \
io.c \
sync.c \
os/linux_usbfs.c
LOCAL_C_INCLUDES += \
external/libusb-1.0.8/ \
external/libusb-1.0.8/libusb/ \
external/libusb-1.0.8/libusb/os
LOCAL_MODULE:= libusb
include $(BUILD_SHARED_LIBRARY)
我的 external/libusb-1.0.0.8/example/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := tests
LOCAL_SRC_FILES := lsusb.c
LOCAL_MODULE := lsusb
LOCAL_C_INCLUDES += external/libusb-1.0.8/
LOCAL_SHARED_LIBRARIES := libc libusb
include $(BUILD_EXECUTABLE)
- download libusb-1.0.0.8, unzip to external (result in a external/libusb-1.0.0.8)
- run ./configure -disable-timerfd
- modify libusb/io.c
加上#define TIMESPEC_TO_TIMEVAL(tv, ts) \ do { \ (tv)->tv_sec = (ts)->tv_sec; \ (tv)->tv_usec = (ts)->tv_nsec / 1000; \ } while (0)
- add 3 Android.mk files
sync to target, run
bash-3.2# lsusb
1d6b:0002 (bus 1, device 1)
1d6b:0002 (bus 2, device 1)
0424:2517 (bus 2, device 2)
0a12:0001 (bus 2, device 3)
13fe:1d00 (bus 2, device 4)
不用 mount usbfs /proc/bus/usbfs 就可以動作(?)
查 libusb/os/linux_usbfs.c :
static const char *find_usbfs_path(void)
{
const char *path = "/dev/bus/usb";
const char *ret = NULL;
if (check_usb_vfs(path)) {
ret = path;
} else {
path = "/proc/bus/usb";
if (check_usb_vfs(path))
ret = path;
}
usbi_dbg("found usbfs at %s", ret);
return ret;
}
用的是 /dev/bus/usb2008 這篇 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=483392 有說不要再 mount /proc/bus/usbfs,請直接用 /dev/bus/usb..
但是到現在好像還很多人在用...
2 則留言:
您好,不好意思想冒昧請教一下:
我現在把libusb porting到android 2.3上了,lsusb也可以正常動作,但是找不到方法可以自己寫c code然後編譯成so讓application(java)去call,所以想請教您有辦法嗎?謝謝!
您好,我已經找到解決方法了!也謝謝您,您的網誌幫了我很多忙,謝謝!
張貼留言