1 概述
大家都知道在Linux下編輯經常要寫一個Makefile文件, 可以把這個Makefile文件理解成一個編譯配置文件,它保存著如何編譯的配置信息,即指導編譯器如何來編譯程序,並決定編譯的結果是什麼。而在Android下的Android.mk文件也是類型的功能,顧名思義,從名字上就可以猜測得到,Android.mk文件是針對Android的Makefile文件.具體來說:該文件是GNU Makefile的一小部分,會被編譯系統解析一次或多次。你可以在每一個Android.mk file中定義一個或多個模塊,你也可以在幾個模塊中使用同一個源代碼文件。編譯系統為你處理許多細節問題。
2 Android.mk的整體結構
例如一個Android.mk的內容如下:
- LOCAL_PATH:= $(call my-dir)
- include $(CLEAR_VARS)
-
- LOCAL_SRC_FILES:= \
- android_media_MediaPlayer.cpp \
- android_media_MediaRecorder.cpp \
- android_media_MediaScanner.cpp \
- android_media_MediaMetadataRetriever.cpp \
- android_media_ResampleInputStream.cpp \
- android_media_MediaProfiles.cpp \
- android_media_AmrInputStream.cpp \
- android_media_Utils.cpp \
- android_mtp_MtpDatabase.cpp \
- android_mtp_MtpDevice.cpp \
- android_mtp_MtpServer.cpp \
-
- LOCAL_SHARED_LIBRARIES := \
- libandroid_runtime \
- libnativehelper \
- libutils \
- libbinder \
- libmedia \
- libskia \
- libui \
- libcutils \
- libgui \
- libstagefright \
- libcamera_client \
- libsqlite \
- libmtp \
- libusbhost \
- libexif
-
- LOCAL_C_INCLUDES += \
- external/jhead \
- external/tremor/Tremor \
- frameworks/base/core/jni \
- frameworks/base/media/libmedia \
- frameworks/base/media/libstagefright/codecs/amrnb/enc/src \
- frameworks/base/media/libstagefright/codecs/amrnb/common \
- frameworks/base/media/libstagefright/codecs/amrnb/common/include \
- frameworks/base/media/mtp \
- $(PV_INCLUDES) \
- $(JNI_H_INCLUDE) \
- $(call include-path-for, corecg graphics)
-
- LOCAL_CFLAGS +=
-
- LOCAL_LDLIBS := -lpthread
-
- LOCAL_MODULE:= libmedia_jni
-
- include $(BUILD_SHARED_LIBRARY)
-
- # build libsoundpool.so
- # build libaudioeffect_jni.so
- include $(call all-makefiles-under,$(LOCAL_PATH))
首先必須定義好LOCAL_PATH變量。然後清除所有LOCAL_XX變量的值,當然LOCAL_PATH的值除外,然後定義源文件,頭文件,接著是編譯選項參數,緊接著是編譯生成的文件名,最後是生成的文件類型.