Native programming with Android building system

Source: Internet
Author: User
In the previous post, native programming on Android, I showed how to use code sourcery toolchain To Do native programming on Android. but in that way, we must link C library statically into our application, which is not desirable. so, in this post, I'll show how to do native programming with the android built-in building system.

For demonstration purpose, I'll create a logtest application. The application relies on cutils lib and writes some log information that can be examined through"ADB logcat"Command.

1. initialize Android source tree
In later steps, I'll use $ android_src to refer to the root of the android source tree.

2. Create a directory for your application within the source tree
One advantage of Android building system is it doesn' t require your application to follow a specific organization structure. your application can be placed in any directory. I created $ android_src/logtest folder for the application.

3. Create an android. mk file for the application in the directory
Android. mk is a reserved file name to indicate a module. This file describes how to build the module. By defining local_module variable, we can assign a name to our application.
Depending on the type of the module, we include$ (Build_executable),$ (Build_dynamic_library)And$ (Build_static_library)Respectively at the end of the android. mk.

4. Specify source files for the Application
Through local_src_files variable, We specifies which source files are necessary to compile the module. Paths to source files are represented relative to the location of the android. mk file.

5. Specify Dependencies
Through local_shared_libraries variable, we can specify other libraries that our module depends on.

6. Build Application
Go to root of Android source tree, and type make $ (local_module) to build the application which will be placed at $ android_src/out/target/product/generic/system/bin/logtest.

TIPS:

1. Show commands
By default, Android building system disables command echoing. It's hard to find out and correct dependency relationships without seeing the actual command. To change this behavior, we can append the showcommands pseudo do target.
For example:
Make logtest showcommands

2. Quick build
Android building system need to find and parse android. MK files within the source tree, and analysis dependencies. it's a time consuming task. in fact, there is a quicker way to build a module.
CD $ android_src
Source build/envsetup. Sh
Mmm {path_to_module_to_be_built} showcommands

3. Build Host module
Android building system can also used to generate modules for the host machine. An example is the ADB application. To build Host module, we can use:
Include $ (build _Host_ Executable) # $ (build _Host_ Static_library)

The demo can be found:
Http://code.google.com/p/rxwen-blog-stuff/source/browse/trunk/android/logtest/

reference :
Android building system
Android build system

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.