ANDROID.MK Simple Analysis

Source: Internet
Author: User

Local_path:= $ (call My-dir) include $ (clear_vars) Local_module_tags: = Optionallocal_src_files: = $ (call All-java-files-under, src) local_package_name: = settingslocal_certificate: = Platforminclude $ (BUILD_PACKAGE) # Use the Folloing include to make we test Apk.include $ (call all-makefiles-under,$ (Local_path))

The Android.mk file path is package/app/settings/android.mk to parse the file

The GNU make ' function ' macro, which must be called by using ' $ (call) ', calls them to return textual information.

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

(1) local_path:= $ (call My-dir)

A android.mk file must first define a good local_path variable. It is used to find source files in the development tree.

The macro function ' My-dir ', provided by the compilation system, is used to return the current path (that is, the directory that contains the Android.mk file).

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

(2) Android.mk can define multiple compilation modules, each compiled module starts with the include $ (clear_vars) and ends with the include $ (build_xxx).

(2.1) include $ (clear_vars)

Clear_vars refers to Clear_vars.mk, which is provided by the build system, which allows the GNU makefile to clear all local_xxx variables except local_path for you, such as Local_module,local_src_files , Local_shared_libraries,local_static_libraries and so on.

This is necessary because all the compilation control files are in the same GNU make execution environment, and all the variables are global.

(2.2) include $ (build_package) # Tell it to BUILD an APK

$ (build_package) is used to compile the apk under build package/app/.

There are several other compilation scenarios:

Include $ (build_static_library) to compile into a static library

Include $ (build_shared_library) to compile into a dynamic library

Include $ (build_executable) to compile into executable program

As an example, jump to the "extensions" below

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

(3) Local_module_tags: = Optional

Analytical:

Local_module_tags: =user eng tests optional

User: The module is compiled only under the user version

ENG: This module is only compiled under the ENG version

Tests: The module is compiled only under the tests version

Optional: Refers to the module compiled under all versions

Range of values Debug ENG tests optional Samples Shell_ash Shell_mksh. Note You cannot take the value of user, and if you want to preload it, you should define CORE.MK.

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

(4) Local_src_files: = $ (call All-java-files-under, SRC)

(4.1) If you want to include Java source code, you can call All-java-files-under to get it. (This form includes all Java files in the Local_path directory)

(4.2) When it comes to C + +, the Local_src_files variable must contain C or C + + source code files that will be compiled into the module. Note that here you can not list header files and include files, because the compiling system will automatically find the dependent files for you; Just list the source code files that are passed directly to the compiler.

The definition of All-java-files-under macro is in build/core/definitions.mk.

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

(5) Local_package_name: = Settings

The name of the package, which will identify the app or package in the script.

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

(6) Local_certificate: = Platform

Local_certificate is followed by the file name of the signature file, stating that settings.apk is an apk that requires platform key signature

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

(7) include $ (build_package)

Explained in (2.2)

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

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

Loads all the makefile files in the current directory, All-makefiles-under returns a list of all android.mk in the subdirectory of the current ' my-dir ' path.

The definition of All-makefiles-under macro is in build/core/definitions.mk.

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

This android.mk file finally generates a settings.apk. After analysis of the above android.mk file, to summarize the various local_xxx.

Three case notes:

Must be defined, the value must be given in the android.mk of the app or package.

Optional definitions can or may not be given values in the android.mk of the app or package.

Without a definition, the script automatically assigns values in the android.mk of the app or package without the given value.

Local_path, the          current path, must be defined. Local_package_name,  must be defined, the name of the package, the name in the script will identify the app or package. Local_module_suffix, without definition, the suffix of MODULE, =.apk. Local_module,        without definition, =$ (local_package_name). Local_java_resource_dirs,     not defined. Local_java_resource_files,    not defined. Local_module_class,  not defined. local_module_tags,   optional definition. Default optional. Value range user Debug Eng tests optional Samples Shell_ash Shell_mksh. Local_asset_dir,     optional definition, recommendation not defined. Default $ (Local_path)/assetslocal_resource_dir,  optional definition, recommended not defined. The default product package and device package corresponding res path and $ (local_path)/res. local_proguard_enabled,       optional definition, default to full, if user or userdebug. Take value full, disabled, custom. full_android_manifest,        without definition, =$ (local_path)/androidmanifest.xml. local_export_package_resources,    optional definition, default NULL. Set true if the resource for the app is allowed to be used by another module. local_certificate,   optional definition, default is TestKey. Final        Private_key: = $ (local_certificate). Pk8        CERTIFICATE: = $ (local_certificate). X509.pem

extension: Multiple executable programs, dynamic libraries, and static libraries can be generated in one android.mk.

(1) Compile APK application template. For the template to compile APK application, please refer to the "ANDROID.MK compilation apk Example" (2) Compiling Java library templates
Local_path: = $ (call My-dir) include $ (clear_vars) # Build All Java files in the Java subdirectorylocal_src_files: = $ (call  All-subdir-java-files) # Any libraries, this library depends onlocal_java_libraries: = android.test.runner# the name of The jar file to Createlocal_module: = sample# Build a static jar File.include $ (build_static_java_library)
Note: local_java_libraries: = Android.test.runner represents the jar file name of the generated JAVA library (3) Compile the C + + application template as follows
Local_path: = $ (call My-dir) #include $ (clear_vars) Local_src_files: = Main.clocal_module: = test_exe#local_c_includes: = #LOCAL_STATIC_LIBRARIES: = #LOCAL_SHARED_LIBRARIES: =include $ (build_executable)

Note : ': = ' is the meaning of assignment, ' + = ' is the appended meaning, ' $ ' indicates a value that references a variable

Add the source file path to the Local_src_files, add the desired header file search path to the Local_c_includes local_static_libraries add the name of the static library (*.A) that you want to link to, local_shared_ LIBRARIES adds the name of the dynamic library (*.so) you need to link to, Local_module represents the final name of the module, and build_executable the compilation as an executable program.

(4) compiling c\c++ static library
Local_path: = $ (call My-dir) include $ (clear_vars) Local_src_files: =  helloworld.clocal_module:= libtest_static # Local_c_includes: = #LOCAL_STATIC_LIBRARIES: = #LOCAL_SHARED_LIBRARIES: =include $ (build_static_library)

Similar to the above, build_static_library means compiling a static library.

(5) compiling a template for C + + dynamic libraries
Local_path: = $ (call My-dir) include $ (clear_vars) Local_src_files: = Helloworld.clocal_module: = libtest_sharedtarget_ Prelink_modules: = false#local_c_includes: = #LOCAL_STATIC_LIBRARIES: = #LOCAL_SHARED_LIBRARIES: =include $ (build_ Shared_library)

Similar to the above, Build_shared_library represents compiling a shared library.

The result of the above three is in the following directory, generic depending on the target will change (possibly dkb~~):
Out/target/product/generic/obj/appsout/target/product/generic/obj/java_librariesout/target/product/generic/obj /executableout/target/product/generic/obj/static_libraryout/target/product/generic/obj/shared_library

The target folders for each module are:

1) apk program: XXX_INTERMEDIATES2) Java Library Program: XXX_INTERMEDIATES3) c\c++ executable: xxx_intermediates4) c\c++ Static library: Xxx_static_ INTERMEDIATES5) c\c++ Dynamic Library: xxx_shared_intermediates

Reference article:

The explanation is very detailed ~ ~

ANDROID.MK Introduction

Compiling the APK example ~ ~

ANDROID.MK Compiling apk example

This talk is a bit wide, involving a lot of MK Files ~ ~

Android Makefile Organizational Structure

ANDROID.MK Simple Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.