上篇說到《framework開發(fā)環(huán)境搭建》,本篇繼續(xù)介紹Android源碼的下載、編譯、刷機(jī)
先貼上Android源碼官網(wǎng)地址:https://source.android.com/docs/setup/start/,俗稱AOSP,Android開源項目,這里我總結(jié)一下具體該怎么操作。
1、安裝repo
Android源碼同時使用git和repo進(jìn)行管理,repo是基于git的代碼管理工具,類似github、gitee,所以需要同時安裝git和repo
sudo apt-get update
sudo apt-get install repo
如果是ubuntu20.04,執(zhí)行上述命令會提示無法定位repo包,那么這個時候需要手動安裝repo
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
export PATH=~/bin:$PATH
如果沒有~/bin/repo目錄,需要先創(chuàng)建一下,安裝好后驗證是否安裝成功
repo verison
如果出現(xiàn)
<repo not installed>
repo launcher version 2.15
(from /usr/bin/repo)
說明安裝成功了,repo安裝好后可以開始下載源碼了
2、下載源碼
首先需要創(chuàng)建一個文件夾來存放源碼
sudo mkdir /projects/Google-Android-Source/
sudo chmod 777 /projects/Google-Android-Source/
當(dāng)然使用git還需要設(shè)置一下git全局配置
git config --global user.name "jason"
git config --global user.email "jason@163.com"
準(zhǔn)備工作完畢,可以直接從Google倉庫拉代碼了,首先初始化倉庫地址
repo init -u https://android.googlesource.com/platform/manifest
這里需要注意下,由于Android源碼在Google服務(wù)器上,國內(nèi)訪問Google服務(wù)器需要VPN,所以,我們可以使用國內(nèi)鏡像,其中穩(wěn)定的鏡像地址是中國科學(xué)技術(shù)大學(xué)的鏡像地址,具體可參考中科大官網(wǎng)的步驟,據(jù)說清華大學(xué)的鏡像源也很穩(wěn)定。本人使用的是公司網(wǎng)絡(luò),有訪問Google的權(quán)限,所以就直接從Google服務(wù)器下載的。因為Android源碼非常大,我下載的Android 13的源碼,有88GB
整個下載過程大概需要7個小時,所以建議你睡覺前開啟下載,一覺醒來就下載完了。下載完成后大概是這樣子的
3、下載廠商驅(qū)動
下載好源碼后先別著急編譯,需要先去下載設(shè)備對應(yīng)的驅(qū)動文件,這樣刷完機(jī)之后才能正常使用,可以看官網(wǎng)說明
根據(jù)你的設(shè)備型號下載對應(yīng)的驅(qū)動即可,下載地址:https://developers.google.cn/android/drivers
我下載的是barbet Android 13
下載完畢以后會得到兩個tgz壓縮文件,將其拷貝到源碼根目錄,然后然后解壓,得到兩個sh腳本文件
執(zhí)行兩個sh腳本文件,會顯示license信息,按D鍵向下翻頁,最后輸入I ACCPET同意條款
此時驅(qū)動文件已準(zhǔn)備就緒,下一步就可以開始編譯源碼了。
4、編譯源碼
編譯前看一下Android源碼目錄結(jié)構(gòu)
關(guān)于目錄結(jié)構(gòu)介紹,可查看我這篇文章《Android源碼目錄結(jié)構(gòu)介紹》,直接開始編譯
第一步,準(zhǔn)備構(gòu)建腳本所需要的環(huán)境
source build/envsetup.sh
第二步,選擇構(gòu)建的目標(biāo)版本
lunch
執(zhí)行完lunch會列出所有的目標(biāo)版本,總共有75個
You're building on Linux
Lunch menu .. Here are the common combinations:
1. aosp_arm-eng
2. aosp_arm64-eng
3. aosp_barbet-userdebug
4. aosp_bluejay-userdebug
5. aosp_bramble-userdebug
6. aosp_bramble_car-userdebug
7. aosp_car_arm-userdebug
8. aosp_car_arm64-userdebug
9. aosp_car_x86-userdebug
10. aosp_car_x86_64-userdebug
11. aosp_cf_arm64_auto-userdebug
12. aosp_cf_arm64_phone-userdebug
13. aosp_cf_x86_64_auto-userdebug
14. aosp_cf_x86_64_foldable-userdebug
15. aosp_cf_x86_64_pc-userdebug
16. aosp_cf_x86_64_phone-userdebug
17. aosp_cf_x86_64_tv-userdebug
18. aosp_cf_x86_phone-userdebug
19. aosp_cf_x86_tv-userdebug
20. aosp_cheetah-userdebug
21. aosp_cloudripper-userdebug
22. aosp_coral-userdebug
23. aosp_coral_car-userdebug
24. aosp_flame-userdebug
25. aosp_flame_car-userdebug
26. aosp_oriole-userdebug
27. aosp_oriole_car-userdebug
28. aosp_panther-userdebug
29. aosp_raven-userdebug
30. aosp_raven_car-userdebug
31. aosp_ravenclaw-userdebug
32. aosp_redfin-userdebug
33. aosp_redfin_car-userdebug
34. aosp_redfin_vf-userdebug
35. aosp_slider-userdebug
36. aosp_sunfish-userdebug
37. aosp_sunfish_car-userdebug
38. aosp_trout_arm64-userdebug
39. aosp_trout_x86-userdebug
40. aosp_whitefin-userdebug
41. aosp_x86-eng
42. aosp_x86_64-eng
43. arm_krait-eng
44. arm_v7_v8-eng
45. armv8-eng
46. armv8_cortex_a55-eng
47. armv8_kryo385-eng
48. beagle_x15-userdebug
49. beagle_x15_auto-userdebug
50. car_ui_portrait-userdebug
51. car_x86_64-userdebug
52. db845c-userdebug
53. gsi_car_arm64-userdebug
54. gsi_car_x86_64-userdebug
55. hikey-userdebug
56. hikey64_only-userdebug
57. hikey960-userdebug
58. hikey960_tv-userdebug
59. hikey_tv-userdebug
60. poplar-eng
61. poplar-user
62. poplar-userdebug
63. qemu_trusty_arm64-userdebug
64. rb5-userdebug
65. sdk_car_arm-userdebug
66. sdk_car_arm64-userdebug
67. sdk_car_md_x86_64-userdebug
68. sdk_car_portrait_x86_64-userdebug
69. sdk_car_x86-userdebug
70. sdk_car_x86_64-userdebug
71. sdk_pc_x86_64-userdebug
72. silvermont-eng
73. uml-userdebug
74. yukawa-userdebug
75. yukawa_sei510-userdebug
不同的目標(biāo)版本對應(yīng)的設(shè)備也不同,因為不同的設(shè)備硬件配置也不一樣,比如有的設(shè)備處理器架構(gòu)是x86的,有的是arm64的,并且你也可以選擇編譯user/userdebug/engineer版本,具體參考官網(wǎng)說明:https://source.android.com/docs/setup/build/running#selecting-device-build
根據(jù)刷機(jī)設(shè)備的型號,選擇對應(yīng)的目標(biāo)版本,這里我選擇的是aosp_barbet-userdebug
最后開始編譯
m -j16
-j16表示開啟多少個線程來編譯,這個取決于你的電腦配置,我的是八核十六線程,所以配置了最大線程數(shù)來編譯,最大程度減少編譯時間,當(dāng)然,也可以不配置,系統(tǒng)將自動選擇最合適的線程數(shù)。
接下來就是漫長的編譯等待了
Android 13的整體編譯大概需要4個小時,具體時間卻決于你的電腦配置,所以,現(xiàn)在你可以起身活動一下,或者去喝杯咖啡,陪女朋友聊聊天等等。
如果不幸編譯失敗,很大可能是因為編譯環(huán)境沒有配置齊全,具體可以參考我之前的文章《framework開發(fā)環(huán)境搭建》。
編譯完成后大概是這個樣子的
5、燒寫鏡像
燒寫鏡像俗稱刷機(jī),就是將編譯生成的鏡像文件拷貝到設(shè)備中。編譯生成的鏡像位于out/target/product/barbet/,barbet是我選擇的目標(biāo)版本,查看一下該目錄下都有哪些鏡像
可以看到里面生成的.img文件都是各個模塊的鏡像文件,如dtbo.img、system.img等。通過fastboot將這個鏡像全部push到模塊的ROM中。
使用usb線連接好設(shè)備跟主機(jī),執(zhí)行
adb devices
查看設(shè)備是否在線
此時可以開始fastboot刷機(jī)了,依次執(zhí)行
#進(jìn)入fastboot模式
adb reboot bootloader
#將所有鏡像刷入設(shè)備
fastboot flashall -w
#重啟設(shè)備
fastboot reboot
刷機(jī)具體說明見官網(wǎng),貼一張進(jìn)入fastboot模式后的截圖
此時等待設(shè)備重啟后就OK啦。文章來源:http://www.zghlxwxcb.cn/news/detail-431027.html
至此,Android 13源碼下載、編譯、刷機(jī)的流程就介紹完了,趕緊去試試吧。文章來源地址http://www.zghlxwxcb.cn/news/detail-431027.html
到了這里,關(guān)于Android源碼的下載,編譯,刷機(jī)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!