Reputation: 8841
I try to run below prebuild project in aosp code. I found the apk size increased about 18MB after copied to target folder:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := com.sample.test
LOCAL_MODULE_OWNER := personal
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := APPS
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_SUFFIX := .apk
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_SRC_FILES := ./test.apk
LOCAL_PRODUCT_MODULE := true
LOCAL_PRIVILEGED_MODULE := true
include $(BUILD_PREBUILT)
Original test.apk and output apk size (14M to 32M):
-rwxrwxr-x 1 me 14M Feb 23 10:42 mytest/test.apk
-rw-rw-r-- 1 me 32M Feb 23 10:43 com.sample.test/com.sample.test.apk
What's the reason the prebuilt apk size increased so much?
Upvotes: 0
Views: 443
Reputation: 26
I also found this problem. And I check my apks, the class.dex file gets bigger.
When compiling, if app is priv app and it needs signed, the building system will uncompress class.dex. Check below .mk files:
dexpreopt_odex_install.mk
# We explicitly uncompress APKs of privileged apps, and used by
# privileged apps
ifneq (true,$(DONT_UNCOMPRESS_PRIV_APPS_DEXS))
ifeq (true,$(LOCAL_PRIVILEGED_MODULE))
LOCAL_UNCOMPRESS_DEX := true
endif
ifneq (,$(filter $(PRODUCT_LOADED_BY_PRIVILEGED_MODULES), $(LOCAL_MODULE)))
LOCAL_UNCOMPRESS_DEX := true
endif
endif # DONT_UNCOMPRESS_PRIV_APPS_DEXS
ifeq (,$(filter PRESIGNED,$(LOCAL_CERTIFICATE)))
# Store uncompressed dex files preopted in /system
ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true)
ifeq ($(call install-on-system-other, $(my_module_path)),)
LOCAL_UNCOMPRESS_DEX := true
endif # install-on-system-other
else # BOARD_USES_SYSTEM_OTHER_ODEX
LOCAL_UNCOMPRESS_DEX := true
endif
endif
app_prebuilt_internal.mk
...
ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
$(uncompress-dexs)
...
definitions.mk
# Uncompress dex files embedded in an apk.
#
define uncompress-dexs
if (zipinfo $@ '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then \
$(ZIP2ZIP) -i $@ -o [email protected] -0 "classes*.dex" && \
mv -f [email protected] $@ ; \
fi
endef
There are two steps to let apk size do not increase:
Set this in BoardConfig.mk
DONT_UNCOMPRESS_PRIV_APPS_DEXS := true.
change value from platform to PRESIGNED in your app's mk.(And you need sign your apk by yourself)
LOCAL_CERTIFICATE := PRESIGNED
Upvotes: 1