• Android Platform Developers Guide
  • Getting Started with Android
  • Android Build System In this document
  • Understanding the makefile
  • Building the Android Platform
  • Building the Android Kernel
  • Android Platform Developer's Guide

    Download 1.03 Mb.
    Hajmi1.03 Mb.
      1   2   3   4   5   6   7   8   9   10

    Android Platform Developer's Guide

    Android Platform Developer's Guide 1

    Android Platform Developer's Guide 5

    About this Guide 5

    Intended Audience 5

    Getting Started with Android 5

    Android Build System 6

    In this document 6

    Building the Android Platform 8

    Building the Android Kernel 10

    Build Variants 11

    Configuring a New Product 12

    In this document 12

    Detailed Instructions 12

    New Product File Tree 15

    Product Definition Files 15

    Build Cookbook 17

    In this document 17

    Building a simple APK 17

    Building a APK that depends on a static .jar file 18

    Building a APK that should be signed with the platform key 18

    Building a APK that should be signed with a specific vendor key 19

    Adding a prebuilt APK 19

    Adding a Static Java Library 19

    Android.mk Variables 20

    Creating Release Keys and Signing Builds 29

    In this document 29

    Introduction 29

    Generating keys 30

    Signing a build for release 31

    Customization 32

    In this document 32

    Boot Screen Customization 32

    Network Customization Platform 33

    Customizing pre-loaded applications 34

    Customizing browser bookmarks 35

    Email Provider Customization 37

    Platform Themes 41

    Bring Up 41

    1. Confirm a Clean Installation of a Basic Linux Kernel 42

    2. Modify Your Kernel Configuration to Accommodate Android Drivers 42

    3. Write Drivers 42

    4. Burn Images to Flash 43

    5. Boot the kernel and mount the RAMdisk. 43

    6. Debug Android-specific init programs on RAMdisk 44

    7. Verify that applications have started 44

    8. Pulling it all together 45

    Android Init Language 45

    Display Drivers 50

    In this document 50

    Functionality 51

    Implementing Your Own Driver (Driver Template) 52

    Troubleshooting 59

    Keymaps and Keyboard Input 59

    In this document 59

    Functionality 60

    Key Layout Map 61

    Key Character Map 63

    Implementing Your Own Driver (Driver Template) 67

    Sample Implementation 70

    Lights 70

    In this document 70

    Building a Lights Library 71

    Interface 71

    Audio 75

    In this document 75

    Building an Audio Library 77

    Interface 77

    Building a Camera Library 84

    Sequence Diagrams 85

    Wake Locks 90

    Driver API 92

    User-space API 93

    Types of Wake Locks 93

    Exploring a Wake Lock Example 93

    PowerManager class 94

    Registering Drivers with the PM Driver 94

    Early Suspend 95

    Sensors 95

    In this document 95

    Building a Sensor Library 96

    Interface 97

    RIL Initialization 99

    RIL Interaction 99

    Implementing the RIL 102

    RIL Functions 103

    Dalvik 105

    In this document 105

    Core Libraries 106

    JNI Call Bridge 106

    Interpreter 107

    Mterp Interpreter Structure 108

    Getting Started With Mterp 109

    Replacing Stubs 110

    Interpreter Switching 111

    Testing 112

    Testing and Debugging 113

    Instrumentation Testing 113

    In this document 113

    Instrumentation Framework 114

    Platform Test Suites 116

    Running Tests 116

    Writing Tests 120

    Debugging with GDB 123

    In this document 123

    Debugging 124

    Just-In-Time Debug Feature 126

    Debugging Native Code 127

    In this document 127

    Capturing logs 127

    Debug Scenarios 127

    Debugging with tcpdump and other tools 135

    Installing tcpdump 135

    Running tcpdump 136

    Other network debugging commands 138

    Android Platform Developer's Guide

    Welcome to the Android Platform Dev Guide! This guide provides an under-the-hood introduction to the Android platform, and is designed for platform developers and manufacturers building Android-powered devices.

    If you're a software developer interested in developing applications for Android, please visit the Android Developers site.

    About this Guide

    This guide is divided into sections by logical platform component (see the table of contents on the left). Android is a complex project under constant development, and the level of detail, as well as the rate of change, may vary from section to section. This guide will be updated regularly as more content becomes available.

    Intended Audience

    This guide is intended for engineers who are proficient with building and running Linux on embedded devices. It aims to provide explanation of the Android platform rather than Linux or embedded development in general.

    Getting Started with Android

    If you are new to Android, start with the platform documentation on the following sites:

    • Android Developers site: This site offers high-level platform documentation and architecture concepts.

    • Android Open Source Project site: This site provides instructions on how to get the source code, establish a development environment, and perform a simple build.

    When you are ready to start customizing the platform or porting to your target hardware, start in this guide with the Build System overview.

    Android Build System

    In this document

    Android uses a custom build system to generate tools, binaries, and documentation. This document provides an overview of Android's build system and instructions for doing a simple build.

    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 % make -v. If you don't have version 3.80 or greater, you need to upgrade your version of make.

    Understanding the makefile

    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_SRC_FILES := main.c

    LOCAL_MODULE_TAGS := eng development


    include $(BUILD_EXECUTABLE)




    The snippet above includes artificial line breaks to maintain a print-friendly document.


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





    myProduct, myProduct_eu, myProduct_eu_fr, j2, sdk

    The product layer defines a complete specification of a shipping product, defining which modules to build and how to configure them. You might offer a device in several different versions based on locale, for example, or on features such as a camera.


    myDevice, myDevice_eu, myDevice_eu_lite

    The device layer represents the physical layer of plastic on the device. For example, North American devices probably include QWERTY keyboards whereas devices sold in France probably include AZERTY keyboards. Peripherals typically connect to the device layer.


    sardine, trout, goldfish

    The board layer represents the bare schematics of a product. You may still connect peripherals to the board layer.


    arm (arm5te) (arm6), x86, 68k

    The arch layer describes the processor running on your board.

    Building the Android Platform

    This 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 Code

    To do a generic build of android, source build/envsetup.sh, which contains necessary variable and function definitions, as described below.

    % 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 Up

    Execute % m clean to clean up the binaries you just created. You can also execute % m clobber to get rid of the binaries of all combos. % m clobber is equivalent to removing the //out/ directory where all generated files are stored.

    Speeding Up Rebuilds

    The binaries of each combo are stored as distinct sub-directories of //out/, making it possible to quickly switch between combos without having to recompile all sources each time.

    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 USE_CCACHE environment variable as shown below:

    % export USE_CCACHE=1

    Doing so will force the build system to use the ccache compiler cache tool, which reduces recompiling all sources.

    ccache binaries are provided in //prebuilt/... and don't need to get installed on your system.


    The 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)


    dx is a Java program that uses facilities first made available in Java version 1.5. Check your version of Java by executing % java -version in the shell you use to build. You should see something like:

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

    Building the Android Kernel

    This 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 (/home/joe/android/device) in order to establish variables and run:

    % . build/envsetup.sh

    % partner_setup generic

    Then switch to the kernel directory /home/joe/android/kernel.

    Checking Out a Branch

    The default branch is always android. To check out a different branch, execute the following:

    % 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 % git checkout .

    Verifying Location

    Find 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-mydevice





    To only see local branches, omit the -a flag.

    Building the Kernel

    To build the kernel, execute:

    % make -j4

    Build Variants

    When 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:


    This is the default flavor. A plain make is the same as make eng.

    • Installs modules tagged with: eng, debug, user, and/or development.

    • Installs non-APK modules that have no tags specified.

    • Installs APKs according to the product definition files, in addition to tagged APKs.

    • ro.secure=0

    • ro.debuggable=1

    • ro.kernel.android.checkjni=1

    • adb is enabled by default.


    make user

    This is the flavor intended to be the final release bits.

    • Installs modules tagged with user.

    • Installs non-APK modules that have no tags specified.

    • Installs APKs according to the product definition files; tags are ignored for APK modules.

    • ro.secure=1

    • ro.debuggable=0

    • adb is disabled by default.


    make userdebug

    The same as user, except:

    • Also installs modules tagged with debug.

    • ro.debuggable=1

    • adb is enabled by default.

    If you build one flavor and then want to build another, you should run make installclean between the two makes to guarantee that you don't pick up files installed by the previous flavor. make clean will also suffice, but it takes a lot longer.

    Download 1.03 Mb.
      1   2   3   4   5   6   7   8   9   10

    Download 1.03 Mb.

    Bosh sahifa

        Bosh sahifa

    Android Platform Developer's Guide

    Download 1.03 Mb.