編輯:關於 Android 程式設計
在我們的 msm8909 + Android 5.1 環境中,編譯之前需要先執行以下兩個命令:
source build/envsetup.sh
source build/envsetup.sh 這個腳本主要用來定義一些基本函數、環境變量,以及配置編譯工具與路徑。其中 source 命令的作用是運行 shell 腳本,功能等同於「.」,所以這條命令也等價於 . build/envsetup.sh。envsetup.sh 裡聲明了當前會話終端可用的命令——請特別注意「當前會話終端」這個前提,也就是說每次新打開一個終端,都得重新執行一次這些指令。
輸入 source build/envsetup.sh 並回車後,會輸出如下信息:
including device/lge/mako/vendorsetup.sh includingdevice/htc/flounder/vendorsetup.sh includingdevice/asus/grouper/vendorsetup.sh including device/asus/fugu/vendorsetup.sh includingdevice/asus/tilapia/vendorsetup.sh including device/asus/deb/vendorsetup.sh includingdevice/qcom/common/vendorsetup.sh including device/generic/mini-emulator-x86/vendorsetup.sh includingdevice/generic/mini-emulator-arm64/vendorsetup.sh includingdevice/generic/mini-emulator-mips/vendorsetup.sh includingdevice/generic/mini-emulator-armv7-a-neon/vendorsetup.sh including device/generic/mini-emulator-x86_64/vendorsetup.sh includingdevice/samsung/manta/vendorsetup.sh includingvendor/qcom/proprietary/common/vendorsetup.sh including sdk/bash_completion/adb.bash
這段輸出對應 envsetup.sh 中如下的內容:它會在 device 和 vendor 目錄下查找 vendorsetup.sh 文件,並加載、執行它們。
# Execute the contents of anyvendorsetup.sh files we can find. for f in `test -d device && find -Ldevice -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \ `test -d vendor && find -L vendor -maxdepth 4 -name'vendorsetup.sh' 2> /dev/null` do echo "including $f" .$f//執行這些文件 done unset f
由於我們用的是 qcom 平台,只加載 qcom 相關的 vendorsetup.sh 也能正常編譯和運行:
including device/qcom/common/vendorsetup.sh
including vendor/qcom/proprietary/common/vendorsetup.sh
此外,sdk/bash_completion 目錄下的 adb.bash 文件也會被加載到當前終端。它用來實現 adb 命令的 bash completion 功能——加載之後,運行 adb 相關命令時,按 Tab 鍵就能自動補全命令輸入。關於 bash completion 的知識,可參考官方文檔:https://www.gnu.org/s/bash/manual/bash.html。
including sdk/bash_completion/adb.bash
add_lunch_combo msm8909-userdebug
add_lunch_combo msm8909-user
add_lunch_combo msm8909-eng
通過調用 add_lunch_combo 函數來增加編譯選項。輸入命令行 lunch 後,輸出如下:
Lunch menu... pick a combo:
1. msm8909-userdebug
2. msm8909-user
3. msm8909-eng
add_lunch_combo 函數的定義如下:
# Clear this variable. It will be built up again when thevendorsetup.sh # files are included at the end of thisfile. unset LUNCH_MENU_CHOICES function add_lunch_combo() { local new_combo=$1 #獲得add_lunch_combo被調用時的參數 local c # 遍歷LUNCH_MENU_CHOICES裡的值,該函數第一次調用時為空 for c in ${LUNCH_MENU_CHOICES[@]} ; do if [ "$new_combo" = "$c" ] ; then # 如果參數裡的值已經存在於LUNCH_MENU_CHOICES變量裡,則返回 return fi done # 如果參數的值不存在,則添加到LUNCH_MENU_CHOICES變量裡 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo) } export QCPATH="vendor/qcom/proprietary"
這個路徑會被下面的文件引用:
device/qcom/common/base.mk:1058:#skip bootjars check if QCPATH not available device/qcom/common/base.mk:1059:ifeq($(strip $(QCPATH)),) device/qcom/common/common64.mk:6:$(callinherit-product-if-exists, $(QCPATH)/common/config/device-vendor.mk) device/qcom/common/common.mk:8:$(callinherit-product-if-exists, $(QCPATH)/common/config/device-vendor.mk) device/qcom/msm8909/BoardConfig.mk:30:-include$(QCPATH)/common/msm8909/BoardConfigVendor.mk device/qcom/msm8909/msm8909.mk:24:-include$(QCPATH)/common/config/qtic-config.mk device/qcom/msm8909/msm8909.mk:39:-include$(QCPATH)/common/config/rendering-engine.mk device/qcom/msm8909/msm8909.mk:185:PRODUCT_PACKAGE_OVERLAYS:= $(QCPATH)/qrdplus/Extension/res-overlay \ device/qcom/msm8909/msm8909.mk:186: $(QCPATH)/qrdplus/globalization/multi-language/res-overlay\
例如:
#set openjdk7 exportJAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 exportJRE_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre exportCLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
envsetup.sh 文件開頭定義了 hmm 函數,執行 hmm 命令後會輸出:
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- lunch: lunch <product_name>-<build_variant>
- tapas: tapas [...] [arm|x86|mips|armv5|arm64|x86_64|mips64][eng|userdebug|user]
- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory, but not their dependencies.
- mmm: Builds all of the modules in the supplied directories, but not their dependencies. To limit the modules being built use the syntax: mmm dir/:target1,target2.
- mma: Builds all of the modules in the current directory, and their dependencies.
- mmma: Builds all of the modules in the supplied directories, and their dependencies.
- cgrep: Greps on all local C/C++ files.
- ggrep: Greps on all local Gradle files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- sgrep: Greps on all local source files.
- godir: Go to the directory containing a file.
完整的函數列表為:adb_get_product_device、adb_get_traced_by、addcompletions、add_lunch_combo、cgrep、check_multisim、check_product、check_project、check_variant、choose、choosecombo、chooseproduct、chooseproject、choosetype、choosevariant、core、coredump_enable、coredump_setup、cproj、croot、findmakefile、gdbclient、gdbclient_old、gdbwrapper、get_abs_build_var、getbugreports、get_build_var、getdriver、getlastscreenshot、get_make_command、getprebuilt、getscreenshotpath、getsdcardpath、get_symbols_directory、gettargetarch、gettop、ggrep、godir、hmm、init、isviewserverstarted、jgrep、key_back、key_home、key_menu、lunch、_lunch、m、make、mangrep、mgrep、mm、mma、mmm、mmma、pez、pid、printconfig、print_lunch_menu、qpid、resgrep、runhat、runtest、sepgrep、set_java_home、setpaths、set_sequence_number、set_stuff_for_environment、settitle、sgrep、smoketest、stacks、startviewserver、stopviewserver、systemstack、tapas、tracedmdump、treegrep。
以上便是 envsetup.sh 所支持的全部函數集。
徹底搞懂 Android 的 layout_weight:剩餘空間到底是怎麼分的
寫 Demo 時碰到 layout_weight,網上關於它的討論很多,但多數說法流於口訣——「值越小權重越大」這類結論背誦起來容易,遇到實際問題就完全用不上。我自己把資
Android 仿微信照片選擇器實現預覽查看圖片
下面進入正題,先來看看實現效果: 整體實現思路如下: 先到手機中掃描 jpeg 與 png 圖片。 獲取圖片的路徑,以及圖片所在的父路徑名(也就是文件夾名)。
Android 開發中單例模式的六種寫法與常見陷阱
不論是 Android 開發還是 Java 開發,單例(Singleton)模式都是使用頻率相當高的設計模式。本文將系統性地梳理單例模式的六種常見寫法,並深入剖析各自可能
Android Studio + UI Automator:動手做一個界面自動化測試
Android 測試支持庫裡有一個 UI 自動化模組,能做黑盒級別的界面測試。它在 API Level 18 引入,允許測試代碼在用戶可見的控件上模擬真實操作——不需要知