裁剪应用
1. 修改 build/core/product.mk
添加PRODUCT_DEL_PACKAGES变量的声明
新增一行_product_single_value_vars += PRODUCT_DEL_PACKAGES
# The first API level this product shipped with
_product_single_value_vars += PRODUCT_SHIPPING_API_LEVEL
_product_single_value_vars += PRODUCT_DEL_PACKAGES # 新增_product_list_vars += VENDOR_PRODUCT_RESTRICT_VENDOR_FILES
_product_list_vars += VENDOR_EXCEPTION_MODULES
2. 修改 build/core/main.mk
修改 product-installed-files 函数的定义,增加两行:
$(eval _pif_dels := ( c a l l g e t − p r o d u c t − v a r , (call get-product-var, (callget−product−var,(1),PRODUCT_DEL_PACKAGES))
$(eval _pif_modules := $(filter-out $(_pif_dels), $(_pif_modules))) \
$(eval ### Filter out the overridden packages and executables before doing expansion) \$(eval _pif_overrides := $(call module-overrides,$(_pif_modules))) \$(eval _pif_modules := $(filter-out $(_pif_overrides), $(_pif_modules))) \$(eval _pif_dels := $(call get-product-var,$(1),PRODUCT_DEL_PACKAGES)) \$(eval _pif_modules := $(filter-out $(_pif_dels), $(_pif_modules))) \$(eval ### Resolve the :32 :64 module name) \
3. 在相应的设备产品mk文件中添加用PRODUCT_DEL_PACKAGES属性来控制模块删除
一般编辑的文件路径为device/公司名/产品名/device.mk, 比如rk3399中:
device/rockchip/rk3399/device.mk
我用的模拟器,使用 lunch sdk_pc_x86_64-userdebug,文件位置为:
aosp/build/target/board/emulator_x86_64/device.mk
PRODUCT_SOONG_NAMESPACES += device/generic/goldfish # for libwifi-hal-emu
PRODUCT_SOONG_NAMESPACES += device/generic/goldfish-opengl # for goldfish deps.ifdef NET_ETH0_STARTONBOOTPRODUCT_VENDOR_PROPERTIES += net.eth0.startonboot=1
endif# Ensure we package the BIOS files too.
PRODUCT_HOST_PACKAGES += \bios.bin \vgabios-cirrus.bin \# 要裁剪的应用
PRODUCT_DEL_PACKAGES += \messaging \Dialer \Contacts \Email \Camera2 \Browser2 \Calendar \DocumentsUI \Music \MusicFX \ExactCalculator \
4. 进行编译
source build/envsetup.sh
# lunch sdk_pc_x86_64-userdebug # 模拟器
lunch xxx-userdebug #xxx表示对应的产品名
make
Android12 系统的裁剪编译规则
裁剪Service,打印机服务
1. 定义boolean变量,从全局属性读取配置
boolean disablePrinter = SystemProperties.getBoolean("config.disable_printer", false);
2. 根据属性判断是否启动服务
if (!disablePrinter && mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) {mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS);
}
3. 增加配置参数
在PRODUCT_PROPERTY_OVERRIDES中增加 config.disable_printer 配置
位置:/data/aosp/build/target/board/emulator_x86_64/device.mk
# 裁剪应用
PRODUCT_DEL_PACKAGES += \messaging \Dialer \Contacts \Email \Camera2 \Browser2 \Calendar \DocumentsUI \Music \MusicFX \ExactCalculator \# printer服务是否开启
PRODUCT_PROPERTY_OVERRIDES += \config.disable_printer=true
5. 屏蔽SystemFeature
查找含有<feature name=“android.software.print” /> 的文件,
通过aosp/frameworks/base/core/java/com/android/server/SystemConfig.java的readAllPermissions方法可知,会在以下文件夹获取打印特性配置文件。
- /system/etc/permission
- /system/etc/sysconfig
- /vendor/etc/permission
- /vendor/etc/sysconfig
- /oem/etc/permission
- /oem/etc/sysconfig
- /odm/etc/permission
- /odm/etc/sysconfig
- /product/etc/permission
- /product/etc/sysconfig
- /system_ext/etc/permission
- /system_ext/etc/sysconfig
查找具体位置,是/vendor/etc/permissions/handheld_core_hardware.xml文件中设置
cd /vendor/etc
find ./ -type f -exec grep -rn "software.print" {} \;
再查找源文件,发现是在frameworks/native/data/etc/handheld_core_hardware.xml文件中,
注释掉 <feature name=“android.software.print” />
find ./ -name "*.mk" -exec grep -rn "handheld_core_hardware" {} \;
6. 修改汇总
7. 重新编译,刷机
删掉out目录下的build.prop,重新编译system(或者直接修改build.prop然后make snod)
通过build.prop生成过程的分析,可知可以修改buildinfo.sh;、 system.prop;、ADDITIONAL_BUILD_PROPERTIES或PRODUCT_PROPERTY_OVERRIDES。建议改system.prop或PRODUCT_PROPERTY_OVERRIDES
8. 修改系统文件改变属性值
emulator -writable-system
adb root
adb remount
adb disable-verity
adb reboot# 待手机重启
adb root
adb remount
修改config.disable_printer属性
adb pull /system/build.prop
# 修改导出的build.prop,末尾增加
####################################
# from variable PRODUCT_SYSTEM_DEFAULT_PROPERTIES
####################################
# Auto-added by post_process_props.py
persist.sys.usb.config=adb
config.disable_printer=false # 增加
# end of fileadb push build.prop /system/build.prop
adb reboot
修改handheld_core_hardware.xml文件
位置:/vendor/etc/permissions/handheld_core_hardware.xml
9. 测试
adb shell service list # 服务列表
adb shell service check printer # 检查服务是否开启
Android属性之build.prop生成过程分析
裁剪SystemServer服务以及关闭SystemFeature
adb remount fails - mount: ‘system’ not in /proc/mounts
关于如何修改android系统system文件夹下build.prop文件参数
其他
常用命令
adb shell pm list package -f # 应用和对应的包
find QSSI.12/out/target/product/qssi/ -name QtiDialer | xargs rm -rf # 查找,删除文件
模块 | make 命令 | mmm 命令 |
---|---|---|
init | make init | mmm system/core/init |
zygote | make app_process | mmm frameworks/base/cmds/app_process |
system_server | make services | mmm frameworks/base/services |
java framework | make framework-minus-apex | mmm frameworks/base |
res framework | make framework-res | mmm frameworks/base/core/res |
jni framework | make libandroid_runtime | mmm frameworks/base/core/jni |
binder | make libbinder | mmm frameworks/native/libs/binder |
我们也可以使用 allmod 指令查看所有的 module,再使用 make 指令编译我们需要的模块。
Android 编译之make基础
Android10.0编译系统
android device.mk文件在哪里