简体   繁体   中英

How can I build ADB with Ndk for Android Apps

I want to build Android ADB with NDK such that the .so that obtained can be used in my project the .mk file is as follow:

# 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)

but i cannot build it by android-ndk-r9c

is this way possible? what should i do ?

could anyone help me ?

the errors during building are :

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

i have tryed build it in by ndk in linux after adding coressphonding lib to the floder some erorrs have been solved however the redifinition is still there i comment out the redifinition struct but new problems comes:

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

By the way, what I realy want is to run the adb command, "adb install" for example, in my apk.Do I need move the entire adbd program to my project? Is there any way to achieve this ?

It's not possible, adbd depends on system libraries that are not exposed by the NDK, some of them have changed between platform releases. Besides, it needs to run with appropriate privileges to work correctly, something you won't be able to do from your application.

you can build adb and fastboot from source for android device.
use this build script, github
in this repo you can see prebuild binary for arm-v7a and arm64

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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