出處: https://codingnote.blogspot.tw/2017/05/androidmk.html
用Android.mk編譯C/C++程式
LOCAL_PATH:= $(call my-dir) # call function my-dir will return the path of Android.mk
include $(CLEAR_VARS) # 清除內建以LOCAL_開頭的變數
LOCAL_SRC_FILES:= foo.c # 程式碼檔案, 用空格,如果要換行,必須在每行結尾打\
LOCAL_MODULE:= foo # 本模組名稱, 整個AOSP內的模組名稱必須不同
include $(BUILD_EXECUTABLE) # 模組編譯成執行檔
裝置的prebuilt模組與檔案
可以在device/{device vender}/{device model name}/vendor.mk要求一定要編譯的模組,和要求拷貝指定的Prebuilt檔案PRODUCT_PACKAGES += libfoo
PRODUCT_COPY_FILES += \
$(call find-copy-subdir-files,*,vendor/mycom/prebuilt/system,system) \
$(call find-copy-subdir-files,*,vendor/yourcom/prebuilt/system,system)
為Prebulit library設定
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := libservice.so
LOCAL_MODULE := libservice
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
為多個Prebuilt library設定
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PREBUILT_LIBS := libaservice.so liblkk.so Dir_name/libfoo.so
include $(BUILD_MULTI_PREBUILT)
設定一個Prebuilt執行檔
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := mybin
LOCAL_MODULE := mybin
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)
對一個Prebuilt的APK簽章
include $(CLEAR_VARS)
LOCAL_MODULE := AppName # APP的模組名稱
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk #如果模組名稱和檔案不一樣,這裡請改成檔案名稱
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform #指定簽章的類型
include $(BUILD_PREBUILT)
遞迴的往下層目錄處理
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include $(call all-makefiles-under,$(LOCAL_PATH))
印出platform及SDK版本
$(warning PLATFORM_VERSION [$(PLATFORM_VERSION)] PLATFORM_SDK_VERSION [$(PLATFORM_SDK_VERSION)])
增加C/C++編譯器的flag
LOCAL_CFLAGS += -Wall
這功能比較常用的是增加Macro定義的功能
LOCAL_CFLAGS += -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION)
增加C/C++的header引用目錄
增加前模組要使用的C/C++的Static Library
LOCAL_STATIC_LIBRARIES := \
libstagefright_nuplayer \
libstagefright_rtsp
增加目前模組要使用的C/C++的Shared Library
LOCAL_SHARED_LIBRARIES := \
libbinder \
libcamera_client