客制化某个项目是否编译某个apk和客制化某个项目是否运行此段代码

客制化某个项目是否编译某个apk

定义一个脚本:modify_config_before_make.sh

#!/bin/bash
echo "================== Enter modify_config_before_make.sh ===================="
modifyconfigssrcsrc=$1
#PRODUCT=$2
linenumber=0
isaddcontent=yes
tagleft=unknow
tagright=unknow
desfilepath=unknow
desfilename=unknow
	
echo "||=============== modify 3G configs ===============>"
	if [ -e $modifyconfigssrcsrc ]; then
		echo "||------------------------------------------------"
		while read srcline
		do
			tagleft=${srcline//\:*/} 
			tagright=${srcline//*\:/}  
			linenumber=0
			
			if [ "${srcline//\#*/#}" = "#" ]; then
				continue
			fi
			
			if [ "$tagleft" = "openfile" ]; then
				desfilename=$tagright
				if [ "$desfilename" = "ProjectConfig.mk" ]; then
					desfilepath=$TARGET_DEVICE_DIR/$desfilename
				elif [ "$desfilename" = "custom.conf" ]; then
					desfilepath=$MTK_COMMON/$desfilename					
				fi
				continue
			elif [ "$tagleft" = "endfile" ] && [ "$tagright" = "$desfilename" ]; then
				desfilepath=unknow
				desfilename=unknow
				continue
			fi
		 
			if [ "$desfilename" = "ProjectConfig.mk" ]; then
				srcvar=${srcline//=*/}
			elif [ "$desfilename" = "custom.conf" ]; then
				srcvar=${srcline//=*/}				
			fi
		
			if [ -e $desfilepath ]; then
				while read desline
				do
					linenumber=` expr $linenumber + 1 `
					if [ "$desfilename" = "ProjectConfig.mk" ]; then
						desvar=${desline//=*/}
					elif [ "$desfilename" = "custom.conf" ]; then
						desvar=${desline//=*/}						
					elif [ "$desfilename" = "init.rc" ]; then
						desvar=${desline//\ */}
						#echo desvar  $echo
					fi
					if [ "$desvar" = "$srcvar" ] && [ "$desvar" != "" ]; then
						echo "||-- modifined file:   " $desfilename ":" $linenumber
						echo "||-- before modifined: " $desline
						echo "||-- after modifined:  " $srcline
						sed -i -e "$linenumber s:$desline:$srcline:" $desfilepath
						echo "||------------------------------------------------"
						isaddcontent=no
						break 
					fi
				done < $desfilepath
				if [ "$isaddcontent" = "yes" ]; then
					echo "||++ add  "  $srcline "  to" $desfilename
					echo $srcline >> $desfilepath
					echo "||------------------------------------------------"
				fi 
				isaddcontent=yes
			fi
			
		done < $modifyconfigssrcsrc
	else
		echo "||the file $modifyconfigssrcsrc is not exists"
	fi
echo "================== End modify_config_before_make.sh ===================="

然后把需要改变的文件和需要改变的内容写到下面的文件:modifyconfigs_before_build

openfile:ProjectConfig.mk


CUSTOM_KERNEL_IMGSENSOR = sp2518_yuv gc5025_mipi_raw sp5506_mipi_raw
CUSTOM_HAL_IMGSENSOR = sp2518_yuv gc5025_mipi_raw sp5506_mipi_raw
CUSTOM_KERNEL_MAIN_IMGSENSOR = gc5025_mipi_raw sp5506_mipi_raw
CUSTOM_HAL_MAIN_IMGSENSOR = gc5025_mipi_raw sp5506_mipi_raw

VIDEO_TYPE=yzx_xiaoyong
YYD_5MIC_SUPPORT = yes
MTK_Y20D_CHARGE_LED = yes
WAKE_UP_NAME=8163_YYD_XIAOYONG_Y20_QQY
LCM_HEIGHT = 720
LCM_WIDTH = 1280
BOOT_LOGO = hd720nl
MTK_Y20D_DDR_SUPPORT =yes
CUSTOM_LK_LCM = jd_9365_cpt
CUSTOM_UBOOT_LCM = jd_9365_cpt
CUSTOM_KERNEL_LCM = jd_9365_cpt
CUSTOM_NAME = xiaoyong
MTK_SHARED_SDCARD = yes
#adupsfota start
ADUPS_FOTA_SUPPORT=yes
ADUPS_FOTA_WITH_ICON=no
ADUPS_FOTA_WITHOUT_MENU=no
#adupsfota 
YYD_AR_SUPPORT = yes
YYD_HUDONG_GAME = yes
#加入该键值对
YYD_APP_Update_SUPPORT = yes
endfile:ProjectConfig.mk

然后再客制化脚本中增加以下代码:

# 针对客户项目,修改以下几个文件中配置 custom.conf(device/mediatek/common/) ProjectConfig.mk(device/yongyida/y20a_dev/)
if [ -e $CUSTOMIZATION_PATH/oem/modifyconfigs_before_build ]; then
. yongyida/tools/modify_config_before_make.sh $CUSTOMIZATION_PATH/oem/modifyconfigs_before_build
fi


在.repo的manifest中加入该仓库。

在device.mk中加入条件:

ifeq ($(strip $(YYD_APP_Update_SUPPORT)), yes)
PRODUCT_PACKAGES += YYDRobotAppUpdateService
endif



客制化某个项目是否运行此段代码

在客制化路径放入一个overrides.prop,然后加入你要加入或者覆盖的build.prop的字段,然后代码中就可以通过查询build.prop的属性的键值对来判断是否执行某段代码:

# This file will be parsed by build/tools/customize_props.py.
# Properties in this file will override properties in /system/build.prop
# If propertyies in this file does not exist in /system/build.prop, the 
# properties will be added into /system/build.prop
# Property format are key = value 
ro.product.model=Y20D
persist.music.usexiri=true

在客制化脚本加入以下代码:

#拷贝 overrides.prop 到设备目标路径,即 device/yongyida/y20a_dev 下,修改build.prop属性。
if [ -e $CUSTOMIZATION_PATH/oem/overrides.prop ]; then
	cp  -rf $CUSTOMIZATION_PATH/oem/overrides.prop $TARGET_DEVICE_DIR/
fi

放到target device目录后,编译时会加入到build.prop中


然后在应用代码中加入判断:

String model = SystemProperties.get("ro.product.model", "");
if(model.equal("Y20D")){
    //执行客制化代码


猜你喜欢

转载自blog.csdn.net/b1480521874/article/details/80909052