2021-05-12 14:32:11
Android 6.0原始碼編譯及燒錄到真機過程記錄
Android 6.0原始碼編譯及燒錄到真機過程記錄,asop使用清華映象源https://mirror.tuna.tsinghua.edu.cn/help/AOSP/
一開始使用每月初始化包的方式因為無法搞定版本的問題,沒能通過編譯,無奈,老老實實一點點下載吧
1、原始碼下載
mkdir aosp
cd aosp
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-6.0.1_r1
sh myrepo.sh
版本號,一定要選對,不然就要來回折騰,因為雖然都是android6.0,但有的版本並不支援nexus5
MMB29Q android-6.0.1_r11 Marshmallow Nexus 5, Nexus 5X, Nexus 6, Nexus 6P, Nexus 7 (flo/deb) MMB29T android-6.0.1_r10 Marshmallow Nexus Player MMB29S android-6.0.1_r9 Marshmallow Nexus 5, Nexus 6, Nexus 9 (volantis/volantisg) MMB29P android-6.0.1_r8 Marshmallow Nexus 5X, Nexus 6P MMB29O android-6.0.1_r7 Marshmallow Nexus 7 (flo/deb) MXB48K android-6.0.1_r5 Marshmallow Pixel C MXB48J android-6.0.1_r4 Marshmallow Pixel C MMB29M android-6.0.1_r3 Marshmallow Nexus 6P, Nexus Player MMB29K android-6.0.1_r1 Marshmallow Nexus 5, Nexus 5X, Nexus 6, Nexus 7 (flo/deb), Nexus 9 (volantis/volantisg)
順便提醒下,一般版本支援的型號越多,相應的體積越大。曾經就下錯過版本,導致燒錄後進入normal模式一直卡在開機動畫上。關於原始碼體積這裡給個簡單的參考:
android-6.0.1_r1 67G android-6.0.1_r3 54G
原始碼體積比較大,建議下載前一定要保證硬碟分割區足夠大,如果既要下載又要編譯,建議存放原始碼分割區不小於120G
myrepo.sh是為避免repo失敗過程,對repo sync 重試過程進行的封裝,見下方
#!/bin/sh
repo sync -j4
while [ $? -ne 0 ]
do
repo sync -j4
done
同步過程出現 curl: (22) The requested URL returned error: 404 Not Found Server does not provide clone.bundle; ignoring. 直接無視即可
2、新增驅動
在程式碼完全同步之後,實際時缺少vendor目錄的,是沒有相應的驅動,編譯出的映象只能執行在模擬器上,下載相關的驅動
https://developers.google.com/android/drivers#hammerheadmmb29k,實際是三個shell 指令碼
依次執行這三個指令碼檔案,這裡要注意,三個指令碼檔案的作用是生成驅動檔案,但是在執行操作前,它會讓你閱讀相關協定,你必須一直按enter鍵一行一行往下讀,更不能一鍵摁到底,因為程式在最後會讓你輸入“I ACCEPT”,如果你一鍵摁到底,也就是說最後一步也摁enter鍵的話它就會執行預設操作,即不接受此協定,那生成驅動檔案的操作就不會執行。這裡有個小竅門,一直摁住enter,注意命令列中閃過的協定項,當讀到第八項時可以放慢速度,一下一下的摁enter鍵了,最後慢慢的到最後一步,輸入I ACCEPT即可。這三個檔案都是這樣的操作流程。上圖展示了在執行完指令碼檔案後生成的驅動檔案目錄。
3、編譯
export USE_CCACHE=1
prebuilts/misc/linux-x86/ccache/ccache -M 50G
source build/envsetup.sh
ninjame@Ubuntu1604:~/aosp$ lunch
------------------------------
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_deb-userdebug
8. aosp_flo-userdebug
9. full_fugu-userdebug
10. aosp_fugu-userdebug
11. mini_emulator_arm64-userdebug
12. m_e_arm-userdebug
13. mini_emulator_mips-userdebug
14. mini_emulator_x86_64-userdebug
15. mini_emulator_x86-userdebug
16. aosp_flounder-userdebug
17. aosp_angler-userdebug
18. aosp_bullhead-userdebug
19. aosp_hammerhead-userdebug
20. aosp_hammerhead_fp-userdebug
21. aosp_shamu-userdebug
Which would you like? [aosp_arm-eng] 19
------------------------
make -j8
最終編譯耗時 1h 22min
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 1511/65536 inodes and 93478/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=367728881 reserve=11083776
#### make completed successfully (01:12:44 (hh:mm:ss)) ####
ninjame@ubuntu1604:~/aosp$ du -sh out/
22G out/
編譯問題記錄:
問題1:
pp frameworks/base/tools/aidl/aidl_language_y.y build/core/binary.mk:609: recipe for target 'out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp' failed make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp] 斷開的管道 make: *** 正在等待未完成的任務.... Lex: aidl <= frameworks/base/tools/aidl/aidl_language_l.l frameworks/base/tools/aidl/aidl_language_l.l:55: warning, 無法匹配規則 flex-2.5.39:嚴重內部錯誤,exec of /usr/bin/m4 failed build/core/binary.mk:646: recipe for target 'out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp' failed make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp] Error 1 make: *** Deleting file 'out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp' 注: 某些輸入檔案使用或覆蓋了已過時的 API。 注: 有關詳細資訊, 請使用 -Xlint:deprecation 重新編譯。 注: 某些輸入檔案使用了未經檢查或不安全的操作。 注: 有關詳細資訊, 請使用 -Xlint:unchecked 重新編譯。 解決辦法:
1 更換軟體源為阿里雲
為了更快的安裝軟體,我們需要更換軟體源為國內的軟體源,這裡推薦使用Ubuntu官方指定的國內軟體源阿里雲,具體方法是:
sudo gedit /etc/apt/sources.list
在檔案最前面加入下面程式碼:
deb http://mirrors.aliyun.com/ubuntu/ quantal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ quantal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ quantal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ quantal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ quantal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal-backports main restricted universe multiverse
2 安裝依賴
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386
sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib
sudo apt-get install tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo apt-get install dpkg-dev libsdl1.2-dev libesd0-dev
sudo apt-get install git-core gnupg flex bison gperf build-essential
sudo apt-get install zip curl zlib1g-dev gcc-multilib g++-multilib
sudo apt-get install libc6-dev-i386
sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev
sudo apt-get install lib32z-dev ccache
sudo apt-get install libgl1-mesa-dev libxml2-utils xsltproc unzip m4
Ubuntu 16.04請務必使用上面的依賴,Ubuntu 16.04需要的依賴和Ubuntu 14.04所需要的依賴是不同的
問題2:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
build/core/host_shared_library_internal.mk:51: recipe for target 'out/host/linux-x86/obj/lib/libart.so' failed
make: *** [out/host/linux-x86/obj/lib/libart.so] Error 1
make: *** 正在等待未完成的任務....
據說這個錯誤只在ubuntu16.04 上出現
修改原始碼
修改 mydroid/art/build/Android.common_build.mk
檔案,定位到75行,注釋掉75-78:
76 # By default, host builds use clang for better warnings.
77 # ART_HOST_CLANG := true
78 #endif
如果不修改這裡,會遇到一個比較棘手的編譯錯誤,修改的目的是把CLANG這個編譯選項關掉,詳見後面的編譯記錄,百度搜狗都無解,這個錯誤只會在Ubuntu16.04上遇到,Ubuntu14.04則不存在這個問題
4、刷機
刷機過程碰到
fastboot reboot
< waiting for any device >
fastboot devices
no permissions (verify udev rules); see [http://developer.android.com/tools/device.html] fastboot
fastboot命令一直識別不了手機,一開始以為時fastboot版本的問題,後來發現不是這麼回事
需要設定usb許可權
因為ubuntu這樣的系統都是預設以非root身份在執行的,要使用usb偵錯,需要sudo支援。
fastboot模式下插入手機
$ lsusb
ninjame@ubuntu1604:~$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 04d9:a0cd Holtek Semiconductor, Inc.
Bus 001 Device 030: ID 18d1:4ee0 Google Inc.
Bus 001 Device 003: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
$sudo vim /etc/udev/rules.d/60-android.rules //60-android.rules為新建的。
加入以下內容:
SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4ee0",MODE="0666"
其中的idvendor idProduct指的是USB的ID可以使用lsusb查詢得到。
比如我的是:
lsusb
Bus 001 Device 030: ID 18d1:4ee0 Google Inc.
ID 18d1 就是idVendor ,4ee0就是 idProduct
執行命令,重新啟動udev:
$sudo chmod a+rx /etc/udev/rules.d/60-android.rules
$sudo service udev restart
(很重要)拔掉usb重新連上再執行:
fastboot devices
ninjame@ubuntu1604:~$ fastboot devices
0779af0143a66640 fastboot
設定環境變數 sudo vim /etc/profile
export ANDROID_PRODUCT_OUT="/home/ninjame/aosp/out/target/product/hammerhead"
source /etc/profile
ninjame@ubuntu1604:~/aosp/out/target/product/hammerhead$ fastboot -w flashall
target reported max download size of 1073741824 bytes
wiping userdata...
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
wiping cache...
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...: HHZ12k
Baseband Version.....: M8974A-2.0.50.2.28
Serial Number........: 0779af0143a66640
--------------------------------------------
checking product...
OKAY [ 0.100s]
sending 'boot' (9160 KB)...
OKAY [ 0.500s]
writing 'boot'...
OKAY [ 0.785s]
sending 'recovery' (10018 KB)...
OKAY [ 0.566s]
writing 'recovery'...
OKAY [ 0.825s]
erasing 'system'...
OKAY [ 1.066s]
sending 'system' (358584 KB)...
OKAY [ 11.452s]
writing 'system'...
OKAY [ 25.345s]
erasing 'userdata'...
OKAY [ 7.935s]
sending 'userdata' (137318 KB)...
OKAY [ 4.511s]
writing 'userdata'...
OKAY [ 9.139s]
erasing 'cache'...
OKAY [ 0.584s]
sending 'cache' (13348 KB)...
OKAY [ 0.630s]
writing 'cache'...
OKAY [ 1.067s]
rebooting...
finished. total time: 65.037s
第一次開機如果卡住,只需要進到recovery模式下,執行wipe cache partition,清除系統快取。
整個過程比較曲折,但看到開機畫面彈出時,還是挺開心的。
編譯的映象燒入手機,比較精簡,上幾張圖
截圖直接儲存到電腦:adb shell screencap -p | sed 's/r$//' > screen.png
Android 6.0原始碼下載地址: http://www.linuxidc.com/Linux/2016-01/127285.htm
相關文章