大家都知道在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的值除外,然后定义源文件,头文件,接着是编译选项参数,紧接着是编译生成的文件名,最后是生成的文件类型.