zoukankan      html  css  js  c++  java
  • 基于Ubuntu 14.04 LTS编译Android4.4.2源码

    版权声明:本文为博主原创文章,未经博主同意不得转载。

    https://blog.csdn.net/gobitan/article/details/24367439

    基于Ubuntu 14.04 LTS编译Android4.4.2源码
            Dennis Hu 2014-4-21
    环境准备:
    基本环境:ubuntu-14.04-desktop-64bit LTS(裸机或者Windows下虚拟机安装均可,12.04也能够,但10.04眼下不支持了)
    其它要求:空暇磁盘空间100G以上,代码部分接近10G,其它为git和编译中间和目标文件准备

    ==========================================
    第一部分:环境初始化
    ==========================================
    1. 安装Oracle JDK
    注意:假设编译Android4.4不能用OpenJDK。必须用Oracle JDK1.6。1.7眼下是不支持的。

    具体怎样安装Oracle JDK,请參见我的还有一篇单独的文章。[Ubuntu Linux下安装Oracle JDK] http://blog.csdn.net/gobitan/article/details/24322561.
    2. 安装必备工具软件
    注意:这里与官方的有个包不同,官方的包会报错.
    $sudo apt-get install git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dri:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 dpkg-dev
    $ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
    3. 配置USB訪问权限
    将例如以下内容增加到/etc/udev/rules.d/51-android.rules文件里
    # adb protocol on passion (Nexus One)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="<username>"
    # fastboot protocol on passion (Nexus One)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="<username>"
    # adb protocol on crespo/crespo4g (Nexus S)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="<username>"
    # fastboot protocol on crespo/crespo4g (Nexus S)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="<username>"
    # adb protocol on stingray/wingray (Xoom)
    SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="<username>"
    # fastboot protocol on stingray/wingray (Xoom)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="<username>"
    # adb protocol on maguro/toro (Galaxy Nexus)
    SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="<username>"
    # fastboot protocol on maguro/toro (Galaxy Nexus)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="<username>"
    # adb protocol on panda (PandaBoard)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="<username>"
    # adb protocol on panda (PandaBoard ES)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d002", MODE="0600", OWNER="<username>"
    # fastboot protocol on panda (PandaBoard)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="<username>"
    # usbboot protocol on panda (PandaBoard)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER="<username>"
    # usbboot protocol on panda (PandaBoard ES)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="<username>"
    # adb protocol on grouper/tilapia (Nexus 7)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0600", OWNER="<username>"
    # fastboot protocol on grouper/tilapia (Nexus 7)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0600", OWNER="<username>"
    # adb protocol on manta (Nexus 10)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee2", MODE="0600", OWNER="<username>"
    # fastboot protocol on manta (Nexus 10)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee0", MODE="0600", OWNER="<username>"
    然后运行例如以下命令,将上述文件里的username替换为你的用户名。

    $sudo sed -i 's/username/dennis/g' /etc/udev/rules.d/51-android.rules
    4. 配置ccache
    安装ccache并将export USE_CCACHE=1增加到~/.bashrc中。


    $sudo apt-get install ccache
    $source ~/.bashrc

    ==========================================
    第二部分:源码下载
    ========================================== 
    1. 安装repo
    (1) 创建文件夹
    $ mkdir ~/bin
    $ PATH=~/bin:$PATH
    (2) 下载repo工具
    注:因为防火墙的原因。官方提供的链接无法使用。需替换为例如以下:
    官方的为curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
    可用的:
    curl http://git-repo.googlecode.com/files/repo-1.12 > ~/bin/repo
    (3) 增加可运行权限
    $ chmod a+x ~/bin/repo
    2. 初始化Repoclient
    (1)创建文件夹
    $mkdir aosp
    $cd aosp

    (2) 初始化repo
    注:后面可能出现网络错误,请先将例如以下内容增加到/etc/hosts中然后做后面的步骤。
    74.125.71.82 www.googlesource.com
    74.125.31.82 android.googlesource.com
    203.208.46.172 cache.pack.google.com
    59.24.3.173 cache.pack.google.com
    至于为什么要出现网络错误,你懂的!

    $repo init -u https://android.googlesource.com/platform/manifest -b android-4.4.2_r2
    注意:假设是在虚拟机中运行。须要採用email验证的方式,具体參见參考资料[2].
    设置git的用户名和邮件地址。将您的真实email地址和name替换了:
    git config --global user.email "you@example.com"
    git config --global user.name "Your Name"
    改动aosp/.resp/manifest.xml,将fetch=".."改为:
    fetch="https://android.googlesource.com/"

    3. 下载源码
    $repo sync
    注意:系统可能会提示你升级repo,最好不要升级,除非你有十足信息解决升级后的一系列问题。

    好了。慢慢等吧,短则数小时。长则几天几夜!

    我花了5个小时


    ==========================================
    第三部分:源码编译 
    ==========================================
    1. 设置ccache
    注:aosp为源码根文件夹
    $ cd aosp
    $ prebuilts/misc/linux-x86/ccache/ccache -M 50G
    2. 设置输出文件夹
    略:因为我未分区,因此採用默认的out文件夹
    3. 初始化编译环境
    dennis@dubuntu1404:~/devenv/aosp$ . build/envsetup.sh 
    including device/samsung/manta/vendorsetup.sh
    including device/generic/mips/vendorsetup.sh
    including device/generic/armv7-a-neon/vendorsetup.sh
    including device/generic/x86/vendorsetup.sh
    including device/lge/mako/vendorsetup.sh
    including device/lge/hammerhead/vendorsetup.sh
    including device/asus/tilapia/vendorsetup.sh
    including device/asus/deb/vendorsetup.sh
    including device/asus/grouper/vendorsetup.sh
    including device/asus/flo/vendorsetup.sh
    including sdk/bash_completion/adb.bash
    dennis@dubuntu1404:~/devenv/aosp$ 
    4. 选择编译目标包
    注:目标包的选择跟你的硬件有关。我这里选择9,mako
    dennis@dubuntu1404:~/devenv/aosp$ lunch
    You're building on Linux
    Lunch menu... pick a combo:
         1. aosp_arm-eng
         2. aosp_x86-eng
         3. aosp_mips-eng
         4. vbox_x86-eng
         5. aosp_manta-userdebug
         6. mini_mips-userdebug
         7. mini_armv7a_neon-userdebug
         8. mini_x86-userdebug
         9. aosp_mako-userdebug
         10. aosp_hammerhead-userdebug
         11. aosp_tilapia-userdebug
         12. aosp_deb-userdebug
         13. aosp_grouper-userdebug
         14. aosp_flo-userdebug
    Which would you like? [aosp_arm-eng] 9
    ============================================
    PLATFORM_VERSION_CODENAME=REL
    PLATFORM_VERSION=4.4.2
    TARGET_PRODUCT=aosp_mako
    TARGET_BUILD_VARIANT=userdebug
    TARGET_BUILD_TYPE=release
    TARGET_BUILD_APPS=
    TARGET_ARCH=arm
    TARGET_ARCH_VARIANT=armv7-a-neon
    TARGET_CPU_VARIANT=krait
    HOST_ARCH=x86
    HOST_OS=linux
    HOST_OS_EXTRA=Linux-3.13.0-24-generic-x86_64-with-Ubuntu-14.04-trusty
    HOST_BUILD_TYPE=release
    BUILD_ID=KVT49L
    OUT_DIR=out
    ============================================
    dennis@dubuntu1404:~/devenv/aosp$ make -j4
    注:j4中的数字跟你的CPU个数和核数有关。具体參见參考资料[3].
    整个编译过程,大约花了三个小时。编译成功后会在out文件夹下生成img文件。


    5. 将img载入到物理机
    (1) 将手机用USB数据线连接到机器
    (2) 安装fastboot工具
    $ sudo apt-get install android-tools-fastboot
    (3) 设置ANDROID_PRODUCT_OUT环境变量
    将例如以下部分增加~/.bashrc文件里:
    export ANDROID_PRODUCT_OUT=/home/dennis/devenv/aosp/out/target/product/mako
    然后保存运行". .bashrc"使其生效。

    (4) 以fastboot模式重新启动手机
    $ adb reboot bootloader
    此时手机会重新启动,呈现一个与往不同的fastboot界面

    (5) 将编译的img刷到目标机
    dennis@dubuntu1404:~/devenv/aosp/out$ fastboot flashall -w
    --------------------------------------------
    Bootloader Version...: PRIMEMD04
    Baseband Version.....: I9250XXLJ1
    Serial Number........: 0146A0D00600900B
    --------------------------------------------
    checking product...
    FAILED
    Device product is 'tuna'.
    Update requires 'mako'.
    finished. total time: 0.035s
    (注:因为我的物理机三星I9250在lunch里没有相应的型号,因此会载入失败,这里这是记录过程)
    ===================================
    假设须要编译其它版本号。可运行例如以下步骤,这里选择虚拟机用的通用版本号aosp_arm-eng。
    $ cd aosp
    dennis@dubuntu1404:~/devenv/aosp$ . build/envsetup.sh
    including device/samsung/manta/vendorsetup.sh
    including device/generic/mips/vendorsetup.sh
    including device/generic/armv7-a-neon/vendorsetup.sh
    including device/generic/x86/vendorsetup.sh
    including device/lge/mako/vendorsetup.sh
    including device/lge/hammerhead/vendorsetup.sh
    including device/asus/tilapia/vendorsetup.sh
    including device/asus/deb/vendorsetup.sh
    including device/asus/grouper/vendorsetup.sh
    including device/asus/flo/vendorsetup.sh
    including sdk/bash_completion/adb.bash
    dennis@dubuntu1404:~/devenv/aosp$ lunch aosp_arm-eng
    ============================================
    PLATFORM_VERSION_CODENAME=REL
    PLATFORM_VERSION=4.4.2
    TARGET_PRODUCT=aosp_arm
    TARGET_BUILD_VARIANT=eng
    TARGET_BUILD_TYPE=release
    TARGET_BUILD_APPS=
    TARGET_ARCH=arm
    TARGET_ARCH_VARIANT=armv7-a
    TARGET_CPU_VARIANT=generic
    HOST_ARCH=x86
    HOST_OS=linux
    HOST_OS_EXTRA=Linux-3.13.0-24-generic-x86_64-with-Ubuntu-14.04-trusty
    HOST_BUILD_TYPE=release
    BUILD_ID=KVT49L
    OUT_DIR=out
    ============================================
    dennis@dubuntu1404:~/devenv/aosp$ make -j4
    ============================================
    PLATFORM_VERSION_CODENAME=REL
    PLATFORM_VERSION=4.4.2
    TARGET_PRODUCT=aosp_arm
    TARGET_BUILD_VARIANT=eng
    TARGET_BUILD_TYPE=release
    TARGET_BUILD_APPS=
    TARGET_ARCH=arm
    TARGET_ARCH_VARIANT=armv7-a
    TARGET_CPU_VARIANT=generic
    HOST_ARCH=x86
    HOST_OS=linux
    HOST_OS_EXTRA=Linux-3.13.0-24-generic-x86_64-with-Ubuntu-14.04-trusty
    HOST_BUILD_TYPE=release
    BUILD_ID=KVT49L
    OUT_DIR=out
    ============================================
    including ./abi/cpp/Android.mk ...
    including ./art/Android.mk ...
    ....中间过程省略
    Install system fs image: out/target/product/generic/system.img
    out/target/product/generic/system.img+ maxsize=588791808 blocksize=2112 total=576716800 reserve=5947392
    编译完毕,运行例如以下命令能够将您刚build好的ROM在模拟器里运行起来,第一次启动的时间可能比較长:
    $ emulator &
    注意:假设提示找不到emulator命令,可将例如以下环境变量又一次初始化一遍(也就是每次又一次进入系统运行的时候,都须要初始化一遍),lunch后面的參数要与你编译的ROM选项一致。

    $. build/envsetup.sh
    $lunch aosp_arm-eng
    转载请注明出处: 雨水:http://blog.csdn.net/gobitan/article/details/24367439 

    更新日志:
    2014-4-25:增加自己编译的ROM在模拟器里的运行方法;

    參考资料:


查看全文
  • 相关阅读:
    Systemd 进程管理教程
    traefik的80和443端口占用进一步分析
    使用KubeOperator安装k8s集群后,节点主机yaml文件路径
    kubernetes1.20 部署 traefik2.3
    数据采集实战(二)-- 京粉商品
    机器人导航(仿真)(三)——路径规划(更新中)
    机器人导航(仿真)(二)——amcl定位
    Tkinter 做简单的窗口视窗 Python GUI
    机器人导航(仿真)(一)——SLAM建图
    (转载)VMware Workstation Ubuntu 20.04 无法连接网络问题
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10650828.html
  • Copyright © 2011-2022 走看看