Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Android.mk template in Android

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report