本文介紹Android的通用編譯技巧,
手機廠商或者芯片平臺可能都封裝了編譯腳本命令,但是基本都沒有脫離Google的原始編譯邏輯,Google在開發者網站對相關命令有介紹,
可以參考Google的官方檔案 https://source.android.google.cn/setup/build/building
基礎編譯流程
對于AOSP原始碼來講,通用的編譯流程如下:
cd /home/tanfuhai/data/code/android
source build/envsetup.sh # Add "lunch" (and other utilities and variables)
# to the shell environment.
lunch [-] # Choose the device to target.
m -j [] # Execute the configured build.
通用目標
在整個AOSP原始碼內部,編譯通用格式:
make 目標
定義好了多個目標,通用的目標如下:
- dist: 將編譯目標構建之后,進行打包處理,服務器一般建議用此命令,
- superimage: 構建超級韌體,
- systemimage: 構建系統韌體,
- vendorimage: 構建vender韌體,
- odmimage: 構建odm韌體,
- productimage: 構建產品韌體,
- clean: 類似于rm -rf out/
- checkbuild Build every module defined in the source tree
- droid :默認的Android目標
- nothing 不構建任何東西,只需決議并驗證構建結構
- java 編譯所有的java代碼,
- native Build all the native code in the source tree
- host Build all the host code (not to be run on a device) in the source tree
- target Build all the target code (to be run on the device) in the source tree
- (java|native)-(host|target)
- (host|target)-(java|native) Build the intersection of the two given arguments
- snod:快速編譯systemimage,不會進行依賴構建
- vnod:快速編譯vendorimage,不會進行依賴構建,
- pnod: 快速編譯productimage,不會進行依賴構建,
- psnod: 快速編譯productserviceimage,不會進行依賴構建,
- onod: 快速編譯odmimage,不會進行依賴構建,
如果make后面沒有跟目標,默認目標是droid
常用編譯目標
除了通用編譯目標之外,實際作業中,可能針對不同的模塊或者目標需要進行具體的指令變更,簡單介紹常用的一些技巧:
修改framework相關
a. 如果當前的原始碼和手機內部版本一致,可以通過adb sync 磁區來進行同步,
make framework-res framework services -j16 // 根據情況擇優編譯
adb sync system
adb shell am restart // 重啟用戶空間,修改的內容會生效,
b. 如果本地原始碼和手機版本不一致,
make installclean -j16 // 此步驟會洗掉out/target/product/XXX/下生成的相關安裝檔案,比如apk、bin等
make framework services -j16
adb sync system
adb shell am restart // 重啟用戶空間,修改的內容會生效,
如果不想洗掉當前產品生成的相關檔案,可以通過adb push --sync 命令來同步檔案到手機,
make framework services -j16
adb push --sync out/target/product/jide_pro2_lte_r/system/framework/ /system/
執行程序中可以將所有命令寫到一起,通過分號隔開,
注意:如果同步程序中提示空間不足,可以先執行 adb shell am restart ,然后在執行 adb sync + 磁區,
修改了apk
make 模塊名 -j16
make Launcher3QuickStep -j16
adb sync product
adb shell pm clear com.android.launcher3
或者adb shell am force-stop com.android.launcher3
修改kernel
make bootimage -j32
adb reboot bootloader
fastboot flash boot boot_image.img
修改selinux相關
- Android O之前
make bootimage -j32
- Android O之后 (Treble架構)
Treble架構的原因,Selinux被拆分到不同的磁區,編譯方式發生了變化:
make selinux_policy -j32
如果可以直接連接手機,執行:
adb sync
否則,將如下對應目錄的所有檔案push到手機對應的位置即可,
- out/target/product/generic/odm/etc/selinux
- out/target/product/generic/vendor/etc/selinux
- out/target/product/generic/product/etc/selinux
- out/target/product/generic/system/etc/selinux
更改了property屬性
AOSP默認沒有一個通用目標可以方便編譯所有的*.prop檔案,為了方便編譯所有的目標, 需要給Makefile打上補丁,
diff --git a/core/Makefile b/core/Makefile
index 3f98ee400..ef3f406b2 100755
--- a/core/Makefile
+++ b/core/Makefile
@@ -679,6 +679,13 @@ endif
.PHONY: package-stats
package-stats: $(PACKAGE_STATS_FILE)
+
+BUILD_TO_PROP := \
+ $(sort $(filter $(TARGET_OUT)/% $(TARGET_OUT_DATA)/%, \
+ $(filter %.prop, $(ALL_DEFAULT_INSTALLED_MODULES))))
+.PHONY: buildprop
+buildprop: $(BUILD_TO_PROP)
+
然后執行:
make buildprop -j32
adb sync // 同步結果到手機
編譯目標磁區所有的apk和jar檔案
make package-stats -j32
adb sync
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/255923.html
標籤:其他
上一篇:學習日志18
