Monday, March 2, 2009

Add a new component into open source Android

更多精彩请到 http://www.139ya.com

转自: http://discuz-android.blogspot.com/2008/11/add-new-component-into-open-source.html


The android build system is complicated. It is not easy to create a simple build script to build single component. But it is much easier to add a new component into the build system. Here is a sample to build the "Hello world!" for Android, and it is dynamic linked executable.

  1. create a directory for the new component in $(YOUR_ANDROID)/external folder: $(YOUR_ANDROID)/external/hello
  2. put the hello.c into the directory: $(YOUR_ANDROID)/external/hello/
  3. create Android.mk in $(YOUR_ANDROID)/external/hello/ directory, the Android.mk likes the following:
    LOCAL_PATH:=$(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_ARM_MODE := arm
    LOCAL_SRC_FILES:= \
    hello.c
    LOCAL_MODULE := hello
    include $(BUILD_EXECUTABLE)
  4. add the following line into $(BUILD_SYSTEM)/main.mk,$(BUILD_SYSTEM) is in $(YOUR_ANDROID)/build/core:
    external/hello ( find the external/zlib in main.mk? Append your lines after that.)
  5. launch the build command in $(YOUR_ANDROID): make hello
you will have the build target hello in $(YOUR_ANDROID)/out/target/product/generic/system/bin.
You can use include $(BUILD_SHARED_LIBRARY) to create shared library. Find more in $(YOUR_ANDROID)/build/core/config.mk.

No comments: