How to use Android.mk template in Android
This article mainly introduces how to use Android.mk template in Android related knowledge, content detailed and easy to understand, simple and fast operation, has a certain reference value, I believe everyone read this article how to use Android.mk template in Android will have some gains, let's take a look at it.
Android development Android.mk template example detailed explanation
1. How to automatically add a list of source files to compile
2. How to add third-party static library, dynamic library dependencies
3. How to construct a complete NDK engineering framework
Suppose our project depends on libmath.a, libjson.a, libffmpeg.so these third-party library files, the project contains the following modules: algorithm, core, network, utils, tests, each module has several.c/.h files, we want to compile the whole project into a dynamic library, and through the native_sdk.c function to provide a call interface to the Java layer.
Then, we can divide the jni directory of Android project as follows:
The corresponding Android.mk file is written as follows (Note: The project file can be viewed online in my Github (@Jhuster/Android) or downloaded in the attachment at the end of this blog post):
LOCAL_PATH := $(call my-dir)3RD_INC_DIR = $(LOCAL_PATH)/3rd/inc3RD_LIB_DIR = $(LOCAL_PATH)/3rd/libs # Prebuild the 3rd libraries include $(CLEAR_VARS)LOCAL_MODULE := mathLOCAL_SRC_FILES := $(3RD_LIB_DIR)/libmath.ainclude $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS)LOCAL_MODULE := jsonLOCAL_SRC_FILES := $(3RD_LIB_DIR)/libjson.ainclude $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS)LOCAL_MODULE := ffmpegLOCAL_SRC_FILES := $(3RD_LIB_DIR)/libffmpeg.soinclude $(PREBUILT_SHARED_LIBRARY) # Build native sdk include $(CLEAR_VARS) LOCAL_MODULE := native_sdk LOCAL_SRC_FILES := \ $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/src/algorithm/*.c)) \ $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/src/core/*.c)) \ $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/src/network/*.c)) \ $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/src/utils/*.c)) \ $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/src/*.c)) LOCAL_C_INCLUDES := $(3RD_INC_DIR)LOCAL_C_INCLUDES := $(LOCAL_PATH)/src LOCAL_C_INCLUDES := $(LOCAL_PATH)/src/algorithmLOCAL_C_INCLUDES += $(LOCAL_PATH)/src/coreLOCAL_C_INCLUDES += $(LOCAL_PATH)/src/networkLOCAL_C_INCLUDES += $(LOCAL_PATH)/src/utils LOCAL_CFLAGS := -DANDROID LOCAL_LDLIBS := -llog LOCAL_STATIC_LIBRARIES := math jsonLOCAL_SHARED_LIBRARIES := ffmpeg include $(BUILD_SHARED_LIBRARY) # Build tests include $(CLEAR_VARS) LOCAL_MODULE := test.outLOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/tests/*.c) LOCAL_CFLAGS := -DANDROID LOCAL_C_INCLUDES := $(LOCAL_PATH)/src LOCAL_LDLIBS := -llog -fPIE -pieLOCAL_SHARED_LIBRARIES:= native_sdkinclude $(BUILD_EXECUTABLE) About" How to use Android.mk template in Android" The content of this article is introduced here, thank you for reading! I believe everyone has a certain understanding of "how to use Android.mk template in Android" knowledge. If you still want to learn more knowledge, please pay attention to the industry information channel.