Monday, November 24, 2008

Android build system

Found document in android open source. They are in myandroid/development/pdk/docs/. Following information are from the "Android build system" section. It is more helpful than "Add a new component into open source Android".
A makefile defines how to build a particular application. Makefiles typically include all of the following elements:
  1. Name: Give your build a name (LOCAL_MODULE := ).
  2. Local Variables: Clear local variables with CLEAR_VARS (include $(CLEAR_VARS)).
  3. Files: Determine which files your application depends upon (LOCAL_SRC_FILES := main.c).
  4. Tags: Define tags, as necessary (LOCAL_MODULE_TAGS := eng development).
  5. Libraries: Define whether your application links with other libraries (LOCAL_SHARED_LIBRARIES := cutils).
  6. Template file: Include a template file to define underlining make tools for a particular target (include $(BUILD_EXECUTABLE)).
The following snippet illustrates a typical makefile.
LOCAL_PATH := $(my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE :=
LOCAL_SRC_FILES := main.c
LOCAL_MODULE_TAGS := eng development
LOCAL_SHARED_LIBRARIES := cutils
include $(BUILD_EXECUTABLE)
(HOST_)EXECUTABLE, (HOST_)JAVA_LIBRARY, (HOST_)PREBUILT, (HOST_)SHARED_LIBRARY,
(HOST_)STATIC_LIBRARY, PACKAGE, JAVADOC, RAW_EXECUTABLE, RAW_STATIC_LIBRARY,
COPY_HEADERS, KEY_CHAR_MAP

Saturday, November 15, 2008

Good start to port 3-party to Android

After you have the open source Android, look into folder external/openssl/README.android. It is a good start to port application to Android.

Friday, November 14, 2008

Add a new component into open source Android

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
  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.

Wednesday, November 12, 2008

build open source android

Refer to Get Source (Android Open Source Project) to get a copy of android open source and make full build. I had a successful build.
The android build system is quite complicated. To make a specific component, run 'make module_name'. Find the module_name in Android.mk, referenced by LOCAL_MODULE. For example, make app_process will build the app_process only.