Android.mk file usage parsing

b8d1b652e26a73b04611727d5c977785.gif

Learn with you for lifeXi, this is Programmer Android

Recommended classic articles. By reading this article, you will gain the following knowledge points:

1. Introduction to Android.mk
2. Basic format of Android.mk 3.
In-depth study of Android.mk 14.
In-depth study of Android.mk
25. In-depth study of Android.mk
36. Android.mk judgment statements
7. References

1. Introduction to Android.mk

Android.mk is a makefile provided by Android. Note that it is used to compile and generate files such as (exe, so, a, jar, apk).

50306d0d1180f94a697446beb27371b1.jpeg

Android.mk generated file

2. Basic format of Android.mk

The basic format of Android.mk is as follows

# 定义模块当前路径
LOCAL_PATH := $(call my-dir)  
#清空当前环境变量
include $(CLEAR_VARS)  
................  
# 引入头文件等
LOCAL_xxx       := xxx
#编译生成的文件名  
LOCAL_MODULE    := hello  
#编译该模块所需的源码
LOCAL_SRC_FILES := hello.c  
#引入jar包等
LOCAL_xxx       := xxx  
................  
#编译生成文件的类型 
#LOCAL_MODULE_CLASS  、JAVA_LIBRARIES
#APPS 、 SHARED_LIBRARIES
#EXECUTABLES 、 ETC
include $(BUILD_EXECUTABLE)

3. Android.mk in-depth study 1

Multiple target files can be compiled using Android.mk:

f07b6158cad1b741c112aeedb453a0d5.jpeg

Android.mk compiles multiple target files

Compile dynamic library

C/C++ files are compiled to generate static library .so files for reference as follows

LOCAL_PATH := $(call my-dir)    
include $(CLEAR_VARS)    
# 生成libhell.so
LOCAL_MODULE = libhello    

LOCAL_CFLAGS = $(L_CFLAGS)    
LOCAL_SRC_FILES = hello.c  
LOCAL_C_INCLUDES = $(INCLUDES) 
LOCAL_SHARED_LIBRARIES := libcutils    
LOCAL_COPY_HEADERS_TO := libhello   
LOCAL_COPY_HEADERS := hello.h   

#编译动态库 BUILD_SHARED_LIBRARY

include $(BUILD_SHARED_LIBRARY)

Compile static library

C/C++ files are compiled to generate static libraries.a file reference is as follows

#编译静态库    
LOCAL_PATH := $(call my-dir)    
include $(CLEAR_VARS)    
# 生成libhell.a
LOCAL_MODULE = libhello

LOCAL_CFLAGS = $(L_CFLAGS)    
LOCAL_SRC_FILES = hello.c    
LOCAL_C_INCLUDES = $(INCLUDES)    
LOCAL_SHARED_LIBRARIES := libcutils    
LOCAL_COPY_HEADERS_TO := libhello   
LOCAL_COPY_HEADERS := hellos.h   

 # 编译 静态库    BUILD_STATIC_LIBRARY
include $(BUILD_STATIC_LIBRARY)

4. Android.mk in-depth study 2

85fbd0935444b4440eb555bf953a8ba4.jpeg

Android.mk reference resources

Reference static library
LOCAL_STATIC_LIBRARIES += libxxxxx

LOCAL_STATIC_LIBRARIES := \
    ...
    libxxx2 \
    libxxx \

Reference dynamic library
LOCAL_SHARED_LIBRARIES += libxxxxx

LOCAL_SHARED_LIBRARIES := liblog libnativehelper libGLESv2

Reference third-party library files
LOCAL_LDFLAGS:=-L/PATH -Lxxx

LOCAL_LDFLAGS := $(LOCAL_PATH)/lib/libtest.a

Reference third-party header files
LOCAL_C_INCLUDES :=path

eg:

LOCAL_C_INCLUDES = $(INCLUDES)

5. Android.mk in-depth study 3

6caac2bad2bda368d3bb8b9ca360a3fa.jpeg

Android.mk in-depth study three

Compile apk

LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
  LOCAL_SRC_FILES := $(call all-subdir-java-files)
  # 生成hello apk
  LOCAL_PACKAGE_NAME := hello
  include $(BUILD_PACKAGE)

Compile jar package

LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
  LOCAL_SRC_FILES := $(call all-subdir-java-files)
  # 生成 hello
  LOCAL_MODULE := hello
  # 编译生成静态jar包
  include $(BUILD_STATIC_JAVA_LIBRARY)
  #编译生成共享jar
  include $(BUILD_JAVA_LIBRARY)
  • Static jar package:

include $(BUILD_STATIC_JAVA_LIBRARY)
JAR files packaged using .class files can be run in any Java virtual machine

  • Dynamic jar package:

include $(BUILD_JAVA_LIBRARY)
Jar files are packaged using .dex based on static jar packages. .dex is the file format used by the android system.

APK dependency jar

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# 静态jar包
LOCAL_STATIC_JAVA_LIBRARIES := static-library
#动态jar包
LOCAL_JAVA_LIBRARIES := share-library

LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := hello
include $(BUILD_PACKAGE)

Precompiled jar package

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#指定编译生成的文件类型
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_MODULE := hello
LOCAL_SRC_FILES :=  $(call all-subdir-java-files)
# 预编译
include $(BUILD_PREBUILT)

Precompiled file types are as follows:

  • 1.LOCAL_MODULE_CLASS:
    Compile file type

  • 2.JAVA_LIBRARIES:
    dex archive file

  • 3.APPS:
    APK file

  • 4.SHARED_LIBRARIES:
    dynamic library files

  • 5.EXECUTABLES:
    Binary files

  • 6.ETC:
    Other file formats

6. Android.mk judgment statements

Decision statements in Android.mk

ifeq($(VALUE), x)   #ifneq
  do_yes
else
  do_no
endif

ifeq/ifneq: perform related compilation based on judgment conditions

references:

[Tencent Documentation] Android Framework Knowledge Base
https://docs.qq.com/doc/DSXBmSG9VbEROUXF5

Friendly recommendation:

Collection of useful information on Android development

At this point, this article has ended. The editor thinks the article is reprinted from the Internet and is excellent. You are welcome to click to read the original article and support the original author. If there is any infringement, please contact the editor to delete it. Your suggestions and corrections are welcome. We look forward to your attention and thank you for reading, thank you!

5befe055ae421216736e8c7f9e838f6e.jpeg

Click to read the original article and like the boss!

Guess you like

Origin blog.csdn.net/wjky2014/article/details/131693042