05 Android系统之删除Android原生内置APK
【摘要】
两种方法
为了在编译阶段将内置apk给异常,下面提供2中方法。
直接找到添加这个apk的mk文件,从 PRODUCT_PACKAGES 中删除通过添加模块,LOCAL_OVERRIDES_PACKAG...
两种方法
为了在编译阶段将内置apk给异常,下面提供2中方法。
- 直接找到添加这个apk的mk文件,从 PRODUCT_PACKAGES 中删除
- 通过添加模块,
LOCAL_OVERRIDES_PACKAGES
定义要覆盖的apk
目录结构
hinzer@ubuntu:android-10$ tree ./device/mi/pure/
./device/mi/pure/
├── Android.mk
├── AndroidProducts.mk
├── BoardConfig.mk
├── product01.mk
- 1
- 2
- 3
- 4
- 5
- 6
操作过程
1、 直接从 PRODUCT_PACKAGES 中删除
# step1 找到apk添加到 PRODUCT_PACKAGES 的那个mk文件
$ mgrep Contacts
# step2 从改mk文件中移除配置项
.....
# step3 清理system目录,重新编译
$ rm -rf out/target/product/pure/system
# step4 验证
make -j4 && emulator
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
2、 通过 LOCAL_OVERRIDES_PACKAGES 删除
- 在Product下添加一个模块
remove_unused_module
$ vim Android.mk
include $(CLEAR_VARS)
LOCAL_MODULE := remove_unused_module
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := FAKE # 指定编译输出的目录为 $(PRODUCT_OUT)/fake_packages
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_OVERRIDES_PACKAGES += \
Contacts \
Email #这里添加要覆盖的apk
include $(BUILD_SYSTEM)/base_rules.mk
$(LOCAL_BUILT_MODULE):
$(hide) echo "Fake: $@"
$(hide) mkdir -p $(dir $@)
$(hide) touch $@
PACKAGES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 将
remove_unused_module
添加到对应product文件的PRODUCT_PACKAGES配置
PRODUCT_PACKAGES += remove_unused_module
- 1
- 清理
out/target/product/pure/system
目录,验证
$ rm -rf out/target/product/pure/system
$ make -j4 && emulator
- 1
- 2
原理补充(PRODUCT_PACKAGES)
对于第一种方法,通过mgrep
命令能够搜索到这个mk文件定义了PRODUCT_PACKAGES,直接移除就ok。对于第二种方法,在 main.mk 里面有对 OVERRIDES_PACKAGES
进行处理(在android-10源码中对这个关键词进行检索)
# Lists most of the files a particular product installs, including:
# - PRODUCT_PACKAGES, and their LOCAL_REQUIRED_MODULES
# - PRODUCT_COPY_FILES
# The base list of modules to build for this product is specified
# by the appropriate product definition file, which was included
# by product_config.mk.
# Name resolution for PRODUCT_PACKAGES:
# foo:32 resolves to foo_32;
# foo:64 resolves to foo;
# foo resolves to both foo and foo_32 (if foo_32 is defined).
#
# Name resolution for LOCAL_REQUIRED_MODULES:
# If a module is built for 2nd arch, its required module resolves to
# 32-bit variant, if it exits. See the select-bitness-of-required-modules definition.
# $(1): product makefile
define product-installed-files
$(eval _mk := $(strip $(1))) \
$(eval _pif_modules := \
$(PRODUCTS.$(_mk).PRODUCT_PACKAGES) \
$(if $(filter eng,$(tags_to_install)),$(PRODUCTS.$(_mk).PRODUCT_PACKAGES_ENG)) \
$(if $(filter debug,$(tags_to_install)),$(PRODUCTS.$(_mk).PRODUCT_PACKAGES_DEBUG)) \
$(if $(filter tests,$(tags_to_install)),$(PRODUCTS.$(_mk).PRODUCT_PACKAGES_TESTS)) \
$(if $(filter asan,$(tags_to_install)),$(PRODUCTS.$(_mk).PRODUCT_PACKAGES_DEBUG_ASAN)) \
$(call auto-included-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 ### Resolve the :32 :64 module name) \
$(eval _pif_modules_32 := $(patsubst %:32,%,$(filter %:32, $(_pif_modules)))) \
$(eval _pif_modules_64 := $(patsubst %:64,%,$(filter %:64, $(_pif_modules)))) \
$(eval _pif_modules_rest := $(filter-out %:32 %:64,$(_pif_modules))) \
$(eval ### Note for 32-bit product, 32 and 64 will be added as their original module names.) \
$(eval _pif_modules := $(call get-32-bit-modules-if-we-can, $(_pif_modules_32))) \
$(eval _pif_modules += $(_pif_modules_64)) \
$(eval ### For the rest we add both) \
$(eval _pif_modules += $(call get-32-bit-modules, $(_pif_modules_rest))) \
$(eval _pif_modules += $(_pif_modules_rest)) \
$(call expand-required-modules,_pif_modules,$(_pif_modules),$(_pif_overrides)) \
$(filter-out $(HOST_OUT_ROOT)/%,$(call module-installed-files, $(_pif_modules))) \
$(call resolve-product-relative-paths,\
$(foreach cf,$(PRODUCTS.$(_mk).PRODUCT_COPY_FILES),$(call word-colon,2,$(cf))))
endef
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
有定义
$(eval _pif_modules := $(filter-out $(_pif_overrides), $(_pif_modules)))
filter-out是Makefile语法支持的函数,从$(_pif_modules)
中 反选过滤出$(_pif_overrides)
之外的所有modules。
涉及到android build系统,我现在也还没搞清楚逻辑链,有待补充。
参考资料
文章来源: blog.csdn.net,作者:hinzer,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/feit2417/article/details/105237647
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)