Android knowledge 001 - Android.mk file brief

#第一行肯定要是文件注释了。This file is to build Settings.apk.
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := Settings
LOCAL_CERTIFICATE := platform

include $(BUILD_PACKAGE)

# Use the folloing include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))

The file path is Android.mk package / app / Settings / Android.mk, to analyze the file

GNU Make 'function' macro must be invoked using '$ (call)', they will return the call to the text of the message.

------------------------------------------------------------------------------------------------------------------------------

(1) LOCAL_PATH:= $(call my-dir)

Android.mk file must first define a good LOCAL_PATH variables. It is used to find the source files in the development tree.

Macro function 'my-dir', provided by the compiler system, a return current path (i.e. Android.mk file directory containing the file).

------------------------------------------------------------------------------------------------------------------------------

(2) Android.mk compiler may define a plurality of modules, each module is compiled to include $ (CLEAR_VARS) begins to include $ (BUILD_XXX) ends.

(2.1) include $(CLEAR_VARS)

CLEAR_VARS refers clear_vars.mk, provided by the compiler system, it will make GNU MAKEFILE you clear all variables other than LOCAL_PATH LOCAL_XXX, such as LOCAL_MODULE, LOCAL_SRC_FILES, LOCAL_SHARED_LIBRARIES, LOCAL_STATIC_LIBRARIES and so on.

This is necessary, because all control files are compiled in the same GNU MAKE execution environment, all variables are global.

 

(2.2) include $(BUILD_PACKAGE)      # Tell it to build an APK

$ (BUILD_PACKAGE) is compiled to generate apk package / app / in.

There are several other cases compiled:

include $ (BUILD_STATIC_LIBRARY) expressed compiled into a static library

include $ (BUILD_SHARED_LIBRARY) represents a compiled DLL

include $ (BUILD_EXECUTABLE) represents the compiled executable         

For example, it jumps to the following "extended"

------------------------------------------------------------------------------------------------------------------------------

(3) LOCAL_MODULE_TAGS := optional

Resolution:

LOCAL_MODULE_TAGS :=user eng tests optional

user: only means that the module was compiled in user version

eng: means that the module was compiled in eng only version

tests: only means that the module was compiled version in tests

optional: means that the module under all versions are compiled

The range of debug eng tests optional samples shell_ash shell_mksh. Be careful not to value user, if you want to pre-installed, you should define core.mk.

------------------------------------------------------------------------------------------------------------------------------

(4) LOCAL_SRC_FILES := $(call all-java-files-under, src)

(4.1) if you want to include the java source code, you can call the all-java-files-under get. (This form contains all the java files in the directory local_path)

(4.2) When it comes to C / C ++, LOCAL_SRC_FILES comprises variable must be packaged into compiled C or C ++ source file module. Note here that you can not list the header files and include files, because the compiler will automatically identify the dependent files for you; just a list of source code files passed directly to the compiler just fine.

Defines all-java-files-under macro is build / core / definitions.mk in.

------------------------------------------------------------------------------------------------------------------------------

(5) LOCAL_PACKAGE_NAME := Settings

package name, the name identifies the app or package in the script.

LOCAL_PACKAGE_NAME designated APP application name. It is compiled by the name of apk, example:

LOCAL_PACKAGE_NAME := TestApplicaiton

The translation of the name of the apk is TestApplicaiton.apk

------------------------------------------------------------------------------------------------------------------------------

(6) LOCAL_CERTIFICATE := platform

Behind LOCAL_CERTIFICATE signature file is the file name, indicating Settings.apk an APK required platform key signature

------------------------------------------------------------------------------------------------------------------------------

(7) include $(BUILD_PACKAGE)

In (2.2) has been interpreted as

------------------------------------------------------------------------------------------------------------------------------

(8) include $(call all-makefiles-under,$(LOCAL_PATH))

Load all makefile files in the current directory, all-makefiles-under will return a list of all Android.mk located in a subdirectory of the current 'my-dir' path in.

All-makefiles-under definitions macros in build / core / definitions.mk in.

------------------------------------------------------------------------------------------------------------------------------

The final document is generated Android.mk the Settings.apk. After the above analysis Android.mk file to summarize various LOCAL_XXX.

Three cases Description:

    You must be defined, the value to be given in the package or Android.mk app.

    Alternatively defined, it may or may not be a given value or package of Android.mk app.

    Without defining, not a given value in Android.mk app or package, the script specified value automatically.

LOCAL_PATH,          当前路径,必须定义。
LOCAL_PACKAGE_NAME,  必须定义,package的名字,这个名字在脚本中将标识app或package。
LOCAL_MODULE_SUFFIX, 不用定义,module的后缀,=.apk。
LOCAL_MODULE,        不用定义,=$(LOCAL_PACKAGE_NAME)。
LOCAL_JAVA_RESOURCE_DIRS,     不用定义。
LOCAL_JAVA_RESOURCE_FILES,    不用定义。
LOCAL_MODULE_CLASS,  不用定义。
LOCAL_MODULE_TAGS,   可选定义。默认optional。取值范围user debug eng tests optional samples shell_ash shell_mksh。
LOCAL_ASSET_DIR,     可选定义,推荐不定义。默认$(LOCAL_PATH)/assets
LOCAL_RESOURCE_DIR,  可选定义,推荐不定义。默认product package和device package相应的res路径和$(LOCAL_PATH)/res。
LOCAL_PROGUARD_ENABLED,       可选定义,默认为full,如果是user或userdebug。取值full, disabled, custom。
full_android_manifest,        不用定义,=$(LOCAL_PATH)/AndroidManifest.xml。
LOCAL_EXPORT_PACKAGE_RESOURCES,    可选定义,默认null。如果允许app的资源被其它模块使用,则设置true。
LOCAL_CERTIFICATE,   可选定义,默认为testkey。最终
        private_key := $(LOCAL_CERTIFICATE).pk8
        certificate := $(LOCAL_CERTIFICATE).x509.pem

Extensions: may generate a plurality of executable program Android.mk, the dynamic and static libraries.

(1) compiled APK application template.

About templates compiled APK Applications, please refer to " Android.mk compiled APK paradigm "

 

(2) compile JAVA library template

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Any libraries that this library depends on
LOCAL_JAVA_LIBRARIES := android.test.runner
# The name of the jar file to create
LOCAL_MODULE := sample
# Build a static jar file.
include $(BUILD_STATIC_JAVA_LIBRARY)

 Note : LOCAL_JAVA_LIBRARIES: = android.test.runner represent jar file name generation JAVA library

(3) compile C / C ++ application template as follows :

LOCAL_PATH := $(call my-dir)
#include $(CLEAR_VARS)
LOCAL_SRC_FILES := main.c
LOCAL_MODULE := test_exe
#LOCAL_C_INCLUDES :=
#LOCAL_STATIC_LIBRARIES :=
#LOCAL_SHARED_LIBRARIES :=
include $(BUILD_EXECUTABLE)

 NOTE : ': =' a meaning is assigned, '= +' is added meaning, '$' represents a reference value of a variable

LOCAL_SRC_FILES中加入源文件路径,LOCAL_C_INCLUDES中加入需要的头文件搜索路径
LOCAL_STATIC_LIBRARIES 加入所需要链接的静态库(*.a)的名称,
LOCAL_SHARED_LIBRARIES 中加入所需要链接的动态库(*.so)的名称,
LOCAL_MODULE表示模块最终的名称,BUILD_EXECUTABLE 表示以一个可执行程序的方式进行编译。

 (4) to compile C \ C ++ static library

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
 helloworld.c
LOCAL_MODULE:= libtest_static
 #LOCAL_C_INCLUDES :=
#LOCAL_STATIC_LIBRARIES :=
#LOCAL_SHARED_LIBRARIES :=
include $(BUILD_STATIC_LIBRARY)

And similar to the above, BUILD_STATIC_LIBRARY represent compile a static library.

Templates (5) to compile C / C ++ dynamic library

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := helloworld.c
LOCAL_MODULE := libtest_shared
TARGET_PRELINK_MODULES := false
#LOCAL_C_INCLUDES :=
#LOCAL_STATIC_LIBRARIES :=
#LOCAL_SHARED_LIBRARIES :=
include $(BUILD_SHARED_LIBRARY)

 

And similar to the above, BUILD_SHARED_LIBRARY represent compile a shared library.

Generating a result of the above three, respectively one of the directories, generic becomes depending on the specific target (possibly dkb ~~):

out/target/product/generic/obj/APPS
out/target/product/generic/obj/JAVA_LIBRARIES
out/target/product/generic/obj/EXECUTABLE
out/target/product/generic/obj/STATIC_LIBRARY
out/target/product/generic/obj/SHARED_LIBRARY

Target file folder for each module are as follows:

1)APK程序:XXX_intermediates
2)JAVA库程序:XXX_intermediates
3)C\C++可执行程序:XXX_intermediates
4)C\C++静态库: XXX_static_intermediates
5)C\C++动态库: XXX_shared_intermediates
 

 

Published 112 original articles · won praise 3 · Views 9714

Guess you like

Origin blog.csdn.net/yush34/article/details/104696167