繁体   English   中英

如何使用Ndk为Android Apps构建ADB

[英]How can I build ADB with Ndk for Android Apps

我想用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

在将coressphonding lib添加到floder之后,我尝试通过ndk在linux中构建它,解决了一些错误,但是重定义仍然存在,我注释了重定义结构,但是出现了新问题:

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

顺便说一句,我真正想要的是在apk中运行adb命令,例如“ adb install”。是否需要将整个adbd程序移到我的项目中? 有什么办法可以做到这一点?

这是不可能的,adbd依赖于NDK未公开的系统库,其中一些在平台发行版之间已更改。 此外,它需要以适当的特权运行才能正常工作,而这是您无法从应用程序中完成的。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM