The Android build environment itself is complex, and unlike a normal compilation environment: only the top-level directories have makefile files, while each of the other component uses a uniform standard of android.mk. ANDROID.MK file itself is relatively simple, but it is not familiar with the makefile, but after the android itself compiled system of many processing, so to really understand the connection is more complex, but the advantage of this approach is to write a new android.mk to Android It would be easier to add a new component.
Compiling a Java program can be done directly using Eclipse's integrated environment, which is not duplicated here. We are mainly for the C + + to illustrate, below a small example to illustrate how to add a C program in Android Hello World:
1. Create a Hello directory under the $ (your_android)/development directory, where $ (your_android) refers to the directory where the ANDROID source code resides.
-# mkdir $ (your_android)/development/hello
2. In the $ (your_android)/external/hello/directory to write hello.c files, HELLO.C's content is of course the classic HelloWorld program:
#include <stdio.h>
int main ()
{
printf ("Hello world!\n");
return 0;
}
3. Write the Android.mk file in the $ (your_android)/external/hello/directory. This is the standard name for Android makefile, do not change. The format and content of the Android.mk file can be referenced in other existing android.mk files, and the contents of the Android.mk file for the HelloWorld program are as follows:
Local_path:= $ (call My-dir)
Include $ (clear_vars)
local_src_files:= \
hello.c
Local_module: = HelloWorld
Include $ (build_executable)
Note that the above local_src_files is used to specify the source file, Local_module specifies the name of the module to be compiled, and the next step is to compile it; include $ (build_executable) means to compile into an executable file, If you want to compile into a dynamic library, you can use Build_shared_library, which is found in the $ (your_android)/build/core/config.mk.
4. Go back to the top-level directory for Android source code to compile:
# CD $ (your_android) && make HelloWorld
Note that the target name HelloWorld in Make HelloWorld is the module name specified by Local_module in the Android.mk file above. The compilation results are as follows:
Target Thumb C:helloworld <= development/hello/hello.c
Target Executable:helloworld (out/target/product/generic/obj/executables/helloworld_intermediates/linked/ HelloWorld
Target Non-prelinked:helloworld (Out/target/product/generic/symbols/system/bin/helloworld)
Target Strip:helloworld (Out/target/product/generic/obj/executables/helloworld_intermediates/helloworld)
Install:out/target/product/generic/system/bin/helloworld
5. As shown in the previous compilation results, the compiled executable is stored in the Out/target/product/generic/system/bin/helloworld, passed to the emulator via "ADB push", and then through the "adb shell" Log in to the emulator terminal and you can execute the
Android compilation Environment (1)-Compile native C module