Android系统源码external添加新模块

本文链接:https://www.jianshu.com/p/1c117e41b915

新建目录external/hello

mkdir external/hello
cd external/hello

新建hello.c

#include   
  
int main()  
{  
    printf("Hello World!\n");  
  
    return 0;  
}  

新建Android.mk,编译bin文件

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := hello
LOCAL_SRC_FILES := $(call all-subdir-c-files)
include $(BUILD_EXECUTABLE)

编译

mmm external/hello/

输出路径:
out/target/product/xxx/system/bin/hello


hello bin

修改Android.mk,编译so文件

写法一

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := hello
LOCAL_SRC_FILES := $(call all-subdir-c-files)
include $(BUILD_SHARED_LIBRARY)

写法二

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE := hello
LOCAL_SRC_FILES := $(call all-subdir-c-files)
include $(BUILD_PREBUILT)

输出路径:
out/target/product/xxx/obj/lib/hello.so


hello.so

修改Android.mk,编译a文件

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := hello
LOCAL_SRC_FILES := $(call all-subdir-c-files)
include $(BUILD_STATIC_LIBRARY)

输出路径:
out/target/product/xxx/obj/STATIC_LIBRARIES/hello_intermediates/hello.a


hello.a

报错

编译报错

No rule to make target `out/target/product/xxx/obj/lib/libc.so'

解:
先编译整个工程

make -j8

设置BUILD_PREBUILT编译报错

build/core/base_rules.mk:97: *** external/hello: LOCAL_MODULE_CLASS must contain exactly one word, not "".  Stop.

解:
添加LOCAL_MODULE_CLASS

参考

例说如何编译android模块 - Eliot_shao的专栏 - CSDN博客
https://blog.csdn.net/eliot_shao/article/details/50441219

Android编译环境(转) - allenpettle - ITeye博客
https://allenshao.iteye.com/blog/616052

android编译系统makefile(Android.mk)写法 - 飞翔的熊猫 - 博客园
https://www.cnblogs.com/hesiming/archive/2011/03/15/1984444.html

你可能感兴趣的:(Android系统源码external添加新模块)