Android ndk learning journey-android. mk

Source: Internet
Author: User
Learning Journey Based on Android ndk ----- Android. mk Introduction

An android. mk file is used to describe your source code to the compilation system. Specifically, this file is a small part of GNU makefile and will be parsed once or multiple times by the compilation system. You can define one or more modules in each android. mk file. You can also use the same source code file in several modules. The compilation system handles many details for you.

The source files in a project are not counted. They are stored in several directories by type, function, and module. makefile defines a series of rules to specify which files need to be compiled first, which files need post-compilation, which need to be re-compiled, or even perform more complex functional operations, because makefile is like a shell script and can also execute operating system commands.

The benefit of makefile is "automatic compilation". Once written, only one make command is required, and the entire project is fully automatically compiled, which greatly improves the efficiency of software development. Make is a command tool that explains commands in makefile. Generally, most ides use this command, such as make in Delphi and nmake in Visual C ++, GNU make in Linux. It can be seen that makefile is a compilation method in Engineering.

The most important and basic function of the make tool is to use the MAKEFILE file to describe the relationship between source programs and automatically maintain the compilation work. The MAKEFILE file needs to be compiled according to a certain syntax. The file must describe how to compile each source file and generate an executable file, and define the dependency between the source files. Makefile is a common method for many compilers-including compilers in Windows NT-to maintain compilation information. It is only possible for users to modify makefile files on a friendly interface in the integrated development environment.

Let's look at an instance:

The JNI file tree is as follows:


The android. mk file is as follows:

, Local_path: = $ (call my-DIR)

An android. mk file must first define the local_path variable. It is used to search for source files in the Development tree. In this example, the macro function 'my-dir' is provided by the compilation system and 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, specifying that GNU makefile clears many local_xxx variables for you (for example, local_module, local_src_files, local_static_libraries, etc.), 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: = hcsyncml

The local_module variable must be defined to identify each module you describe in the Android. mk file. The name must be unique and contain no spaces. Note that the compilation system automatically generates the appropriate prefix and suffix. In other words, a shared library module named 'hcsynyml' will generate the 'libhcsyncml. so' file.

4. local_c_includes: = $ (local_path)/extra_inc $ (local_path)/main_inc

Path of the header file to be included in local_c_shortdes

5. local_src_files

Add the source file path (the file to be compiled) to local_src_files. Multiple files are separated '\'.

6. local_ldlibs + =-L $ (sysroot)/usr/lib-llog

Allow Log Printing

 

Related Article

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.