The usage and foundation of ANDROID.MK

Source: Internet
Author: User


  1) apk program, General Android program, compile package build apk file
  2) Java library, Java Class Library, compile package build jar file
  3)  c\c++ application, executable c\c++ Application
  4) c\c++ Static library, compile and build c\c++ static library, and package as. A file
  5) c\c++ shared library,  build shared libraries (dynamic link libraries) and package them as. So, and only shared libraries can be installed/copied into your application (APK) package.
(1) Look at a simple example: a simple "Hello World", such as the following file:
sources/helloworld/helloworld.c 
sources/helloworld/android.mk

----- -----Cut here------------------

[CPP] view Plaincopy 
    1. Local_path: = $ (call My-dir)
    2. Include $ (clear_vars)
    3. Local_module
    4. : = HelloWorld
    5. Local_src_files: = HELLOWORLD.C
    6. Include $ (build_shared_library)

---------cut here------------------
Let's explain these lines of code:
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. In this example, the macro function ' My-dir ', provided by the compilation system, is used to return the current path (that is, the directory containing the android.mk file).
2,include $ (clear_vars), Clear_vars is provided by the compilation system (can see its definition in the Android installation directory/build/core/config.mk file, for clear_vars:= $ ( Build_system)/clear_vars.mk), specifies that the GNU makefile for you to clear many local_xxx variables (for example Local_module, Local_src_files, Local_static_ LIBRARIES, et cetera ...), except Local_path. This is necessary because all the compilation control files are in the same GNU make execution environment, and all the variables are global.
3,local_module: = Helloworld,local_module variables must be defined to identify each module that you describe in the Android.mk file. The name must be unique and does not contain any spaces. Note that the compilation system automatically generates the appropriate prefix and suffix, in other words, a shared library module named ' foo ' will generate a ' libfoo.so ' file (which can also be named directly libxxx).
4,local_src_files: = helloworld.c,local_src_files variable must contain C or C + + source code files that will be compiled into the module. Note that you do not have to list header files and include files here, because the compilation system will automatically find the dependent files for you; Just list the source code files that are passed directly to the compiler.

There is no use for other common use here:

5,local_c_includes: Optional variable that represents the search path for the header file. The default header file search path is the Local_path directory. Example: local_c_includes: = Sources/foo or Local_c_includes: = $ (local_path)/... /foo

6,target_arch: The name of the target CPU platform; TARGET_PLATFORM:Android.mk the name of the target Android platform at the time of parsing, Target_arch_abi: temporarily supports only two Value,armeabi and armeabi-v7a

7,local_static_libraries: Indicates which static libraries the module needs to use in order to link at compile time.

8,local_shared_libraries: Represents a shared library (dynamic Library) that the module relies on at run time, which is required at link time to embed its corresponding information when the file is generated.

9,local_ldlibs: Additional linker options to use when compiling the module.

10,local_arm_mode: By default, the arm target binary is generated as a thumb (16 bits) and you can set this variable to arm if you want your module to be in the form of a 32-bit instruction

11,local_cflags: Optional compiler option to use when compiling C code files

12,include $ (call All-subdir-makefiles): Returns a list of all android.mk in the subdirectory of the current ' my-dir ' path.

(2) adding local programs or libraries to Android, these programs and libraries have nothing to do with the path they are carrying, only their android.mk files. Android.mk and ordinary makefile different, it has a unified writing, mainly contains some of the system public macros. Multiple executable programs, dynamic libraries, and static libraries can be generated in a single android.mk.
A, compile the templates for C + + applications:
#Test Exe
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)
(Rookie level Explanation:: = is the meaning of the assignment, + = is the appended meaning, $ is the value of a reference to a variable) build_executable means to compile in an executable program. Supplemental Note: The Include $ (build_package) is compiled out of a Apk,include $ (build_static_java_library) is compiled out of the jar package.
B, compile the template for the static library:
#Test Static Lib
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)
in general, similar to the above, Build_static_library represents compiling a static library. a file. Static libraries are not copied to the APK package, but can be used to compile shared libraries.
C, compile the template for the dynamic library:
#Test Shared Lib
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)
in general, similar to the above, build_shared_library means compiling a dynamic library.
the results of the above three are as follows, generic depending on the target will change:
out/target/product/generic/obj/executable
out/target/product/generic/obj/static_library
out/target/product/generic/obj/shared_library
the target folders for each module are:
executable program: Xxx_intermediates
Static Library: Xxx_static_intermediates
Dynamic Library: Xxx_shared_intermediates
(3) In addition, in the Android.mk file, you can also specify the final target installation path, specified with Local_module_path and Local_unstripped_path. Different file system paths are selected with the following macros:
Target_root_out: Represents the root file system out/target/product/generic/root.
Target_out: Represents the system filesystem out/target/product/generic/system.
Target_out_data: Represents the DATA file system out/target/product/generic/data.

Out_dir: Code Engineering compile-Time Out build directory

Product_out: Image Generation Directory

Reference Original: http://hubingforever.blog.163.com/blog/static/171040579201152185542166/

The usage and foundation of ANDROID.MK

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.