Http://www.top-e.org/jiaoshi/html? 157. html
The android compiling environment is complex and unlike the normal compiling environment: Only makefile files are available in the top-level directory, while each other component uses a unified standardAndroid. mk.Android. mkThe file itself is relatively simple, but it is not the makefile we are familiar with, but a lot of processing through the android compilation system. Therefore, it is still complicated to understand the links, however, the advantage of this method is to write a newAndroid. mkTo add a new component for Android.
Compiling Java programs can be completed directly using the eclipse integrated environment, which will not be repeated here. We mainly describe C/C ++. The following uses a small example to illustrate how to add a C program Hello world in Android:
1. Create the hello directory under the $ (your_android)/Development Directory. $ (your_android) indicates the directory where the android source code is located.
-# Mkdir $ (your_android)/development/Hello
2. Write the hello. c file in the $ (your_android)/external/Hello/directory. The content of Hello. C 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 of Android makefile. Do not change it. For the format and content of the android. mk file, refer to other existing Android. mk files. The content of the android. mk file for the helloworld program is 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 are used to specify the source file. local_module specifies the name of the module to be compiled, which will be used in the next step. include $ (build_executable) indicates that the file will be compiled into an executable file, if you want to compile it into a dynamic library, you can use build_shared_library, which can be in $ (your_android)/build/CORE/config. mk.
4. Return to the top-level directory of the android source code for compilation:
# 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 result is as follows:
Target thumb C: helloworld <= Development/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 preceding compilation result, the compiled executable file is stored in the out/target/product/generic/system/bin/helloworld file and transmitted to the simulator through "ADB push, then, log on to the simulator terminal through "ADB shell", and you will be able to execute