积跬步至千里系列之十--编译Android源码实践

Android源码编译的步骤之前看过,没有自己实践过。今天抽出时间写一篇自己编译源码的总结。
我的源码是从别人硬盘上拷贝的所有版本的镜像,省去了翻墙下载的漫长过程。Android源码是用repo来进行管理的,我的理解repo其实就是对git的又一次封装,在git包含了所有的项目分支。
1.第一步.获取源码。根据google给出的文档说明,可以知道获取源码一般有两种方式,第一种是从google提供的源码链接中获取,然后获取指定分支,拉取代码;另外一种方式就是从一个镜像中检出获取。我在实践编译时使用的第二种,省区了漫长的等待时间.下面就说一下两种方式

第一种 : 根据源码链接获取
//创建一个空目录
$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY
//配置用户名和邮箱
$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"
//init命令会根据url所指向的地址获取最新的版本
$ repo init -u https://android.googlesource.com/platform/manifest
//该命令表示从url中检出-b后所指定的特定分支 
repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
//接下来就是获取上面所指定的分支代码
$ repo sync

第二种:从一个镜像获取.不需要网络连接
//create and sync the mirror itself. 
$ mkdir -p /usr/local/aosp/mirror
$ cd /usr/local/aosp/mirror
$ repo init -u https://android.googlesource.com/mirror/manifest --mirror
$ repo sync

//Once the mirror is synced, new clients can be created from it. Note that it's important to specify an absolute path:

$ mkdir -p /usr/local/aosp/master
$ cd /usr/local/aosp/master
$ repo init -u /usr/local/aosp/mirror/platform/manifest.git
$ repo sync

//Finally, to sync a client against the server, the mirror needs to be synced against the server, then the client against the mirror:

$ cd /usr/local/aosp/mirror
$ repo sync
$ cd /usr/local/aosp/master
$ repo sync

2.下载固件.我使用的是Nexus5,这个需要到源码目录下执行lunch看一下要编译的版本所对应的版本名称,然后到google上下载对应的固件。

lunch

You're building on Darwin

Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_arm64-eng
     3. aosp_mips-eng
     4. aosp_mips64-eng
     5. aosp_x86-eng
     6. aosp_x86_64-eng
     7. aosp_deb-userdebug
     8. aosp_flo-userdebug
     9. full_fugu-userdebug
     10. aosp_fugu-userdebug
     11. aosp_grouper-userdebug
     12. aosp_tilapia-userdebug
     13. mini_emulator_arm64-userdebug
     14. m_e_arm-userdebug
     15. mini_emulator_mips-userdebug
     16. mini_emulator_x86-userdebug
     17. mini_emulator_x86_64-userdebug
     18. aosp_flounder-userdebug
     19. aosp_hammerhead-userdebug
     20. aosp_mako-userdebug
     21. aosp_shamu-userdebug
     22. aosp_manta-userdebug

Which would you like? [aosp_arm-eng] 21

如上图,我们进入到检出的源码根据目录中,执行lunch命令,就会列出一个编译版本列表,我们从终端键入我们要编译的版本前面的编号,如21,会有如下输出:

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=5.1.1
TARGET_PRODUCT=aosp_shamu
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=krait
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_OS=darwin
HOST_OS_EXTRA=Darwin-14.5.0-x86_64-i386-64bit
HOST_BUILD_TYPE=release
BUILD_ID=LMY48M
OUT_DIR=out
============================================

如上图,终端输出了所选择的21版本所对应的信息,其中列出了具体的详细各种配置和具体的名称版本等信息。其中我们可以看到,BUILD_ID:其表示的就是22所独影的编译版本id,我们所要下载的固件就是根据该名称来确定。还有OUT_DIR表示编译后生成的文件会在out目录下。接下来,我们就根据上面拿到的BUILD_ID去下载固件.我们在google搜google nexus image 选第一个就是google设备对应的固件支持列表,我们找到要找的LMY48M所对应的列表,然后点击下载固件。
三个固件都是tar包。下载后使用tar -xvf 将三个tar包依次解压,解压之后得到三个.sh可执行脚本文件,然后将三个文件放在android源码的根目录下:

extract-broadcom-shamu.sh
extract-moto-shamu.sh
extract-qcom-shamu.sh

接下来就是执行编译命令,依次执行如下:

$ . build/envsetup.sh
$ make -j32

接下来就开始编译了,等着编译完成就好了。等到编译完成之后,我们就将编译好的系统刷到设备中就好了,向设备上刷系统:

//进入bootloader模式
$ adb reboot bootloader
//刷进设备中
$ fastboot flashall -w 

在编译之前,还可以设置添加一个缓存,这样在下次编译时就可以省去java层的编译.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值