爲Nexus5編譯AndroidL固件
接前一篇文章使用Android Studio查看Android Lollipop源碼, 我們知道,僅僅看代碼,提高是比較有限的,而且理解起來也比較膚淺,往往過目就忘. 而自己寫過的代碼,往往會印象比較深刻,在寫的時候也會比較容易理解流程. 所以我們在看代碼的同時, 如果能修改代碼, 在手機上跑起來並看到修改的效果,這無疑會加快看代碼的效率和積極性. 所以這篇文章,就講解一下如何自己編譯AndroidL的源碼,並且在Nexus5上跑起來. 至於爲何需要自己編譯固件,而不是直接安裝Google給出的工廠固件?原因是Google給出的工廠固件是User版本,是沒法隨心所欲Push東西進去的. 所以我們需要編譯自己的Userdebug版本.
本文假設你已經下載了AndroidL的源碼,並且有一臺Nexus5手機(手機系統開發人員必備), 如果你還沒有AndroidL的源碼,或者你有源碼但是沒有配置編譯的環境,那麼 Initializing a Build Environment 和Downloading the Source這兩篇文章你應該先去看一下(我又一次假設你會翻牆,如果你不會翻牆,那麼下代碼也是一個痛苦的事情). 這後面的教程Google官網也有教程.所以我只針對Nexus5進行講解.
另外你需要知道AOSP,AOSP即Android Open Source Project 漢語意思是:谷歌開放源代碼項目.我們通過Google官方下載的源代碼,就是AOSP的代碼, 其中是不包含Google開發的那些個應用的,各個廠商拿到的也是這個版本,在這個版本的基礎上進行修改. 而Google發佈的工廠固件則是包含全套Google服務的. 廠商如果想安裝Google服務,就需要過Google的那一套認證,比較麻煩,而且價格不菲,鑑於Google在國內的尷尬地位,國內很多廠商都沒有過這個認證.
1. 初始化編譯環境
1
|
. build/envsetup.sh
|
2. 加載機型
1
|
lunch
|
3. 選擇要編譯的機器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
You're building on Linux 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_shamu-userdebug 8. aosp_manta-userdebug 9. full_fugu-userdebug 10. aosp_fugu-userdebug 11. aosp_grouper-userdebug 12. aosp_tilapia-userdebug 13. aosp_deb-userdebug 14. aosp_flo-userdebug 15. aosp_mako-userdebug 16. aosp_hammerhead-userdebug 17. aosp_flounder-userdebug 18. mini_emulator_x86_64-userdebug 19. mini_emulator_arm-userdebug 20. mini_emulator_x86-userdebug 21. mini_emulator_mips-userdebug 22. mini_emulator_arm64-userdebug |
3.1 機型對照表
DEVICE | CODE NAME | BUILD CONFIGURATION |
---|---|---|
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-userdebug3.2 |
3.2 三個版本說明版本
BUILDTYPE | USE |
---|---|
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 |
選擇aosp_hammerhead-userdebug之後,會有下面的確認信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=5.0.50.50.50.50 TARGET_PRODUCT=aosp_hammerhead 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=linux HOST_OS_EXTRA=Linux-3.13.0-37-generic-x86_64-with-Ubuntu-14.10-utopic HOST_BUILD_TYPE=release BUILD_ID=AOSP OUT_DIR=out ============================================ |
4. 生成驅動目錄
接下來需要在Android官網下載 Nexus5所需要的驅動:
HARDWARE COMPONENT | COMPANY | DOWNLOAD | MD5 CHECKSUM | SHA-1 CHECKSUM |
---|---|---|---|---|
NFC, Bluetooth, Wi-Fi | Broadcom | Link | 2c398994e37093df51b105d63f0eb611 | 991346159c95ae75f760014a6822b8b3e8667700 |
Camera, Sensors, Audio | LG | Link | 74cf8235e6bb04da28b2ff738b13eee9 | 175dd5bae81bb54030d072cb0f0b4ec81eb3f71f |
Graphics, GSM, Camera, GPS, Sensors, Media, DSP, USB | Qualcomm | Link | 0a43395e175d3de3dc312d8abdcb4f20 | 007cf9d49f0409d5c703e7f2811fd153fee22353 |
下載完成後,解壓出來是三個.sh文件,放到Android源碼目錄下面,然後執行.會將相關驅動放到vender目錄下面.
5. 執行編譯命令
1
|
make -j8
|
如果沒有出錯的話,在經過漫長的時間之後,編譯成功:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Installed file list: out/target/product/hammerhead/installed-files.txt Target system fs image: out/target/product/hammerhead/obj/PACKAGING/systemimage_intermediates/system.img Running: mkuserimg.sh -s out/target/product/hammerhead/system out/target/product/hammerhead/obj/PACKAGING/systemimage_intermediates/system.img ext4 system 1073741824 -L system out/target/product/hammerhead/root/file_contexts make_ext4fs -s -T -1 -S out/target/product/hammerhead/root/file_contexts -L system -l 1073741824 -a system out/target/product/hammerhead/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/hammerhead/system Creating filesystem with parameters: Size: 1073741824 Block size: 4096 Blocks per group: 32768 Inodes per group: 8192 Inode size: 256 Journal blocks: 4096 Label: system Blocks: 262144 Block groups: 8 Reserved block group size: 63 Created filesystem with 1445/65536 inodes and 85879/262144 blocks Install system fs image: out/target/product/hammerhead/system.img out/target/product/hammerhead/system.img+out/target/product/hammerhead/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p maxsize=1096212480 blocksize=135168 total=336629666 reserve=11083776 |
6. 刷機命令
Nexus5關機狀態下,長按音量下+電源,即可進入recovery模式, 然後在源碼根目錄下執行下面命令:
1
|
fastboot -w flashall
|
刷機成功後會自動重啓
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
~/Android-SourceCode fastboot -w flashall target reported max download size of 1073741824 bytes Creating filesystem with parameters: Size: 13725835264 Block size: 4096 Blocks per group: 32768 Inodes per group: 8144 Inode size: 256 Journal blocks: 32768 Label: Blocks: 3351034 Block groups: 103 Reserved block group size: 823 Created filesystem with 11/838832 inodes and 93654/3351034 blocks Creating filesystem with parameters: Size: 734003200 Block size: 4096 Blocks per group: 32768 Inodes per group: 7472 Inode size: 256 Journal blocks: 2800 Label: Blocks: 179200 Block groups: 6 Reserved block group size: 47 Created filesystem with 11/44832 inodes and 5813/179200 blocks -------------------------------------------- Bootloader Version...: HHZ12d Baseband Version.....: M8974A-2.0.50.2.22 Serial Number........: 08ade1a513dc087b -------------------------------------------- checking product... OKAY [ 0.100s] sending 'boot' (8950 KB)... OKAY [ 0.500s] writing 'boot'... OKAY [ 0.784s] sending 'recovery' (9672 KB)... OKAY [ 0.556s] writing 'recovery'... OKAY [ 0.814s] erasing 'system'... OKAY [ 1.166s] sending 'system' (328187 KB)... OKAY [ 10.501s] writing 'system'... OKAY [ 23.623s] erasing 'userdata'... OKAY [ 14.657s] sending 'userdata' (137318 KB)... OKAY [ 4.520s] writing 'userdata'... OKAY [ 9.776s] erasing 'cache'... OKAY [ 0.618s] sending 'cache' (13348 KB)... OKAY [ 0.630s] writing 'cache'... OKAY [ 1.070s] rebooting... finished. total time: 70.095s |
7.秀桌面
本文標題:爲Nexus5編譯AndroidL固件
文章作者:Gracker
發佈時間:2015年02月04日 - 20時51分
最後更新:2015年04月01日 - 21時11分
原始鏈接:http://androidperformance.com/2015/02/04/build-rom-for-nexus5.html
許可協議: "署名-非商用-相同方式共享 3.0" 轉載請保留原文鏈接及作者。