您好,欢迎访问三七文档
宏控方案实现原理:平台代码以前是用overlay来实现不同项目的不同风格,这样做的弊端是当修改了主干代码,不能同步到每一个overlay分支上。现在采用宏控制的方法,在cc++javah代码中用宏来控制代码的分支,方便以后在不同项目中的配置,只需要打开和关闭宏开关即可实现差异化修改方案:首先修改lunch文件,将要用到的宏添加到lunch文件中,这里用740代码的msm8916_32来验证,当需要打开的宏请添加在MEIG_TRUE_740_JULI后面,格式得是-DXXX,不需要打开的宏请添加在MEIG_FALSE_740_JULI后面,格式同上;1.在配置文件(lunch文件)中添加代码:#addbytanfusheng@20160118forcustomfunctionstart#这个路径是当前分支的路径,不同分支路径不一样MEIG_MK_PATH:=device/qcom/msm8916_32#要打开的宏MEIG_TRUE_740_JULI+=\-DFACTORYTEST\-DFACTORYTEST2#不需要打开的宏MEIG_FALSE_740_JULI+=\-DNO_FACTORY_TEST\-DNO_FACTORY_TEST2#以下这几行代码必须加上,用来将宏进行处理$(shellecho$(MEIG_TRUE_740_JULI)|sed's/-D/\r\n/g'meig_true_list.txt)$(shellecho$(MEIG_FALSE_740_JULI)|sed's/-D/\r\n/g'meig_false_list.txt)$(shellbuild/meig_find.sh)$(shellbuild/meig_function_java.sh)include$(MEIG_MK_PATH)/meig_module_function.mk#rm$(MEIG_MK_PATH)/meig_module_function.mk#addbytanfusheng@20160118forcustomfunctionend2.在Z:\tanfusheng\740\LA.BR.1.2.4-04310-8x16.0\build\core\binary.mk中添加代码:#addbytanfusheng@20160118forcustomfunctionstartnormal_objects_cflags+=$(MEIG_TRUE_740_JULI)#addbytanfusheng@20160118forcustomfunctionend3.在build/目录下添加文件meig_find.sh此文件主要用来将宏转化成在java文件中能识别的宏,也就是将宏全都写到一个文件中路径:frameworks/base/core/java/android/os/ForgeManage.java#!/bin/bashFORGE_PATH=frameworks/base/core/java/android/os/MeigFunctionManage.javased-e'1d'meig_true_list.txtmeig_output.txtsed-e'1d'meig_false_list.txtmeig_output_false.txtechopackageandroid.os;$FORGE_PATHechopublicclassMeigFunctionManage{$FORGE_PATHwhilereadlinedoechopublicstaticfinalString$line=\true\;$FORGE_PATHdonemeig_output.txtwhilereadlinedoechopublicstaticfinalString$line=\false\;$FORGE_PATHdonemeig_output_false.txtecho}$FORGE_PATH代码中用宏控制方法:1.在c,c++中用宏控制方法:直接用控制,如果编译到这个地方出现乱码,则表示此宏打开,否则表示此宏关闭Z:\tanfusheng\740\LA.BR.1.2.4-04310-8x16.0\frameworks\av\media\libstagefright\AudioPlayer.cpp中添加:#ifdefFACTORYTESTadfasdfaf153156,#endif#报错则说明此宏定义起作用了#ifdefNO_FACTORY_TESTadfasdfaf153156,#endif#不报错说明此宏为false,2在java中使用宏的方法:Z:\tanfusheng\740\LA.BR.1.2.4-04310-8x16.0\packages\apps\Music\src\com\android\music\MediaPlaybackService.java中if(true.equals(android.os.MeigFunctionManage.FACTORYTEST)){XXXX;//要实现的功能}这样即可实现宏在java文件中的控制。3.在mk文件中用宏控制代码:在配置文件msm8916_32.mk中添加代码:#执行脚本文件meig_function_java.sh$(shellbuild/meig_function_java.sh)#将中间文件meig_module_function.mk中的宏引进到配置文件中,MEIG_MK_PATH:=device/qcom/msm8916_32include$(MEIG_MK_PATH)/meig_module_function.mk来看看meig_function_java.sh代码:#!/bin/bashMEIG_MK_PATH=device/qcom/msm8916_32/meig_module_function.mksed-e'1d'meig_true_list.txtmeig_output.txtsed-e'1d'meig_false_list.txtmeig_output_false.txtecho$MEIG_MK_PATHwhilereadlinedoechoMEIG_TRUE_740_JULI_$line:=true|sed's/\r//g'$MEIG_MK_PATHdonemeig_output.txtwhilereadlinedoechoMEIG_FALSE_740_JULI_$line:=false|sed's/\r//g'$MEIG_MK_PATHdonemeig_output_false.txtrmmeig_output.txtrmmeig_output_false.txtrmmeig_true_list.txtrmmeig_false_list.txt在Z:\tanfusheng\740\LA.BR.1.2.4-04310-8x16.0\packages\apps\Music中的android.mk文件中使用宏:MEIG_TRUE_740_JULI_FACTORYTESTLOCAL_PATH:=$(callmy-dir)include$(CLEAR_VARS)LOCAL_MODULE_TAGS:=optionalLOCAL_SRC_FILES:=$(callall-java-files-under,src)\src/com/android/music/IMediaPlaybackService.aidlifeq(true,$(MEIG_TRUE_740_JULI_FACTORYTEST))LOCAL_PACKAGE_NAME:=MusicelseLOCAL_PACKAGE_NAME:=TfsMusicendifLOCAL_CERTIFICATE:=platformLOCAL_PROGUARD_FLAG_FILES:=proguard.flagsinclude$(BUILD_PACKAGE)#Usethefolloingincludetomakeourtestapk.include$(callall-makefiles-under,$(LOCAL_PATH))以上用颜色标注出来的代码,上库后就不用再修改注意在编译步骤:1执行.build/envsetup.sh2.执行lunch3.选定要编译的项目查看device/qcom/msm8916_32/meig_module_function.mk这个mk里的内容类似:MEIG_TRUE_740_JULI_FACTORYTEST:=trueMEIG_TRUE_740_JULI_FACTORYTEST2:=trueMEIG_FALSE_740_JULI_NO_FACTORY_TEST:=falseMEIG_FALSE_740_JULI_NO_FACTORY_TEST2:=false再查看frameworks/base/core/java/android/os/MeigFunctionManage.java里的内容类似:packageandroid.os;publicclassMeigFunctionManage{publicstaticfinalStringFACTORYTEST=true;publicstaticfinalStringFACTORYTEST2=true;publicstaticfinalStringNO_FACTORY_TEST=false;publicstaticfinalStringNO_FACTORY_TEST2=false;}4.先执行一次makeupdate-api5.执行make-j4
本文标题:宏的添加和使用
链接地址:https://www.777doc.com/doc-2498086 .html