如何使用Ndk为Android应用程序构建ADB

时间:2014-12-10 10:41:29

标签: android android-ndk adb

我想用NDK构建Android ADB,以便获得的.so可以在我的项目中使用 .mk文件如下:

# Copyright 2005 The Android Open Source Project
#
# Android.mk for adb
#

LOCAL_PATH:= $(call my-dir)
#adbd device daemon
# =========================================================

include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
adb.c \
fdevent.c \
transport.c \
transport_local.c \
transport_usb.c \
adb_auth_client.c \
sockets.c \
services.c \
file_sync_service.c \
jdwp_service.c \
framebuffer_service.c \
remount_service.c \
usb_linux_client.c

LOCAL_CFLAGS := \
-O2 \
-g \
-DADB_HOST=0 \
-D_XOPEN_SOURCE \
-D_GNU_SOURCE \
-Wall -Wno-unused-parameter -Werror -Wno-deprecated-declarations \

ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
LOCAL_CFLAGS += -DALLOW_ADBD_ROOT=1
endif

LOCAL_MODULE := adbd

LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT_SBIN)
LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)

LOCAL_STATIC_LIBRARIES := liblog libcutils libc libmincrypt libselinux
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
include $(BUILD_EXECUTABLE)

但我无法通过android-ndk-r9c构建它

这种方式可行吗? 我该怎么办?

任何人都可以帮助我吗?

建筑期间的错误是:

jni/adb.c:31:0:
jni/sysdeps.h: In function 'adb_shutdown':
jni/sysdeps.h:363:5: error: implicit declaration of function 'shutdown' [-Werror=implicit-            function-declaration]
jni/sysdeps.h:363:25: error: 'SHUT_RDWR' undeclared (first use in this function)
jni/sysdeps.h:363:25: note: each undeclared identifier is reported only once for each function it appears in
jni/sysdeps.h: At top level:
jni/sysdeps.h:418:81: error: unknown type name 'socklen_t'
jni/sysdeps.h: In function 'adb_socket_setbufsize':
jni/sysdeps.h:453:5: error: implicit declaration of function 'setsockopt' [-Werror=implicit-function-declaration]
jni/sysdeps.h: In function 'unix_socketpair':
jni/sysdeps.h:465:5: error: implicit declaration of function 'socketpair' [-Werror=implicit-function-declaration]
jni/sysdeps.h: In function 'adb_socketpair':
jni/sysdeps.h:472:36: error: 'SOCK_STREAM' undeclared (first use in this function)
In file included from jni/private/android_filesystem_config.h:33:0,
             from jni/adb.c:39:
jni/private/android_filesystem_capability.h: At top level:
jni/private/android_filesystem_capability.h:37:16: error: redefinition of 'struct __user_cap_header_struct'
D:/cygwin/android-ndk-r9c/platforms/android-5/arch-arm/usr/include/linux/capability.h:20:16: note: originally defined here
D:/NDK/android-ndk-r10c/samples/hello-jni/jni/private/android_filesystem_capability.h:40:11: error: conflicting types for 'cap_user_header_t'
D:/cygwin/android-ndk-r9c/platforms/android-5/arch-arm/usr/include/linux/capability.h:23:11: note: previous declaration of 'cap_user_header_t' was here
D:/NDK/android-ndk-r10c/samples/hello-jni/jni/private/android_filesystem_capability.h:42:16: error: redefinition of 'struct __user_cap_data_struct'
D:/cygwin/android-ndk-r9c/platforms/android-5/arch-arm/usr/include/linux/capability.h:25:16: note: originally defined here
D:/NDK/android-ndk-r10c/samples/hello-jni/jni/private/android_filesystem_capability.h:46:11: error: conflicting types for 'cap_user_data_t'
D:/cygwin/android-ndk-r9c/platforms/android-5/arch-arm/usr/include/linux/capability.h:29:11: note: previous declaration of 'cap_user_data_t' was here
D:/NDK/android-ndk-r10c/samples/hello-jni/jni/private/android_filesystem_capability.h:70:0: error: "_LINUX_CAPABILITY_VERSION" redefined [-Werror]
D:/cygwin/android-ndk-r9c/platforms/android-5/arch-arm/usr/include/linux/capability.h:18:0: note: this is the location of the previous definition
D:/NDK/android-ndk-r10c/samples/hello-jni/jni/adb.c:40:28: fatal error: sys/capability.h: No such file or directory
cc1.exe: all warnings being treated as errors

我试过用linux中的ndk构建它 在向floder添加coressphonding lib之后,一些erorrs已经解决了 但是重新定义仍然存在 我注释掉了redifinition结构,但是出现了新的问题:

linux/capability.h:35:10: error:expected '=', ',' , 'j','asm' or'__attribute__' before '*' token } __user * cap_user_header_t

顺便说一下,我真正想要的是在我的apk中运行adb命令,例如“adb install”。我需要将整个adbd程序移动到我的项目中吗?有没有办法实现这个目标?

2 个答案:

答案 0 :(得分:0)

这是不可能的,adbd依赖于NDK未公开的系统库,其中一些在平台版本之间发生了变化。此外,它需要以适当的权限运行才能正常工作,这是您无法通过应用程序执行的操作。

答案 1 :(得分:0)

您可以从android设备的源代码构建adb和fastboot。
使用此构建脚本github
在此版本库中,您可以看到arm-v7a和arm64的预编译二进制文件