Android.mk

Executable Template

LOCAL_PATH:= $(call my-dir) # call function my-dir will return the path of Android.mk

include $(CLEAR_VARS) # clean all variables mainly started with LOCAL_

LOCAL_SRC_FILES:= foo.c # Source file list

LOCAL_MODULE:= foo # The name of executable binary

include $(BUILD_EXECUTABLE) # Start to build executable binary

Shared Library Template

LOCAL_PATH:= $(call my-dir) # call function my-dir will return the path of Android.mk

include $(CLEAR_VARS) # clean all variables mainly started with LOCAL_

LOCAL_SRC_FILES:= foo.c bar.c # Source file list

LOCAL_MODULE:= libfoo # The name of shared library

LOCAL_PRELINK_MODULE := false # Prevent from prelink error

include $(BUILD_SHARED_LIBRARY) # Start to build shared library

Static Library Template

LOCAL_PATH:= $(call my-dir) # call function my-dir will return the path of Android.mk

include $(CLEAR_VARS) # clean all variables mainly started with LOCAL_

LOCAL_SRC_FILES:= foo.c bar.c # Source file list

LOCAL_MODULE:= libbar # The name of static library

LOCAL_PRELINK_MODULE := false # Prevent from prelink error

include $(BUILD_STATIC_LIBRARY) # Start to build static library

Use other shared library

LOCAL_SHARED_LIBRARIES := libfoo

Use other static library

    • LOCAL_STATIC_LIBRARIES

      • These are the static libraries that you want to include in your module.

      • Mostly, we use shared libraries, but there are a couple of places, like executables in sbin and host executables where we use static libraries instead.

LOCAL_STATIC_LIBRARIES := libbar

    • LOCAL_WHOLE_STATIC_LIBRARIES

      • These are the static libraries that you want to include in your module without allowing the linker to remove dead code from them.

      • This is mostly useful if you want to add a static library to a shared library and have the static library's content exposed from the shared library.

LOCAL_WHOLE_STATIC_LIBRARIES := libbar

Include path list

LOCAL_C_INCLUDES += \

usr/include \

usr/local/include \

$(LOCAL_PATH)/include

Use c/cpp/cxx/ld flags

LOCAL_CFLAGS += -DONLY_C_NEEDED

LOCAL_CXXFLAGS += -DONLY_CXX_NEEDED

LOCAL_CPPFLAGS += -DBOTH_C_CXX_NEEDED

LOCAL_LDFLAGS += -Wl,--exclude-libs=libgcc_eh.a

LOCAL_LDLIBS += -lpthread

Call subdir's Android.mk

    • Not recursively, just the directly sudir.

include $(call all-subdir-makefiles)

    • Notice

      • Don't use this with `include $(BUILD_EXECUTABLE/BUILD_SHARED_LIBRARY/BUILD_STATIC_LIBRARY) at the same Android.mk, there are some bugs.