将Android下的可执行文件以静态库的形式进行编译

2019-07-13 06:26发布

这里以toolbox为例,只需要稍加修改Android.mk就可以编译出一个静态链接的toolbox。以下diff文件就是改动信息。 diff --git a/system/core/toolbox/Android.mk b/system/core/toolbox/Android.mk index 086ba0d..d5aef3b 100755 --- a/system/core/toolbox/Android.mk +++ b/system/core/toolbox/Android.mk LOCAL_SRC_FILES := grep/grep.c grep/fastgrep.c grep/file.c grep/queue.c grep/util.c LOCAL_SHARED_LIBRARIES := libcutils libc libusbhost +LOCAL_STATIC_LIBRARIES := libcutils libc libusbhost LOCAL_C_INCLUDES := bionic/libc/bionic LOCAL_C_INCLUDES += external/libselinux/include endif +LOCAL_FORCE_STATIC_EXECUTABLE := true LOCAL_MODULE := toolbox # Including this will define $(intermediates). 然后进行编译就自动编译成了静态链接的了。 $ file out/target/product/xxx/system/bin/toolbox
out/target/product/xxx/system/bin/toolbox: ELF 32-bit LSB executable, ARM,
version 1 (SYSV), statically linked, stripped
由这里我们可以想到对于Android下的可执行文件,只需按照相同的方法将该Andoird.mk进行修改一下,就可以移植到普通的Linux系统了。