Android之build.prop属性详解

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android之build.prop属性详解相关的知识,希望对你有一定的参考价值。

 

注:本篇文章是基于MSD648项目(androidTV)的prop进行说明。

Android版本:4.4.4

内核版本:3.10.86

 

1.生成build.prop

  build.prop的生成是由make系统解析build/core/Makefile完成

  1.1.Makefile生成build.prop的主要代码如下

$(INSTALLED_BUILD_PROP_TARGET): $(BUILDINFO_SH) $(INTERNAL_BUILD_ID_MAKEFILE) $(BUILD_SYSTEM)/version_defaults.mk $(system_prop_file)
    @echo Target buildinfo: [email protected]
    @mkdir -p $(dir [email protected])
    $(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) > [email protected]
    $(hide) $(foreach file,$(system_prop_file),         if [ -f "$(file)" ]; then             echo "#" >> [email protected];             echo Target buildinfo from: "$(file)";             echo "# from $(file)" >> [email protected];             echo "#" >> [email protected];             cat $(file) >> [email protected];         fi;)
    $(if $(ADDITIONAL_BUILD_PROPERTIES),         $(hide) echo >> [email protected];                 echo "#" >> [email protected];                 echo "# ADDITIONAL_BUILD_PROPERTIES" >> [email protected];                 echo "#" >> [email protected]; )
    $(hide) $(foreach line,$(ADDITIONAL_BUILD_PROPERTIES),         echo "$(line)" >> [email protected];)
    $(hide) build/tools/post_process_props.py [email protected]

build_desc :=

  1.2.目标文件为$(INSTALLED_BUILD_PROP_TARGET),其定义为:

INSTALLED_BUILD_PROP_TARGET := $(TARGET_OUT)/build.prop

  1.3.首先对属性进行赋值,如BUILD_ID="$(BUILD_ID)",最后执行bash脚本:bash $(BUILDINFO_SH) > [email protected],其定义为

BUILDINFO_SH := build/tools/buildinfo.sh

  1.4.开始执行sh脚本中的内容

#!/bin/bash

echo "# begin build properties"
echo "# autogenerated by buildinfo.sh"

echo "ro.build.id=$BUILD_ID"
echo "ro.build.display.id=$BUILD_DISPLAY_ID"
echo "ro.build.version.incremental=$BUILD_NUMBER"
echo "ro.build.version.sdk=$PLATFORM_SDK_VERSION"
echo "ro.build.version.codename=$PLATFORM_VERSION_CODENAME"
echo "ro.build.version.release=$PLATFORM_VERSION"
echo "ro.build.date=`date`"
echo "ro.build.date.utc=`date +%s`"
echo "ro.build.type=$TARGET_BUILD_TYPE"
echo "ro.build.user=$USER"
echo "ro.build.host=`hostname`"
echo "ro.build.tags=$BUILD_VERSION_TAGS"
echo "ro.product.model=$PRODUCT_MODEL"
echo "ro.product.brand=$PRODUCT_BRAND"
echo "ro.product.name=$PRODUCT_NAME"
echo "ro.product.device=$TARGET_DEVICE"
echo "ro.product.board=$TARGET_BOOTLOADER_BOARD_NAME"
echo "ro.product.cpu.abi=$TARGET_CPU_ABI"
if [ -n "$TARGET_CPU_ABI2" ] ; then
  echo "ro.product.cpu.abi2=$TARGET_CPU_ABI2"
fi
echo "ro.product.manufacturer=$PRODUCT_MANUFACTURER"
if [ -n "$PRODUCT_DEFAULT_LANGUAGE" ] ; then
  echo "ro.product.locale.language=$PRODUCT_DEFAULT_LANGUAGE"
fi
if [ -n "$PRODUCT_DEFAULT_REGION" ] ; then
  echo "ro.product.locale.region=$PRODUCT_DEFAULT_REGION"
fi
echo "ro.wifi.channels=$PRODUCT_DEFAULT_WIFI_CHANNELS"
echo "ro.board.platform=$TARGET_BOARD_PLATFORM"

echo "# ro.build.product is obsolete; use ro.product.device"
echo "ro.build.product=$TARGET_DEVICE"

echo "# Do not try to parse ro.build.description or .fingerprint"
echo "ro.build.description=$PRIVATE_BUILD_DESC"
echo "ro.build.fingerprint=$BUILD_FINGERPRINT"
echo "ro.build.characteristics=$TARGET_AAPT_CHARACTERISTICS"

echo "# end build properties"

  1.5.最后追加余下的属性

    $(hide) $(foreach file,$(system_prop_file),         if [ -f "$(file)" ]; then             echo "#" >> [email protected];             echo Target buildinfo from: "$(file)";             echo "# from $(file)" >> [email protected];             echo "#" >> [email protected];             cat $(file) >> [email protected];         fi;)
    $(if $(ADDITIONAL_BUILD_PROPERTIES),         $(hide) echo >> [email protected];                 echo "#" >> [email protected];                 echo "# ADDITIONAL_BUILD_PROPERTIES" >> [email protected];                 echo "#" >> [email protected]; )
    $(hide) $(foreach line,$(ADDITIONAL_BUILD_PROPERTIES),         echo "$(line)" >> [email protected];)
    $(hide) build/tools/post_process_props.py [email protected]

    其中system_prop_file定义:

ifdef TARGET_SYSTEM_PROP
system_prop_file := $(TARGET_SYSTEM_PROP)
else
system_prop_file := $(wildcard $(TARGET_DEVICE_DIR)/system.prop)
endif

    即$(TARGET_DEVICE_DIR)/system.prop文件

  到此,prop文件生成完毕!

 

2.对生成的build.prop的属性进行说明:

# begin build properties
# autogenerated by buildinfo.sh
ro.build.id=KTU84P  #版本ID
ro.build.display.id=aosp_almond-userdebug 4.4.4 KTU84P TVOS-04.19.010.02.06.Mooney test-keys  #具体版本号
ro.build.version.incremental=TVOS-04.19.010.02.07.Mooney  #版本增量说明
ro.build.version.sdk=19  #SDK版本
ro.build.version.codename=REL  #版本代号
ro.build.version.release=4.4.4  #Android系统版本
ro.build.date=2017年 07月 13日 星期四 14:39:47 CST  #编译时间
ro.build.date.utc=1499927987  #编译时间(UTC)
ro.build.type=userdebug  #编译类型(eng/user)
ro.build.user=pngcui  #编译者
ro.build.host=Sky-pngcui  #编译机器名
ro.build.tags=test-keys  #系统标记
ro.product.model=MSD6A648  #设备型号
ro.product.brand=MStar  #设备品牌
ro.product.name=aosp_almond  #产品名
ro.product.device=almond  #采用的设备名
ro.product.board=almond  #采用的主板名
ro.product.cpu.abi=armeabi-v7a  #CPU版本
ro.product.cpu.abi2=armeabi  #CPU品牌
ro.product.manufacturer=Skyworth-qx, Inc.  #产品制造商
ro.product.locale.language=zh
ro.product.locale.region=CN
ro.wifi.channels=  #无线局域网络的通信信道,空白表示自动识别
ro.board.platform=mooney  #主板平台
# ro.build.product is obsolete; use ro.product.device
ro.build.product=almond  #设备名,已被废弃,使用ro.product.device
# Do not try to parse ro.build.description or .fingerprint
ro.build.description=aosp_almond-userdebug 4.4.4 KTU84P TVOS-04.19.010.02.06.Mooney test-keys  #用户key
ro.build.fingerprint=MStar/aosp_almond/almond:4.4.4/KTU84P/TVOS-04.19.010.02.06.Mooney:userdebug/test-keys  #机身码
ro.build.characteristics=tv
# end build properties

 

3.修改prop的属性的说明,需要对照build/tools/buildinfo.sh进行

  3.1.ro.build.id属性(build/core/build_id.mk)

export BUILD_ID=8M648

  3.2.ro.build.display.id(build/core/Makefile)

build_desc := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER) $(BUILD_VERSION_TAGS)

# Display parameters shown under Settings -> About Phone
ifeq ($(TARGET_BUILD_VARIANT),user)
  # User builds should show:
  # release build number or branch.buld_number non-release builds

  # Dev. branches should have DISPLAY_BUILD_NUMBER set
  ifeq "true" "$(DISPLAY_BUILD_NUMBER)"
    BUILD_DISPLAY_ID := $(BUILD_ID).$(BUILD_NUMBER) $(BUILD_KEYS)
  else
    BUILD_DISPLAY_ID := $(BUILD_ID) $(BUILD_KEYS)
  endif
else
  # Non-user builds should show detailed build information
    BUILD_DISPLAY_ID := $(build_desc)
endif

  3.3.ro.build.version.incremental(device/mstar/almond/BoardConfigCommon.mk)

BUILD_NUMBER := TVOS-04.19.010.02.07.Mooney

  3.4.ro.product.model、ro.product.brand、ro.product.name、ro.product.device、ro.product.manufacturer(device/mstar/almond/aosp_almond.mk)

# Set those variables here to overwrite the inherited values.
PRODUCT_NAME := aosp_almond
PRODUCT_DEVICE := almond
PRODUCT_BRAND := MStar
PRODUCT_MODEL := MSD6A648
PRODUCT_MANUFACTURER := Skyworth-qx, Inc.

  注:PRODUCT_DEVICE会决定device下目录的选择,故尽量不要更改

  3.5.ro.build.description(build/core/Makefile)

build_desc := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER) $(BUILD_VERSION_TAGS)

$(INSTALLED_BUILD_PROP_TARGET): PRIVATE_BUILD_DESC := $(build_desc)

  3.6.ro.product.board(device/mstar/almond/BoardConfig.mk)

TARGET_BOOTLOADER_BOARD_NAME := almond

 

4.Android系统中Setting.apk中内核版本

  packages/apps/Settings/src/com/android/settings/DeviceInfoSettings.java

 1 private static final String FILENAME_PROC_VERSION = "/proc/version";
 2 private static final String KEY_KERNEL_VERSION = "kernel_version";
 3 
 4 @Override
 5 public void onCreate(Bundle icicle) {   
 6   findPreference(KEY_KERNEL_VERSION).setSummary(getFormattedKernelVersion());
 7 }
 8 
 9     public static String getFormattedKernelVersion() {
10         try {
11             return formatKernelVersion(readLine(FILENAME_PROC_VERSION));
12 
13         } catch (IOException e) {
14             Log.e(LOG_TAG,
15                 "IO Exception when getting kernel version for Device Info screen",
16                 e);
17 
18             return "Unavailable";
19         }
20     }
21 
22   public static String formatKernelVersion(String rawKernelVersion) {
23         // Example (see tests for more):
24         // Linux version 3.0.31-g6fb96c9 ([email protected]) 25         //     (gcc version 4.6.x-xxx 20120106 (prerelease) (GCC) ) #1 SMP PREEMPT 26         //     Thu Jun 28 11:02:39 PDT 2012
27 
28         final String PROC_VERSION_REGEX =
29             "Linux version (\\S+) " + /* group 1: "3.0.31-g6fb96c9" */
30             "\\((\\S+?)\\) " +        /* group 2: "[email protected]" (kernel builder) */
31             "(?:\\(gcc.+? \\)) " +    /* ignore: GCC version information */
32             "(#\\d+) " +              /* group 3: "#1" */
33             "(?:.*?)?" +              /* ignore: optional SMP, PREEMPT, and any CONFIG_FLAGS */
34             "((Sun|Mon|Tue|Wed|Thu|Fri|Sat).+)"; /* group 4: "Thu Jun 28 11:02:39 PDT 2012" */
35 
36         Matcher m = Pattern.compile(PROC_VERSION_REGEX).matcher(rawKernelVersion);
37         if (!m.matches()) {
38             Log.e(LOG_TAG, "Regex did not match on /proc/version: " + rawKernelVersion);
39             return "Unavailable";
40         } else if (m.groupCount() < 4) {
41             Log.e(LOG_TAG, "Regex match on /proc/version only returned " + m.groupCount()
42                     + " groups");
43             return "Unavailable";
44         }
45         return m.group(1) + "\n" +                 // 3.0.31-g6fb96c9
46             m.group(2) + " " + m.group(3) + "\n" + // [email protected] #1
47             m.group(4);                            // Thu Jun 28 11:02:39 PDT 2012
48     }
49             

  即从/proc/version文件中提取相应信息。

 

以上是关于Android之build.prop属性详解的主要内容,如果未能解决你的问题,请参考以下文章

Android build.prop参数详解

Android4.0.4-在build.prop中添加属性的方法

Android的系统属性:build.propSystemProperties

Android——build.prop 解析

Android——build.prop 解析

Android系统下的build.prop文件