如何为Google的Nexus 5手机编译Android KitKat(4.4)

http://blog.csdn.net/michaelpp/article/details/26073867
Howto Build Android KitKat (4.4) for the Google Nexus 5
如何为Google的Nexus 5手机编译Android KitKat(4.4)


December 1, 2013
2013-12-01


[Screenshot of KitKat AOSP Running on the Google Nexus 5]
KitKat AOSP在Google Nexus 5上的运行截图。


NOTE: If you know what this is, and just want to start with a basically working source tree, skip to the section titled “Just Build the Thing ?.”
请严重注意:如果你知道怎么做,只是想开始一个基本的工作源代码树,请跳过前面的章节,直觉前往本节:只是编译系统。




Overview
概述:


This page describes the steps necessary to compile the Android Open Source Project (AOSP) sources into a working phone image for the Google Nexus 5 (Here-forth called "hammerhead.")
本文描述了必须的步骤:编译Android开放源代码工程(AOSP)的源代码,为Google Nexus 5(又称为:hammerhead)生成一个可以工作的手机镜像文件。


If the process of building Android sources is new to you, please start by reading the Android documentation on “Downloading and Building,” in full.
如果你不熟悉编译Android源代码的过程,请开始完整地阅读Android文档:下载和编译Android。
http://source.android.com/source/building.html


This method includes:
这些方法包括:


1. Android Open Source Project as a basis
2. Additional proprietary files for the hammerhead, to enable GPS, comms, etc.
3. Additional proprietary files to support the Google Apps suite (Play store, GMail, et al.)
4. In-tree kernel build from source


1、Android开放源代码工程是最基础的。
2、hammerhead的附件的属性文件:开关GPS、电话本等等功能。
3、附件的属性文件以支持Google应用程序套件(Play应用程序商店、GMail等等。)
4、从源代码数中编译内核。




Obtain the AOSP Sources
获取AOSP的源代码


The Android page on Building for Devices tells us to use the android-4.4_r1 tag for the Hammerhead. Incidentally, as per the Google release notification, this is the same baseline used for the KRT16M factory image.
在编译设备的Android页面,告诉我们如何为Hammerhead使用android-4.4_r1这个TAG版本。
http://source.android.com/source/building-devices.html#picking-and-building-the-configuration-that-matches-a-device
顺便说一下,对于每一个Google的发行版公告,使用KRT16M工厂镜像的话就会具有相同的时间轴。
https://groups.google.com/d/msg/android-building/JVLaFRoJxFk/1qVKNV2oKG4J


This procedure is well documented:
本过程的详细文档请参考:
http://source.android.com/source/downloading.html#initializing-a-repo-client


1. repo init -u https://android.googlesource.com/platform/manifest -b android-4.4_r1
2. repo sync


!!!!请严重注意,在中国大陆,这个过程会出错。更多请参考:
http://blog.csdn.net/sunao2002002/article/details/47869281
如何不翻墙下载Android代码
repo init -u git://aosp.tuna.tsinghua.edu.cn/android/platform/manifest -b android-4.4_r1
repo sync




Obtain the Vendor Proprietary Files
获取供应商的专有文件


There are a few methods to do this, but the (at face value) easiest is to download the vendor files from the Nexus Device Binaries page.
有几个方法可以干这事,但是(表面上)最容易方法的就是从Nexus设备的二进制页面下载供应商文件。


1. wget https://dl.google.com/dl/android/aosp/broadcom-hammerhead-krt16m-bf9b8548.tgz
2. wget https://dl.google.com/dl/android/aosp/lge-hammerhead-krt16m-0efa9c33.tgz
3. wget https://dl.google.com/dl/android/aosp/qcom-hammerhead-krt16m-53cf1896.tgz


!!!!请严重注意,在中国大陆,这个过程会出错。更多请参考(建议用迅雷之类的下载工具手动下载):
http://news.mydrivers.com/1/281/281003.htm
Nexus 5 Android 4.4官方底包公布了


Now, untar the packages, and run the extractor scripts:
现在要做的就是打开压缩包,运行提取脚本:


1. for f in *.tgz; do tar xzf $f; done
2. for extractor_script in *.sh; do bash $extractor_script; done


After you go through the EULAs and type “I ACCEPT”, once for each extractor, you’ll have directory trees at vendor/broadcom/hammerhead, vendor/lge/hammerhead, vendor/qcom/hammerhead.
当你看完EULA之后(小经验:按F2可以跳到最后^_),需要输入大写的“I ACCEPT”,每次提取都需要输入一次。全部(三次)做完之后你就会看见这些目录:vendor/broadcom/hammerhead、vendor/lge/hammerhead、vendor/qcom/hammerhead。


Now, in the past, these proprietary binary releases have been fairly comprehensive. Unfortunately, the LG and Qualcomm drops appear to be missing some critial files. (Take my word for it — you won’t have 3G / cellular connectivity.)
以前,这些专有的二进制发行版都是非常完整的。不幸的是,LG和Qualcomm似乎是删除了一些关键性的文件。(请相信我吧——否则你的镜像文件将不会有3G/蜂窝网络连接。)


If you look at proprietary-blobs.txt and vendor_owner_info.txt (both in the device/lge/hammerhead project), you’ll see that the following files are mentioned, but are not present at this point in the vendor trees.
如果你查看proprietary-blobs.txt和vendor_owner_info.txt(两者都在device/lge/hammerhead工程中),你将会看到被提及的这些文件,此时此刻并没有出现在专有文件列表里。
https://android.googlesource.com/device/lge/hammerhead/+/android-4.4_r1/proprietary-blobs.txt
https://android.googlesource.com/device/lge/hammerhead/+/android-4.4_r1/vendor_owner_info.txt


Missing from vendor/lge/hammerhead:
这个目录vendor/lge/hammerhead中缺少的文件列表:


01. /system/app/OmaDmclient.apk
02. /system/etc/DxHDCP.cfg
03. /system/vendor/bin/vss_init
04. /system/vendor/firmware/discretix/dxhdcp2.b00
05. /system/vendor/firmware/discretix/dxhdcp2.b01
06. /system/vendor/firmware/discretix/dxhdcp2.b02
07. /system/vendor/firmware/discretix/dxhdcp2.b03
08. /system/vendor/firmware/discretix/dxhdcp2.mdt
09. /system/vendor/lib/libDxHdcp.so
10. /system/vendor/lib/libvdmengine.so
11. /system/vendor/lib/libvdmfumo.so
12. /system/vendor/lib/libvss_common_core.so
13. /system/vendor/lib/libvss_common_idl.so
14. /system/vendor/lib/libvss_common_iface.so
15. /system/vendor/lib/libvss_nv_core.so
16. /system/vendor/lib/libvss_nv_idl.so
17. /system/vendor/lib/libvss_nv_iface.so


And these, from vendor/qcom/hammerhead:
这个目录vendor/qcom/hammerhead中缺少:


1. /system/app/shutdownlistener.apk
2. /system/app/TimeService.apk


Note: actually, OmaDmclient.apk is probably the only one that has to do with cellular networks. (See OMA DM description.)
注意:实际上,OmaDmclient.apk可能是唯一一个与蜂窝网络相关的应用程序。(更多请参考:OMA DM)


So, to fix this, we need to do two things:
因此,要解决这些问题,我们需要做两件事情:


1. Obtain the binaries;
2. Add them to the build system.


1、获取这些二进制文件;
2、将他们加入到android系统中并在编译过程中包含他们。(将他们加入到编译系统中)


For the first, it is possible to rip the binaries from the KRT16M factory image. To do this, you can either simply pull them from a working (stock) hammerhead device, as mentioned here — or, you can rip them from the Factory image file directly. The second method is clearly more repeatably correct, so let’s go that route.
首先,你所要做的就是打开KRT16M的二进制格式的工厂镜像文件。为了做到这一点,你只需要简单地将他们从一个可以正常工作的(原始的)hammerhead手机中pull出来(adb pull)。这里将会介绍一种更加简单的做法:你可以直接从工厂镜像文件中获取他们。第二种方法显然更加简便宜行,因为我们将会走这条路。


Get the factory image release and untar it:
获取工厂镜像的发行版并将其解压缩:


1. wget https://dl.google.com/dl/android/aosp/hammerhead-krt16m-factory-bd9c39de.tgz
2. tar xzf hammerhead-krt16m-factory-bd9c39de.tgz
3. cd hammerhead-krt16m


!!!!请严重注意,在中国大陆,这个过程会出错。更多请参考(建议用迅雷之类的下载工具手动下载):
http://news.mydrivers.com/1/281/281003.htm
Nexus 5 Android 4.4官方底包公布了


Decompress that actual phone image:
解压缩那个真实的手机镜像文件:


1. unzip image-hammerhead-krt16m.zip


At this point, you will see the system partition, system.img. To convert it to something mountable, you need to run it through the simg2img tool that is built with AOSP by default. (When you build android, it shows up at $TOP/out/host/linux-x86/bin/simg2img):
解压缩之后,你将会看见系统分区文件:system.img。通过运行在默认编译AOSP的时候生成的simg2img工具,你就可以在ubuntu下挂载system.img。(当你编译android的时候,就会在这个目录$TOP/out/host/linux-x86/bin/simg2img找到它。)


1. simg2img system.img system.img.raw


Now, mount the thing:
现在,就可以在ubuntu下挂载了:


1. mount -oloop -t ext4 system.img.raw /mnt


From here, you’ll have to copy the files listed above, from the /mnt, into your build tree. There’s undoubtedly countless ways to do that, but I suggest something like this:


到现在为止,你只需要从目录/mnt中将上面列表中所缺少的文件拷贝到你的android工程中。无疑有千百种方法可以用,但是我建议使用下面的脚本:


1. for file in $lge_missing_files; do
2.     mnt_location=$(find /mnt -name $(basename $file))
3.     cp $mnt_location vendor/lge/hammerhead/proprietary/
4. done


And then likewise for the Qualcomm files, replacing lge for qcom.
对于Qualcomm文件,只需要将lge替换为Qualcomm即可!


ALRIGHT. So once we have obtained the files, we need to add them to the build system.
全部完成之后,我们将获得这些文件,但是我们还是需要将他们加入到android系统的编译中去。


To do this, you need to add PRODUCT_COPY_FILES rules for each of these additional files, so that they get included in the eventual Android phone image. An example of that is shown here, in my github project for vendor/lge/hammerhead, and here, for vendor/qcom/hammerhead.
要做到这一点,你需要为每一个添加的文件增加PRODUCT_COPY_FILES规则,这样它们将会被包含在最终的Android手机镜像中。在我的github工程中有一个实例,目录vendor/lge/hammerhead的在这里:
https://github.com/jamesonwilliams/vendor_lge_hammerhead
目录vendor/qcom/hammerhead的在这里:
https://github.com/jamesonwilliams/vendor_qcom_hammerhead/commit/75b01aecc2792aab308885dd16de43e59ba2e54a
https://github.com/jamesonwilliams/vendor_qcom_hammerhead


Note that if you don’t feel like going through all of this BS, you could of course just checkout and use these projects, in lieu of running the extractor scripts for LG and Qualcomm:
注意:如果你不想知道所有这些细节问题,你还是可以只checkout代码并使用这个工程的,这样可以代替运行LG和Qualcomm的提取脚本。


1. rm -r -f vendor/lge/hammerhead vendor/qcom/hammerhead
2. git clone https://github.com/jamesonwilliams/vendor_lge_hammerhead.git vendor/lge/hammerhead
3. git clone https://github.com/jamesonwilliams/vendor_qcom_hammerhead.git vendor/qcom/hammerhead


The last, and critical step, is to modify the device project, so that these vendor files are used (ref: git commit):
最后一步,也是最关键的一步,就是修改设备工程。以便使用这些内核文件(请参考git的描述)。
https://github.com/jamesonwilliams/device_lge_hammerhead/commit/75e110fdfcf7022f752d70e610198ed5bf5928eb


1. sed -i '/^PRODUCT_RESTRICT_VENDOR_FILES/s/true/false/' device/lge/hammerhead/full_hammerhead.mk


作用:将
PRODUCT_RESTRICT_VENDOR_FILES := true
修改为:
PRODUCT_RESTRICT_VENDOR_FILES := false




Obtain the Google Proprietary Apps
获取Google的专属应用程序


Now, usually, RootzWiki posts the Google Apps update packages here, and with a little finagling, you can adapt the updater-script into makefile rules for the Android Build System. Unfortunately, at time of writing, RootzWiki has not provided an update package for KitKat.
现在,通常情况下,RootzWiki会在这里发布Google的应用程序升级包。通过技术处理(欺骗手段),你可以在makefile文件中适配升级脚本来编译Android系统。不幸的是,在本文完成之时,RootzWiki还没有来得及为KitKat提供一个升级包。


The most mature bundling of the Google Apps I have found for KitKat so far is from the Paranoid Andorid crew, as mentioned on this post.
到目前为止,我发现Google(KitKat)应用程序的最成熟的打包方法是从骨灰级Andorid玩家那里释放出来的,以前提到过。
https://plus.google.com/107979589566958860409/posts/FYkuneXi3J7


The creation of my vendor/google/gapps project from this file is sort of outside the scope of this page, but I will mention a few of the main points.
我的vendor/google/gapps工程的创建方法不在本文讨论了,但是我将会提到几个要点。
https://github.com/jamesonwilliams/vendor_google_gapps


Inspiration was taken from jpuderer's vendor-aospplus project.
灵感来自jpuderer的vendor-aospplus工程。
https://github.com/jpuderer/vendor-aospplus/tree/master/mako


Module rules and product copy file rules were created from scratch, for each of the proprietary files found in the Paranoid Android package.
对于每一个在Paranoid Android包中所发现的属性文件,模块的规则和产品复制文件的规则是通过修改创建的。


These rules were further developed to include packages like Chrome, and to override packages that are included in AOSP but not in the default factory image. (A very noticable example is that the new Google Home launcher overrides the old Launcher3.)
这些规则被进一步的拓展以便包含像Chrome这样的应用程序包,并且重载AOSP中的包,但也不是官方的工厂刷机包。(一个显而易见的例子是新版的Google的主页launcher程序包是由旧版本的Launcher3重载得到的。)


In short, to include the Google apps, you need to checkout this project:
长话短说(总之),为了包含Google的应用程序包,你需要checkout这个工程:


1. mkdir -p vendor/google
2. git clone https://github.com/jamesonwilliams/vendor_google_gapps.git vendor/google/gapps


And add rules to vendor/lge/hammerhead, so that the makefiles get included in the build:
给vendor/lge/hammerhead添加规则,以便makefile文件能够在编译的时候包含进来:
Z:\wyb\nexus5_android-4.4_r1\vendor\lge\hammerhead


1. cat >> vendor/lge/hammerhead/BoardConfigVendor.mk <<- EOF
2. -include vendor/google/gapps/BoardConfigPartial.mk
3. EOF
4.  
5. cat >> vendor/lge/hammerhead/device-vendor.mk <<- EOF
6. $(call inherit-product-if-exists, vendor/google/gapps/device-partial.mk) (????这个文件有呀!最后一行就是呀!)
7. EOF
(Ref: github commit.)
https://github.com/jamesonwilliams/vendor_lge_hammerhead/commit/b75465d8fc6515a8d53047a7afe6a43250668353




Including the Kernel Sources
包含内核源文件(!!!!暂时还没有办法拿到这个源码包)


By default, the AOSP image for hammerhead uses a prebuilt kernel binary, specifically device/lge/hammerhead-kernel/zImage-dtb. In order to build the kernel from source, we need to do a few things:
默认情况下,hammerhead的AOSP镜像文件使用的是预编译的内核二进制文件,尤其是:device/lge/hammerhead-kernel/zImage-dtb。如果要编译内核源码,我们需要做这些事情:


1. Get the correct version of the kernel source;
2. Adapt the AndroidKernel.mk for an in-tree build;
3. Adapt the device/lge/hammerhead project, to include the new kernel.


1、获取正确版本的内核源代码。
2、为编译树适配AndroidKernel.mk。
3、适配device/lge/hammerhead工程以包含新的内核。


At time of writing, the Android documentation on Building Kernels has not been updated with instructions for hammerhead. However, it’s very similar to the Nexus 4 (mako) procedure.
在成文的时候,Android的内核编译文档还没有为hammerhead手机更新指令。但是,它是和Nexus 4(mako)的编译过程是非常相似的。
http://source.android.com/source/building-kernels.html


Get the source by:
获取内核源码的方法:


1. git clone https://android.googlesource.com/kernel/msm.git -b android-msm-hammerhead-3.4-kk-r1 kernel
(!!!!暂时还没有办法拿到这个源码包)


You can verify that the commit that branch points to is the same as the stock kernel.
你能够验证以确保那个分之指向同样原始的内核。
https://android.googlesource.com/kernel/msm.git/+/9eb14badd0f9ab0792100a16c52f460e716c9ebe


Now, make a few tweaks to fix the kernel build:
现在,需要做一些调整来修正内核编译:


1. # The build fails if we try to make the modules, so remove those lines:
2. sed -i '48,51d' kernel/AndroidKernel.mk
3.  
4. # Build a dtb kernel, not the default zImage:
5. sed -i '47s,$, zImage-dtb,' kernel/AndroidKernel.mk


Finally, we need to modify the device project.
最后,我们需要修改设备工程。


This is a bit more involved, but you can see the patch needed in my github project.
这里有一点麻烦,但是你能够在我的github工程中找到所需要的patch文件。
https://github.com/jamesonwilliams/device_lge_hammerhead/commit/fe714801e33b38af4a81ddc3f40c3fdc53583f66




Just Build the Thing
只是编译系统:


Alright. All that above was stuff I had to do. But if you had to do it everytime, you’d probably put a shotgun to your face. Fortunately, I’ve uploaded all the miscellaneous bits and pieces to github repositories, and linked them all together with my own manifest.
因此,上面所叙述的步骤都是必须的。但是如果你每次都得这样做,你可能会拿把枪指着我的脸。幸运的是,我将所有的这些乱七八糟的文件都上传到github上了,并且在我的主页上将他们都链接在一起。


In short, just grab the working tree by doing this:
总之,只要通过这样做来获取工具目录,


1. repo init -u git://github.com/jamesonwilliams/platform_manifest.git -b android-4.4_r1.1
2. repo sync


repo init -u git://aosp.tuna.tsinghua.edu.cn/android/platform/manifest -b android-4.4_r1
repo sync


So, you can just do that instead.
因此,你也能仅仅只这样做:


All you need to do now is build the tree:
你现在所需要做的仅仅只是编译这个工程:


1. source build/envsetup.sh
2. lunch aosp_hammerhead-userdebug
3. make clean
4. make updatepackage -j10




增加eng/user模式:
Z:\wyb\orig_nexus5_android-4.4_r1\device\lge\hammerhead\vendorsetup.sh
add_lunch_combo aosp_hammerhead-eng
add_lunch_combo aosp_hammerhead-user
add_lunch_combo aosp_hammerhead-userdebug


source build/envsetup.sh
lunch aosp_hammerhead-eng
make clean
make updatepackage -j8




Deploy the thing
部署事宜:


After the build (successfully) completes, you’ll be left with an update image package here:
在编译(成功)完成之后,你就能够在这里得到用于更新的镜像包:


1. UPDATE_PACKAGE="$OUT/$TARGET_PRODUCT-img-$TARGET_BUILD_VARIANT.$USER.zip"
2. echo $UPDATE_PACKAGE


Make sure your hammerhead device has USB debugging enabled. (If you need help with this, YouTube can help. Like This video.)
请确保您的hammerhead手机已经打开了USB调试模式。(如果你想知道如何打开调试模式,上YouTube找吧。)
http://www.youtube.com/watch?v=aLQ-nNMXwAc


Enter the bootloader and unlock the device:
进入bootloader模式后将手机解锁。


1. adb reboot-bootloader
2. fastboot oem unlock


Lastly, flash the device, and reboot it:
最后,将手机刷机并重启。


1. fastboot -w update $UPDATE_PACKAGE
2. fastboot continue


Errata
Technically speaking, android-4.4_r1 (KRT16M) is the documented tag for hammerhead, while I have used android-4.4_r1.1 (KRT16O), here. As per the Google release announcement, the only difference is that this release includes also support for the Nexus 4, Nexus 7, and Nexus 10. So, it’s more convenient to use that tag, if you’re ultimately supporting the full range of devices.


勘误表:
从技术上讲,android-4.4_r1(KRT16M)是hammerhead的发布标记,因此我在这里使用android-4.4_r1.1(KRT16O)。对于每一个Google的发型版,唯一不同的是这个发行版可以支持Nexus 4、Nexus 7甚至Nexus 10。因此,如果你最终将要支持全系列设备的话,使用这个TAG版本将会更加方便。




本文所需要的一些参考文档:
http://pan.baidu.com/s/1nun5jy5
链接:http://pan.baidu.com/s/1i4kV2Xv 密码:1nov

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值