修改Android系统版本号

Build.VERSION.INCREMENTAL、ro.build.version.incremental、BUILD_NUMBER、AOSP、Android源码、Android11

0. 需求背景

系统INCREMENTAL版本号默认是eng..20240717.154301格式,希望在必要时可以自定义版本号

1. 搜索路径

从Android SDK源码可知Build.VERSION.INCREMENTAL实际读取的是系统属性ro.build.version.incremental,线索可以自从ro.build.version.incremental入手。
结合之前对build属性的了解,直接在aosp/build目录进行搜索,先搜索.mk文件没发现ro.build.version.incremental,再搜索.sh文件找到位置

./make/tools/buildinfo.sh:8:echo "ro.build.version.incremental=$BUILD_NUMBER"

继续在.mk中搜索BUILD_NUMBER,发现主要是在version_defaults.mk文件中处理

/make/core/version_defaults.mk:26:#     BUILD_NUMBER
./make/core/version_defaults.mk:282:# BUILD_DATETIME and DATE can be removed once BUILD_NUMBER moves
./make/core/version_defaults.mk:286:HAS_BUILD_NUMBER := true
./make/core/version_defaults.mk:287:ifndef BUILD_NUMBER
./make/core/version_defaults.mk:288:  # BUILD_NUMBER should be set to the source control value that
./make/core/version_defaults.mk:294:  # If no BUILD_NUMBER is set, create a useful "I am an engineering build
./make/core/version_defaults.mk:297:  BUILD_NUMBER := eng.$(shell echo $${BUILD_USERNAME:0:6}).$(shell $(DATE) +%Y%m%d.%H%M%S)
./make/core/version_defaults.mk:298:  HAS_BUILD_NUMBER := false
./make/core/version_defaults.mk:300:.KATI_READONLY := BUILD_NUMBER HAS_BUILD_NUMBER

打开version_defaults.mk文件,其中关键代码为

HAS_BUILD_NUMBER := true
ifndef BUILD_NUMBER
  # BUILD_NUMBER should be set to the source control value that
  # represents the current state of the source code.  E.g., a
  # perforce changelist number or a git hash.  Can be an arbitrary string
  # (to allow for source control that uses something other than numbers),
  # but must be a single word and a valid file name.
  #
  # If no BUILD_NUMBER is set, create a useful "I am an engineering build
  # from this date/time" value.  Make it start with a non-digit so that
  # anyone trying to parse it as an integer will probably get "0".
  BUILD_NUMBER := eng.$(shell echo $${BUILD_USERNAME:0:6}).$(shell $(DATE) +%Y%m%d.%H%M%S)
  HAS_BUILD_NUMBER := false
endif

那就好吧了,直接在环境变量中定义BUILD_NUMBER即可。

2. 解决方案

在编译时增加环境变量

source build/envsetup.sh &&
lunch ${DEVICE}-${BUILD_VARIANT} &&
BUILD_NUMBER=${Your_Version} PRODUCT_NAME=${Your_ProductName} ./build.sh -AUCKuo -J32
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容