Android compiling environment-compiling the hello World module

Source: Internet
Author: User

Android compiling environment --- compiling the hello World module

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 the unified standard android. mk. android. the MK file itself is relatively simple, but it is not a familiar makefile, 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 new android. MK to add a new component for Android is relatively simple.
Compile Java Program You can directly use the eclipse integrated environment. 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, where $ (your_android) indicates android Source code Directory.
-# 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:
<textarea cols="50" rows="15" name="code" class="cpp"># Include <stdio. h> <br/> int main () <br/> {<br/> printf ("Hello world! /N "); <br/> return 0; <br/>}</textarea>

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:
<textarea cols="50" rows="15" name="code" class="cpp">Local_path: = $ (call my-DIR) <br/> include $ (clear_vars) <br/> local_src_files: = hello. c <br/> local_module: = helloworld <br/> include $ (build_executable)</textarea>
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 android SourceCode Compile the top-level directory:
# 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

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.