本文简要分析一下build.prop是如何生成的。Android的build.prop文件是在Android编译时刻收集的各种property(LCD density/语言/编译时间, etc.),编译完成之后,文件生成在out/target/product/<board>/system/目录下。在Android运行时刻可以通过property_get()[c/c++域] / SystemProperties_get*()[Java域]读取这些属性值。
build.prop的生成是由make系统解析build/core/Makefile完成。相关脚本如下:
BUILDINFO_SH := build/tools/buildinfo.sh $(INSTALLED_BUILD_PROP_TARGET): $(BUILDINFO_SH) $(INTERNAL_BUILD_ID_MAKEFILE) $(BUILD_SYSTEM)/version_defaults.mk $(wildcard $(TARGET_DEVICE_DIR)/system.prop) @echo Target buildinfo: $@ @mkdir -p $(dir $@) $(hide) TARGET_BUILD_TYPE="$(TARGET_BUILD_VARIANT)" \ TARGET_DEVICE="$(TARGET_DEVICE)" \ PRODUCT_NAME="$(TARGET_PRODUCT)" \ PRODUCT_BRAND="$(PRODUCT_BRAND)" \ PRODUCT_DEFAULT_LANGUAGE="$(call default-locale-language,$(PRODUCT_LOCALES))" \ PRODUCT_DEFAULT_REGION="$(call default-locale-region,$(PRODUCT_LOCALES))" \ PRODUCT_DEFAULT_WIFI_CHANNELS="$(PRODUCT_DEFAULT_WIFI_CHANNELS)" \ PRODUCT_MODEL="$(PRODUCT_MODEL)" \ PRODUCT_MANUFACTURER="$(PRODUCT_MANUFACTURER)" \ PRIVATE_BUILD_DESC="$(PRIVATE_BUILD_DESC)" \ BUILD_ID="$(BUILD_ID)" \ BUILD_DISPLAY_ID="$(BUILD_DISPLAY_ID)" \ BUILD_NUMBER="$(BUILD_NUMBER)" \ PLATFORM_VERSION="$(PLATFORM_VERSION)" \ PLATFORM_SDK_VERSION="$(PLATFORM_SDK_VERSION)" \ PLATFORM_VERSION_CODENAME="$(PLATFORM_VERSION_CODENAME)" \ BUILD_VERSION_TAGS="$(BUILD_VERSION_TAGS)" \ TARGET_BOOTLOADER_BOARD_NAME="$(TARGET_BOOTLOADER_BOARD_NAME)" \ BUILD_FINGERPRINT="$(BUILD_FINGERPRINT)" \ TARGET_BOARD_PLATFORM="$(TARGET_BOARD_PLATFORM)" \ TARGET_CPU_ABI="$(TARGET_CPU_ABI)" \ TARGET_CPU_ABI2="$(TARGET_CPU_ABI2)" \ TARGET_AAPT_CHARACTERISTICS="$(TARGET_AAPT_CHARACTERISTICS)" \ bash $(BUILDINFO_SH) > $@ $(hide) if [ -f $(TARGET_DEVICE_DIR)/system.prop ]; then \ cat $(TARGET_DEVICE_DIR)/system.prop >> $@; \ fi $(if $(ADDITIONAL_BUILD_PROPERTIES), \ $(hide) echo >> $@; \ echo "#" >> $@; \ echo "# ADDITIONAL_BUILD_PROPERTIES" >> $@; \ echo "#" >> $@; ) $(hide) $(foreach line,$(ADDITIONAL_BUILD_PROPERTIES), \ echo "$(line)" >> $@;) $(hide) build/tools/post_process_props.py $@
从上面的命令中可以看到,build.prop由三部分组成:BUILDINFO_SH、system.prop、ADDITIONAL_BUILD_PROPERTIES等,对应的写入命令:
bash $(BUILDINFO_SH) > $@ $(hide) if [ -f $(TARGET_DEVICE_DIR)/system.prop ]; then \ cat $(TARGET_DEVICE_DIR)/system.prop >> $@; \ fi $(hide) $(foreach line,$(ADDITIONAL_BUILD_PROPERTIES), \ echo "$(line)" >> $@;)1) Makefile中首先定义各种变量,这在下一步执行时会用到。比如:
1. ... 2. PRODUCT_DEFAULT_LANGUAGE="$(calldefault-locale-language,$(PRODUCT_LOCALES))" \ 3. PRODUCT_DEFAULT_REGION="$(calldefault-locale-region,$(PRODUCT_LOCALES))" \ 4. ...
2) Makefile中调用build/tools/buildinfo.sh执行脚本,并输出到build.prop
Buildinfo.sh很简单,只是echo一些属性,比如:
1. ... 2. echo"ro.product.locale.language=$PRODUCT_DEFAULT_LANGUAGE" 3. echo"ro.product.locale.region=$PRODUCT_DEFAULT_REGION" 4. ...
而,ro.product.locale.language/ ro.product.locale.region就是些属性,等号后面是值。
3) Makefile中直接把$(TARGET_DEVICE_DIR)/system.prop的内容追加到build.prop中。
4) 收集ADDITIONAL_BUILD_PROPERTIES中的属性,追加到build.prop中。
ADDITIONAL_BUILD_PROPERTIES又会收集PRODUCT_PROPERTY_OVERRIDES中定义的属性
1. ADDITIONAL_BUILD_PROPERTIES:= \ 2. $(ADDITIONAL_BUILD_PROPERTIES)\ 3. $(PRODUCT_PROPERTY_OVERRIDES)
通过build.prop生成过程的分析,可知哪里可以修改原有的属性或加入自己定义属性,那就是2) buildinfo.sh; 3) system.prop; 4) ADDITIONAL_BUILD_PROPERTIES或PRODUCT_PROPERTY_OVERRIDES。不过个人建议改在system.prop或PRODUCT_PROPERTY_OVERRIDES,这对应于具体特定平台或产品的修改。原文:http://blog.csdn.net/thl789/article/details/7014300