赞
踩
接触android Framework 层开发没多久,最近学习了一下系统的裁剪的工作,一般系统裁剪分为 APK、so、jar 库和服务的裁剪,目前只学习了APK和so库的裁剪,这里做一下学习记录
因为安卓系统里内置了很多的APK,包括一些平台也会内置一些APK在系统里面,有些不需要的我们就可以把它不编译到系统里来,至于那些APK可以不用,这个可以根据自己项目的需求来,刚开始学的可以用adb 在system/app 或者 system/priv-app 目录下找
想要把app编译到系统,都需要在.mk文件中添加,而PRODUCT_PACKAGES 就是添加APK的变量,我用RK自己的一个APP(RKUpdateService)做为例子,先找到APK在哪里添加的,因为RK的应用都在vendor/rockchip/common/apps/目录下,可以使用grep -nr “RKUpdateService” vendor/rockchip/common/apps/ 搜索:
在app.mk就可以看到添加APK的代码
正常来说把RKUpdateService 这行注释掉就可以完成裁剪的操作,但是不好统一管理,如果删除了多个需要恢复的时候又得一个一个去找很不方便,在网上参考了这篇文章,把APK进行了统一的管理
首先先找到系统在哪里添加所有的APK,使用grep 搜索 PRODUCT_PACKAGES 在build/core/main.mk文件中
ifdef FULL_BUILD
# 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.
product_MODULES := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES)
# Filter out the overridden packages before doing expansion
product_MODULES := $(filter-out $(foreach p, $(product_MODULES), \
$(PACKAGES.$(p).OVERRIDES)), $(product_MODULES))
# Filter out executables as well
product_MODULES := $(filter-out $(foreach m, $(product_MODULES), \
$(EXECUTABLES.$(m).OVERRIDES)), $(product_MODULES))
在这里把所有的使用PRODUCT_PACKAGES 添加的APK 都找统一找出来,可以根据这个添加一个宏,把要删除的APK统一起来
然后在build/core/product.mk文件中添加PRODUCT_DEL_PACKAGES宏
在新建的evb_del.mk文件中把要删除的APK添加进来
最后需要在main.mk把PRODUCT_DEL_PACKAGES的APK移除出去
ifdef FULL_BUILD # 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. product_MODULES := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES) # Filter out the overridden packages before doing expansion product_MODULES := $(filter-out $(foreach p, $(product_MODULES), \ $(PACKAGES.$(p).OVERRIDES)), $(product_MODULES)) # Filter out executables as well product_MODULES := $(filter-out $(foreach m, $(product_MODULES), \ $(EXECUTABLES.$(m).OVERRIDES)), $(product_MODULES)) #裁剪app---------------------------------- product_sub_MODULES := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_DEL_PACKAGES) product_MODULES := $(filter-out $(foreach p, $(product_sub_MODULES), \ $(p)), $(product_MODULES)) #---------------------------------
最后这样编译后再到system/app目录下应该已经没有上面的APK了
//在这里把使用 PRODUCT_COPY_FILES so库统一添加 unique_product_copy_files_pairs := $(foreach cf,$(PRODUCT_COPY_FILES), \ $(if $(filter $(unique_product_copy_files_pairs),$(cf)),,\ $(eval unique_product_copy_files_pairs += $(cf)))) unique_product_copy_files_destinations := $(foreach cf,$(unique_product_copy_files_pairs), \ $(eval _src := $(call word-colon,1,$(cf))) \ $(eval _dest := $(call word-colon,2,$(cf))) \ $(call check-product-copy-files,$(cf)) \ $(if $(filter $(unique_product_copy_files_destinations),$(_dest)), \ $(info PRODUCT_COPY_FILES $(cf) ignored.), \ $(eval _fulldest := $(call append-path,$(PRODUCT_OUT),$(_dest))) \ $(if $(filter %.xml,$(_dest)),\ $(eval $(call copy-xml-file-checked,$(_src),$(_fulldest))),\ $(eval $(call copy-one-file,$(_src),$(_fulldest)))) \ $(eval ALL_DEFAULT_INSTALLED_MODULES += $(_fulldest)) \ $(eval unique_product_copy_files_destinations += $(_dest)))) #$(warning , $(unique_product_copy_files_destinations)) unique_product_copy_files_pairs := unique_product_copy_files_destinations :=
后续的逻辑和APK的一样
在build/core/product.mk添加,PRODUCT_DEL_SO宏
在前面新建的evb_del.mk文件中添加so库
PRODUCT_DEL_SO += \
vendor/rockchip/common/apps/RKUpdateService/lib/arm/librockchip_update_jni.so:system/lib/librockchip_update_jni.so
#获取要删除的so库------------------------------ unique_product_dle_files_pairs := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_DEL_SO) #$(warning , "unique_product_dle_files_pairs Build") #$(warning , $(unique_product_dle_files_pairs)) #-------------------------------------------- unique_product_copy_files_pairs := $(foreach cf,$(PRODUCT_COPY_FILES), \ $(if $(filter $(unique_product_copy_files_pairs),$(cf)),,\ $(eval unique_product_copy_files_pairs += $(cf)))) #过滤 so库 PRODUCT_DEL_SO ---------------------------- unique_product_copy_files_pairs := $(filter-out $(foreach p, $(unique_product_dle_files_pairs), \ $(p)), $(unique_product_copy_files_pairs)) #$(warning , $(unique_product_copy_files_pairs)) #-------------------------------------------------- unique_product_copy_files_destinations := $(foreach cf,$(unique_product_copy_files_pairs), \ $(eval _src := $(call word-colon,1,$(cf))) \ $(eval _dest := $(call word-colon,2,$(cf))) \ $(call check-product-copy-files,$(cf)) \ $(if $(filter $(unique_product_copy_files_destinations),$(_dest)), \ $(info PRODUCT_COPY_FILES $(cf) ignored.), \ $(eval _fulldest := $(call append-path,$(PRODUCT_OUT),$(_dest))) \ $(if $(filter %.xml,$(_dest)),\ $(eval $(call copy-xml-file-checked,$(_src),$(_fulldest))),\ $(eval $(call copy-one-file,$(_src),$(_fulldest)))) \ $(eval ALL_DEFAULT_INSTALLED_MODULES += $(_fulldest)) \ $(eval unique_product_copy_files_destinations += $(_dest)))) #$(warning , $(unique_product_copy_files_destinations)) unique_product_copy_files_pairs := unique_product_copy_files_destinations :=
主要的修改都标识出来了,需要注意的是,有的so库在lib和lib64都有添加,所以要裁剪的时候要把两个都添加进来,不然在lib删了,lib64还是会有
在evb_del.mk中把lib64的也添加进来
只是个人学习记录,亲测是可以完成裁剪的操作
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。