zoukankan      html  css  js  c++  java
  • 编译android源代码(aosp)

     
    步骤1:按照官方的文档,下载源码,配置环境,并执行相应的命令。最好按照官方的硬件和系统配置build。
     
    build的版本是6.0,源码目录是/home/koder/android-source-20151229
     
    Requirements:
    • 下载的源码很大,估计有30,40G左右。加上build,最好腾出100+的空间来。
    • 按官方说的MAC OS或者Ubuntu LTS (14.04)X64,自己是Ubuntu LTS (14.04) 64位。
    • 硬件问题:内存不足,看文末问题1。
     
     
     
    有一个注意文档说的:lunch aosp_arm-eng
    这里是要build出一个适应于emulator的img,并且允许debug。
     
    aosp_arm-eng 表示target或者build configuration, 格式是: BUILD-BUILDTYPE
     
    aosp_arm是BUILD。如果希望build不同设备或者emulator的img,就要不同的值。点击这里有介绍。其中arm是叫做code name
     
    eng是BUILDTYPE:
    BuildtypeUse
    user limited access; suited for production
    userdebug like "user" but with root access and debuggability; preferred for debugging
    eng development configuration with additional debugging tools

    target有的例子有这些:
    DeviceCode nameBuild configuration
    Nexus 6P angler aosp_angler-userdebug
    Nexus 5X bullhead aosp_bullhead-userdebug
    Nexus 6 shamu aosp_shamu-userdebug
    Nexus Player fugu aosp_fugu-userdebug
    Nexus 9 volantis (flounder) aosp_flounder-userdebug
    Nexus 5 (GSM/LTE) hammerhead aosp_hammerhead-userdebug
    Nexus 7 (Wi-Fi) razor (flo) aosp_flo-userdebug
    Nexus 7 (Mobile) razorg (deb) aosp_deb-userdebug
    Nexus 10 mantaray (manta) full_manta-userdebug
    Nexus 4 occam (mako) full_mako-userdebug
    Nexus 7 (Wi-Fi) nakasi (grouper) full_grouper-userdebug
    Nexus 7 (Mobile) nakasig (tilapia) full_tilapia-userdebug
    Galaxy Nexus (GSM/HSPA+) yakju (maguro) full_maguro-userdebug
    Galaxy Nexus (Verizon) mysid (toro) aosp_toro-userdebug
    Galaxy Nexus (Experimental) mysidspr (toroplus) aosp_toroplus-userdebug
    PandaBoard (Archived) panda aosp_panda-userdebug
    Motorola Xoom (U.S. Wi-Fi) wingray full_wingray-userdebug
    Nexus S soju (crespo) full_crespo-userdebug
    Nexus S 4G sojus (crespo4g) full_crespo4g-userdebug

    Do not use 4.1.1 on a Nexus 7 that was originally sold with 4.1.2 or newer.

     

    步骤2:顺利make成功后。
     
    会在目录/home/koder/android-source-20151229/out/target/product/generic下生成系统系统的文件,包括system.img, ramdisk.img,userdata.img等。
     
    然后运行,由于build的是emulator的img,所以就运行虚拟机。
    官方文档说,会自动把环境变量设置好,但是执行emulator的时候,发现并没有该命令,所以需要自己找到emulator的目录。emulator在prebuilts/android-emulator下,prebuilts目录是官方提供的,下载源码时就已经build好的一些工具和库,包括kernel也在这下面,所以如果自己要build kernel,就看这里。题外话了,回到emulator,切换到emulator目录,运行:
    ./emulator
    -sysdir ${ANDROID_PRODUCT_OUT}
    -system ${ANDROID_PRODUCT_OUT}/system.img
    -ramdisk ${ANDROID_PRODUCT_OUT}/ramdisk.img
    -data ${ANDROID_PRODUCT_OUT}/userdata.img
    -kernel /home/koder/android-source-20151229/prebuilts/qemu-kernel/arm/kernel-qemu-armv7
    -skindir /home/koder/android-source-20151229/sdk/emulator/skins
    -memory 2048
    -partition-size 2048
    -skin WVGA800
    -scale 0.7
     
    自己改好对应目录就好了。个人环境变量是:
     
    JAVA_HOME=/home/koder/Documents/jdk1.8.0_65
    PATH=$JAVA_HOME/bin:$PATH
    CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
    ANDROID_HOME=/home/koder/Documents/android-sdk-linux
    ANDROID_BUILD_OUT_HOST=/home/koder/android-source-20151229/out/host/linux-x86/bin
    ANDROID_PRODUCT_OUT=/home/koder/android-source-20151229/out/target/product/generic
    PATH=$ANDROID_HOME:$ANDROID_BUILD_OUT_HOST:$PATH
    export JAVA_HOME PATH CLASSPATH ANDROID_PRODUCT_OUT
     
               到这里就OK了。
     
     
    BUILD过程中遇到的问题:
     
    1. 提示:increasing heap size。就是Java虚拟机的heap size不够了,添加环境变量:
    export _JAVA_OPTIONS=-Xmx8192m
    赋值大小看自己机器了。
    然而,即使这样设置了,有时候也不起作用,因为可能机器本身硬件内存就不足了,根本就没有8G那么多好吗。由于自己的机器是8G的,而且运行在虚拟机上,只分配到4G的空间,所以build的过程中,内存不足的问题卡了自己很久很久,而且官方说,最好是有16g ram以上,几乎要放弃了。最后想了个办法,增加swap内存。
    至于如何增加swap内存,参考这里
     
    自己直接swap增加了16G,由于本来是8G,所以最好是24G了。
    感叹一下,UNIX的“Everything is file”的伟大,硬件不够,软件来补,呵呵~~~
    解决这个内存问题后,就顺利的build出来了。
     
     

    另外:

    1.查看cccache:watch -n1 -d prebuilts/misc/linux-x86/ccache/ccache -s
     
  • 相关阅读:
    Windows Server 2003中不能安装MSN的解决方法
    招新人的一个标准
    SVN源代码服务器 证书通不过时的解决办法
    项目风险控制
    项目与团队管理体会
    季羡林老先生百年为人处世哲学
    李一男2003年在港湾给开发人员培训时的语录
    项目管理中的一些想法
    poj 1236 Network of Schools
    poj 2528 Mayor's posters
  • 原文地址:https://www.cnblogs.com/chiefhsing/p/5175624.html
Copyright © 2011-2022 走看看