Android Build System
In this document
Android's build system is make based and requires a recent version of GNU Make (note that Android uses advanced features of GNU Make that may not yet appear on the GNU Make web site). Before continuing, check your version of make by running Understanding the makefileA makefile defines how to build a particular application. Makefiles typically include all of the following elements:
The following snippet illustrates a typical makefile. LOCAL_PATH := $(my-dir) include $(CLEAR_VARS) LOCAL_MODULE := <buil_name> 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 The snippet above includes artificial line breaks to maintain a print-friendly document. LayersThe build hierarchy includes the abstraction layers described in the table below. Each layer relates to the one above it in a one-to-many relationship. For example, an arch can have more than one board and each board can have more than one device. You may define an element in a given layer as a specialization of an element in the same layer, thus eliminating copying and simplifying maintenance.
Building the Android PlatformThis section describes how to build the default version of Android. Once you are comfortable with a generic build, then you can begin to modify Android for your own target device. Device CodeTo do a generic build of android, source % cd $TOP % . build/envsetup.sh # pick a configuration using choosecombo % choosecombo % make -j4 PRODUCT-generic-user You can also replace user with eng for a debug engineering build: % make -j4 PRODUCT-generic-eng
These Build Variants differ in terms of debug options and packages installed. Cleaning UpExecute Speeding Up RebuildsThe binaries of each combo are stored as distinct sub-directories of However, performing a clean rebuild is necessary if the build system doesn't catch changes to environment variables or makefiles. If this happens often, you should define the % export USE_CCACHE=1
Doing so will force the build system to use the ccache compiler cache tool, which reduces recompiling all sources.
TroubleshootingThe following error is likely caused by running an outdated version of Java. device Dex: core UNEXPECTED TOP-LEVEL ERROR: java.lang.NoSuchMethodError: method java.util.Arrays.hashCode with signature ([Ljava.lang.Object;)I was not found. at com.google.util.FixedSizeList.hashCode(FixedSizeList.java:66) at com.google.rop.code.Rop.hashCode(Rop.java:245) at java.util.HashMap.hash(libgcj.so.7) [...]
java version "1.5.0_07" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-164) Java HotSpot(TM) Client VM (build 1.5.0_07-87, mixed mode, sharing) If you do have Java 1.5 or later and your receive this error, verify that you have properly updated your Building the Android KernelThis section describes how to build Android's default kernel. Once you are comfortable with a generic build, then you can begin to modify Android drivers for your own target device. To build the kernel base, switch to the device directory ( % . build/envsetup.sh % partner_setup generic Then switch to the kernel directory Checking Out a BranchThe default branch is always % git checkout --track -b android-mydevice origin/android-mydevice //Branch android-mydevice set up to track remote branch % refs/remotes/origin/android-mydevice. //Switched to a new branch "android-mydevice" To simplify code management, give your local branch the same name as the remote branch it is tracking (as illustrated in the snippet above). Switch between branches by executing Verifying LocationFind out which branches exist (both locally and remotely) and which one is active (marked with an asterisk) by executing the following: % git branch -a android * android-mydevice origin/HEAD origin/android origin/android-mydevice origin/android-mychipset To only see local branches, omit the Building the KernelTo build the kernel, execute: % make -j4
Build VariantsWhen building for a particular product, it's often useful to have minor variations on what is ultimately the final release build. These are the currently-defined build variants:
If you build one flavor and then want to build another, you should run |
|