android源码编译时拷贝替换指定文件

卧疾丰暇豫,翰墨时间作。这篇文章主要讲述android源码编译时拷贝替换指定文件相关的知识,希望能为你提供帮助。
由于要做版本定制,某些版本的资源文件等(例如style.xml)需要不同的配置,但是android的编译开关无法在xml里使用,于是想到了编译时根据不同的编译开关编译不同的文件,如下:
1.建立A.xml文件,当编译开关OEM_CUSTOMER_SUPPORT=22时编译将该文件拷贝到指定目录。
建立B.xml文件,当编译开关OEM_CUSTOMER_SUPPORT不等于22时,将该文件拷贝到指定目录。
2.编写拷贝脚本文件myDefine.sh,内容为:
#!/bin/bash
#
if [ $OEM_CUSTOMER_SUPPORT -eq 22 ] ; then
cp packages/apps/xxx/config/A.xml  packages/apps/xxx/res/values/styles.xml
else
cp packages/apps/xxx/config/B.xml  packages/apps/xxx/res/values/styles.xml
fi
3.将拷贝脚本文件myDefine.sh加入到系统编译build/core/main.mk
......
# A helper goal printing out install paths
.PHONY: GET-INSTALL-PATH
GET-INSTALL-PATH:
@$(foreach m, $(ALL_MODULES), $(if $(ALL_MODULES.$(m).INSTALLED), \
echo ‘INSTALL-PATH: $(m) $(ALL_MODULES.$(m).INSTALLED)‘; ))
else # ONE_SHOT_MAKEFILE
ifneq ($(dont_bother),true)
#
# Include all of the makefiles in the system
#
# Can‘t use first-makefiles-under here because
# --mindepth=2 makes the prunes not work.
$(shell chmod 777 packages/apps/PeepHole/config/PeepHoleStyle.sh)
$(shell packages/apps/PeepHole/config/PeepHoleStyle.sh)
......
【android源码编译时拷贝替换指定文件】粗体部分为新加内容,第一句是使得sh脚本有读写执行的权限,第二句是真正的执行

    推荐阅读