1 . 確保主目錄下有一個 bin/ 目錄,而且該目錄包含在路徑中:java
mkdir ~/bin PATH=~/bin:$PATH
2 . 下載 Repo 工具,並確保它可執行:android
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo chmod a+x ~/bin/repo
3 .建立一個空目錄來存放您的工做文件:git
mkdir AndroidSource cd AndroidSource
4. 配置GITweb
git config --global user.name "Your Name" git config --global user.email "you@example.com"
5. 下載源碼api
-b 後面接的是分支名稱,當前下的是android 9.0開發分支,在這個網站上能夠查詢android源碼的分支:https://android.googlesource.com/platform/frameworks/base/+refsbash
repo init -u https://android.googlesource.com/platform/manifest -b pie-dev
6. 同步代碼curl
repo sync -j8
7. 下載驅動ionic
我使用的是Pixel2xl,在 https://developers.google.com/android/drivers 頁面下載相應的二進制驅動ide
將下載的壓縮包解壓出的自解壓腳本放在源碼樹的根目錄下,並運行.sh 文件工具
運行後,會提示你查看證書,按Enter鍵一行行的查看,出現下面的輸入提示時,輸入 I ACCEPT
,解壓到了vendor
目錄下。其它驅動同理執行。
1. 清理目錄
爲了確保新安裝的二進制文件在解壓後會被適當考慮在內,請使用如下命令刪除全部之前編譯操做的已有輸出
make clobber
2. 初始化編譯環境
source build/envsetup.sh
3. 選中須要編譯的 版本,須要和本身的手機,下載的驅動相對應
編譯的版本有 user,userdebug,eng,三者具體差別Google也在官方文檔中給出了說明:https://source.android.com/source/building
lunch
4. 編譯
make -j8
1. 編譯IDE iml
在編譯完android源碼後,再編譯 IDE,成功後再源碼根目錄會生成android.ipr文件和android.iml文件
mmm development/tools/idegen/ ./development/tools/idegen/idegen.sh
可能會遇到的錯誤:
Couldn't locate the directory
解決方案:使用MAC原始終端bash,不要使用zsh等~
2. 修改android.iml文件中以下
1 <?xml version="1.0" encoding="UTF-8"?> 2 <module version="4" relativePaths="true" type="JAVA_MODULE"> 3 <component name="ModuleRootManager" /> 4 <component name="NewModuleRootManager" inherit-compiler-output="true"> 5 <exclude-output /> 6 <content url="file://$MODULE_DIR$"> 7 <!--sourceFolder標籤表示須要索引的代碼目錄--> 8 <sourceFolder url="file://$MODULE_DIR$/frameworks/base/core/java" isTestSource="false" /> 9 <sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" /> 10 <!--excludeFolder標籤表示這個目錄下全部內容都不索引--> 11 <excludeFolder url="file://$MODULE_DIR$/.repo" /> 12 <excludeFolder url="file://$MODULE_DIR$/abi" /> 13 <excludeFolder url="file://$MODULE_DIR$/art" /> 14 <excludeFolder url="file://$MODULE_DIR$/bionic" /> 15 <excludeFolder url="file://$MODULE_DIR$/bootable" /> 16 <excludeFolder url="file://$MODULE_DIR$/build" /> 17 <excludeFolder url="file://$MODULE_DIR$/cts" /> 18 <excludeFolder url="file://$MODULE_DIR$/dalvik" /> 19 <excludeFolder url="file://$MODULE_DIR$/developers" /> 20 <excludeFolder url="file://$MODULE_DIR$/development" /> 21 <excludeFolder url="file://$MODULE_DIR$/device" /> 22 <excludeFolder url="file://$MODULE_DIR$/docs" /> 23 <excludeFolder url="file://$MODULE_DIR$/external" /> 24 <excludeFolder url="file://$MODULE_DIR$/external/bluetooth" /> 25 <excludeFolder url="file://$MODULE_DIR$/external/chromium" /> 26 <excludeFolder url="file://$MODULE_DIR$/external/emma" /> 27 <excludeFolder url="file://$MODULE_DIR$/external/icu4c" /> 28 <excludeFolder url="file://$MODULE_DIR$/external/jdiff" /> 29 <excludeFolder url="file://$MODULE_DIR$/external/webkit" /> 30 <excludeFolder url="file://$MODULE_DIR$/frameworks/base/docs" /> 31 <excludeFolder url="file://$MODULE_DIR$/frameworks/base/tests" /> 32 <excludeFolder url="file://$MODULE_DIR$/frameworks/base/tools" /> 33 <excludeFolder url="file://$MODULE_DIR$/hardware" /> 34 <excludeFolder url="file://$MODULE_DIR$/libcore" /> 35 <excludeFolder url="file://$MODULE_DIR$/libnativehelper" /> 36 <excludeFolder url="file://$MODULE_DIR$/ndk" /> 37 <excludeFolder url="file://$MODULE_DIR$/out" /> 38 <excludeFolder url="file://$MODULE_DIR$/pdk" /> 39 <excludeFolder url="file://$MODULE_DIR$/platform_testing" /> 40 <excludeFolder url="file://$MODULE_DIR$/prebuilt" /> 41 <excludeFolder url="file://$MODULE_DIR$/sdk" /> 42 <excludeFolder url="file://$MODULE_DIR$/tools" /> 43 <excludeFolder url="file://$MODULE_DIR$/vendor" /> 44 <excludeFolder url="file://$MODULE_DIR$/toolchain" /> 45 <excludeFolder url="file://$MODULE_DIR$/system" /> 46 <excludeFolder url="file://$MODULE_DIR$/prebuilts" /> 47 <excludeFolder url="file://$MODULE_DIR$/phoenix" /> 48 </content> 49 50 <orderEntry type="sourceFolder" forTests="false" /> 51 <orderEntry type="inheritedJdk" /> 52 <orderEntryProperties /> 53 </component> 54 </module>
3. 打開源碼
使用androidstudio選擇open(源碼目錄下android.ipr文件)
4. 實現跳轉
實如今androidstudio中ctrl點擊源碼跳轉:
點擊下圖箭頭(或直接command+enter):
添加以下:
1. 檢查刷機的鏡像
編譯的可刷機的文件有 boot.img、system.img、recovery.img、cache.img、userdata.img 五個鏡像文件。
咱們在刷機前輸出ANDROID_PRODUCT_OUT變量的值,確保它的值和編譯後鏡像輸出目錄的路徑值一致。若是不一致的話,從新設置ANDROID_PRODUCT_OUT的值與編譯後鏡像輸出目錄路徑值一致。
echo $ANDROID_PRODUCT_OUT
2. 手機進入bootloader 模式
adb reboot bootloader
3. 手機解鎖
fastboot oem unlock
4. 刷入鏡像
fastboot -w flashall
5. 設備上鎖
fastboot oem lock