Android Build architecture add C project

Source: Internet
Author: User

1. Adding a project is closely related to the Android compiler hub. Special information needs to be told about the compiler hub.

For example:

A what is the target name of this project?

B What is the project compilation type, Bin? C? Lib? or jar?

C What is the variant of this project, and this indicates that different variants will put the output in different product catalogs.

D where should the project be placed? The preferred target is external and vendor directory, for what, I can only say is for consistency, in fact where, theoretically can be.

2. Project type definition:

The basic project type definition is defined in the Jb/build/core/config.mk file.

1Clear_vars:= $ (Build_system)/clear_vars.mk2Build_host_static_library:= $ (Build_system)/host_static_library.mk3Build_host_shared_library:= $ (Build_system)/host_shared_library.mk4Build_static_library:= $ (Build_system)/static_library.mk5Build_raw_static_library: = $ (Build_system)/raw_static_library.mk6Build_shared_library:= $ (Build_system)/shared_library.mk7Build_executable:= $ (Build_system)/executable.mk8Build_raw_executable:= $ (Build_system)/raw_executable.mk9Build_host_executable:= $ (Build_system)/host_executable.mkTenBuild_package:= $ (Build_system)/package.mk OneBuild_phony_package:= $ (Build_system)/phony_package.mk ABuild_host_prebuilt:= $ (Build_system)/host_prebuilt.mk -Build_prebuilt:= $ (Build_system)/prebuilt.mk -Build_multi_prebuilt:= $ (Build_system)/multi_prebuilt.mk theBuild_java_library:= $ (Build_system)/java_library.mk -Build_static_java_library:= $ (Build_system)/static_java_library.mk -Build_host_java_library:= $ (Build_system)/host_java_library.mk -Build_droiddoc:= $ (Build_system)/droiddoc.mk +Build_copy_headers: = $ (Build_system)/copy_headers.mk -Build_native_test: = $ (Build_system)/native_test.mk +Build_host_native_test: = $ (Build_system)/host_native_test.mk ABuild_notice_file: = $ (Build_system)/notice_files.mk

He mountain stone, can attack Jade, see the summary of others

Obviously, what we need to use is build_executable.

OK, start working and create the HelloWorld directory under the external directory.

HelloWorld

|----inclued

| |-----hello.h

|----src

| |-----MAIN.C

|----ANDROID.MK

NO1 write code for hello.h. Directory is helloworld/include below

1#include <stdio.h>2#include <stdlib.h>3 4 #ifndef __hello_h5 #define__hello_h6 7 voidmakeprintf (Char*str)8 {9printf"%s\n", str);Ten } One  A #endif

NO2 write code for MAIN.C. Directory is helloworld/src below

1 " include/hello.h " 2 int Main () 3 {4         makeprintf ("helloWorld"); 5         return 0 ; 6 }

NO3 Writing android.mk files

1 ########################################2 # Jeff3# jan -4 5Local_path:= $ (Call my-dir)6 7 #########################8 # Build HelloWorld by Jeff9 Ten include $ (clear_vars) One  AHello_headers: =  - hello.h -  theHELLO_SRC: =  - main.c -  -Local_c_includes: =$ (addprefixinclude/, $ (hello_headers)) +Local_src_files: = $ (Addprefix src/, $ (hello_src)) -  +local_module:=HelloWorld ALocal_module_tags: =Eng at  -Include $ (build_executable)

NO4 compilation, CD to HelloWorld directory execution #mm

Install:out/target/product/cv6a628h_base/system/bin/helloworld

NO5 verification, copy HelloWorld to board execution #./helloworld

1 [email protected]_base:/system/bin #./HelloWorld 2 Hello World

NO6 back to see ANDROID.MK

Three variables:

A local_path:= $ (call My-dir)

The stone of the mountain can attack the jade, see the others explain

Each android.mk file must start with a definition of local_path . It is used to find source files in the development tree.

Macro My-dir is provided by the build system. Returns the directory path that contains the ANDROID.MK.

b include $ (clear_vars)

The Clear_vars variable is provided by the build system. and points to a specified GNU Makefile, which is responsible for cleaning up many local_xxx.

For example:local_module, Local_src_files, local_static_libraries and so on. But do not clean local_path.

This cleanup action is necessary because all compiled control files are parsed and executed by the same GNU make, and their variables are global. So we can avoid the mutual influence after cleaning.

C include $ (build_executable), as explained above, does not say here.

D: Why should I write this android.mk

1 hello_headers: =2    3 hello_src: =4         MAIN.C5 local_c_includes: = $ (Addprefix include/, $ (hello_headers))6 local_src _files  : = $ (Addprefix src/,$ (HELLO_SRC))

Mainly from other people's writing, feel good, fake with include n. h or src under N. c files, at this time this writing is very useful, only need to add header files and C files under Hello_headers and HELLO_SRC.

Android Build architecture add C project

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.