<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-348  評論-598  文章-0  trackbacks-0

    Android Build System

    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 := <build_name>).
    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 := <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.

    Layers

    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.

    LayerExampleDescription
    Product 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.
    Device 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.
    Board sardine, trout, goldfish The board layer represents the bare schematics of a product. You may still connect peripherals to the board layer.
    Arch 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.

    Troubleshooting

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

    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
    * android-mydevice
    origin/HEAD
    origin/android
    origin/android-mydevice
    origin/android-mychipset
    

    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:

    eng This is the default flavor. A plain make is the same as make eng.
    • Installs modules tagged with: engdebuguser, 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.
    user 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.
    userdebug 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.  

    從 http://android.git.kernel.org/ 查看各個分支及其TAG
    • 下載源碼
      • mkdir /android; cd /android
      • curl http://android.git.kernel.org/repo > repo  
        # repo上android的下載源碼腳本
      • mkdir -p /android/donut_release; cd /android/donut_release
      • ../repo init -u git://android.git.kernel.org/platform/manifest.git -b donut
      • ../repo sync 
    • 下載內(nèi)核
      • mkdir /android/donut_kernel; cd /android/donut_kernel
      • git clone git://android.git.kernel.org/kernel/common.git  
      • cd common; 
      • git branch -a; 查看分支
      • git checkout origin/android-goldfish-2.6.29 -b goldfish
      • vi Makefile : 設(shè)置 ARCH和CROSS_COMPILE為 arm/ arm-eabi-
      • make 嘗試編譯。
    • 設(shè)置編譯環(huán)境
    • sudo apt-get -y install git-core gnupg sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev valgrind g++ sun-javadb-javadoc
    • export JAVA_HOME=/usr/lib/jvm/java-5-sun
    • export JRE_HOME=${JAVA_HOME}/jre
    • export ANDROID_JAVA_HOME=$JAVA_HOME
    • export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:${JAVA_HOME}/lib:$JRE_HOME/lib:$CLASSPATH
    • export ANDROID_HOME=/android/donut_release
    • export ANDROID_PRODUCT_OUT=$ANDROID_HOME/out/target/product/generic
    • export PATH=$PATH:$JAVA_HOME/bin:${JRE_HOME}/bin:$ANDROID_HOME/out/host/linux-x86/bin:$ANDROID_HOME:/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin
    • sudo update-alternatives --config javac [java/javadoc] 
      #配置使用 java-5-sun的配置。(ubuntu 9.10中舍棄了jdk5, 可以自己安裝 jdk1.5.bin
    • 編譯make (make sdk) 
      • cd $ANDROID_HOME; make #修改做部分修改,詳情看最后
      • 編譯完成后,使用模擬器進(jìn)行測試。

    模擬器

            ./android list targets ; 查看當(dāng)前的支持的target

            ./android create avd --name avd-donut --target 1
            ./androld list avd
            ./emulator -avd 
    avd-donut
    調(diào)試橋
            ./adb remount
            ./adb shell
    根文件系統(tǒng)
            目錄在 out/target/product/generic/ 下

    從模擬器中獲取默認(rèn)配置文件
            adb pull /proc/config.gz /tmp; cd /tmp

            gunzip config.gz

            mv config /android/donut_kernel/.config

    測試配置文件

            cd /android/donut_kernel

            make ARCH=arm menuconfig

            make CROSS_COMPILE=arm-eabi-

    • 初始化完成,進(jìn)行第二步,內(nèi)核的移植,搭載idea 6410 自帶的rootfs
    ==== 編譯android時需要改動的源碼地方 BEGIN===
    E: ‘EAI_NODATA’ undeclared
    S: vi external/qemu/Makefile.android
         ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
         -  MY_CFLAGS += -Wa,--32
         +  MY_CFLAGS += -Wa,--32 -D_GNU_SOURCE
         endif



    E: cupcake battery bug
    S: vi frameworks/base/services/java/com/android/server/BatteryService.java
         private final void sendIntent() {
             //  Pack up the values and broadcast them to everyone
            +    mBatteryLevel = 100;

    E: Build error message:
    frameworks/policies/base/PolicyConfig.mk:22: *** No module defined for the given PRODUCT_POLICY (android.policy_phone).

    S: modify codes at line 89 in build/tools/findleaves.sh
    #find "${@:0:$nargs}" $findargs -type f -name "$filename" -print |
    find "${@:1:$nargs-1}" $findargs -type f -name "$filename" -print |


    E: frameworks/base/tools/aidl/AST.cpp:10: error: 'fprintf' was not declared in this scope的錯誤

    S:下載gcc-4.3和g++-4.3

      apt-get install gcc-4.3 g++-4.3

    cd /usr/bin

      ln -s gcc-4.3 gcc

      ln -s g++-4.3 g++



    ==== 編譯android時需要改動的源碼地方 END ===


    ---------------------------------------------------------
    專注移動開發(fā)

    Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
    posted on 2010-05-30 17:33 TiGERTiAN 閱讀(2196) 評論(0)  編輯  收藏 所屬分類: AndroidLinux
    主站蜘蛛池模板: 啦啦啦在线免费视频| 在人线av无码免费高潮喷水| 国产精品久久亚洲一区二区| 国产精品亚洲专区在线观看| 亚洲国产成人综合| 亚洲成a人片在线网站| 亚洲精品国产成人| 亚洲精品高清国产麻豆专区| 91亚洲国产在人线播放午夜| 亚洲最大黄色网址| 亚洲卡一卡2卡三卡4麻豆| 亚洲专区一路线二| 亚洲午夜成人精品无码色欲| 亚洲精品欧美综合四区| 免费观看亚洲人成网站| 成人福利在线观看免费视频| 成人免费av一区二区三区| 国产在线精品免费aaa片| 91精品免费观看| 日本XXX黄区免费看| 在线观看免费毛片| 免费观看国产小粉嫩喷水| 亚洲欧洲自拍拍偷精品 美利坚| 亚洲午夜未满十八勿入网站2| 亚洲AV无码欧洲AV无码网站| 亚洲无人区视频大全| 亚洲国产精品ⅴa在线观看| 青青草97国产精品免费观看| 日本道免费精品一区二区| 中文字幕免费在线| 久久午夜夜伦鲁鲁片免费无码| 中文字幕不卡亚洲| 亚洲码国产精品高潮在线| 亚洲精品无码不卡| 亚洲一区二区三区久久| 亚洲精品无码一区二区| 国产免费区在线观看十分钟| 99re在线视频免费观看| 免费黄色小视频网站| 国产午夜亚洲不卡| 亚洲成a人片在线观|