Revert "Don't extract jni from prebuilt apks."

This reverts commit 3797466fbd.

Bug: 20810492
Bug: 20811499
Change-Id: Ic922d9daccc4550db489c0f3d4ad6b4ff85b5e60
This commit is contained in:
Ying Wang 2015-05-04 18:39:46 +00:00
parent 3797466fbd
commit 97dfa3177d
6 changed files with 52 additions and 28 deletions

View File

@ -20,6 +20,7 @@ LOCAL_UNSTRIPPED_PATH:=
LOCAL_MODULE_CLASS:=
LOCAL_MODULE_SUFFIX:=
LOCAL_PACKAGE_NAME:=
LOCAL_PAGE_ALIGN_JNI_SHARED_LIBRARIES:=
LOCAL_OVERRIDES_PACKAGES:=
LOCAL_EXPORT_PACKAGE_RESOURCES:=
LOCAL_MANIFEST_PACKAGE_NAME:=

View File

@ -2097,7 +2097,8 @@ $(hide) mkdir -p $(addprefix $(dir $@)lib/,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI))
$(foreach abi,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI),\
$(call _add-jni-shared-libs-to-package-per-abi,$(abi),\
$(patsubst $(abi):%,%,$(filter $(abi):%,$(PRIVATE_JNI_SHARED_LIBRARIES)))))
$(hide) (cd $(dir $@) && zip -r -0 $(notdir $@) lib)
$(hide) (cd $(dir $@) && zip -r \
$(if $(filter true, $(PRIVATE_PAGE_ALIGN_JNI_SHARED_LIBRARIES)),-0,) $(notdir $@) lib)
$(hide) rm -rf $(dir $@)lib
endef
@ -2143,22 +2144,21 @@ endef
define align-package
$(hide) mv $@ $@.unaligned
$(hide) $(ZIPALIGN) \
-f -p \
-f \
$(if $(filter true, $(PRIVATE_PAGE_ALIGN_JNI_SHARED_LIBRARIES)),-p,) \
4 \
$@.unaligned $@.aligned
$(hide) mv $@.aligned $@
endef
# Uncompress shared libraries embedded in an apk.
#
define uncompress-shared-libs
$(hide) if unzip -l $@ $(PRIVATE_EMBEDDED_JNI_LIBS) >/dev/null ; then \
rm -rf $(dir $@)uncompressedlibs && mkdir $(dir $@)uncompressedlibs; \
unzip $@ $(PRIVATE_EMBEDDED_JNI_LIBS) -d $(dir $@)uncompressedlibs && \
zip -d $@ 'lib/*.so' && \
( cd $(dir $@)uncompressedlibs && zip -D -r -0 ../$(notdir $@) lib ) && \
rm -rf $(dir $@)uncompressedlibs; \
fi
$(hide) rm -rf $(dir $@)/tmpworkdir
$(hide) mv $@ $@.compressed
$(hide) mkdir $(dir $@)/tmpworkdir
$(hide) unzip $@.compressed 'lib/*.so' -d $(dir $@)/tmpworkdir
$(hide) ( cd $(dir $@)/tmpworkdir && zip -D -r -0 ../$(notdir $@).compressed lib )
$(hide) mv $@.compressed $@
$(hide) rm -rf $(dir $@)/tmpworkdir
endef
define install-dex-debug

View File

@ -8,7 +8,7 @@
#
# Output variables:
# jni_shared_libraries, jni_shared_libraries_abi, jni_shared_libraries_with_abis if we are going to embed the libraries into the apk;
# embedded_prebuilt_jni_libs, prebuilt jni libs embedded in prebuilt apk.
# extracted_jni_libs, if we extract jni libs from prebuilt apk.
#
my_embed_jni :=
@ -27,7 +27,7 @@ jni_shared_libraries :=
jni_shared_libraries_abis :=
# jni_shared_libraries_with_abis is a list of <abi>:<path-to-the-built-jni-lib>
jni_shared_libraries_with_abis :=
embedded_prebuilt_jni_libs :=
extracted_jni_libs :=
#######################################
# For TARGET_ARCH
@ -51,7 +51,7 @@ jni_shared_libraries += $(my_jni_shared_libraries)
jni_shared_libraries_abis += $(my_jni_shared_libraries_abi)
jni_shared_libraries_with_abis += $(addprefix $(my_jni_shared_libraries_abi):,\
$(my_jni_shared_libraries))
embedded_prebuilt_jni_libs += $(my_embedded_prebuilt_jni_libs)
extracted_jni_libs += $(my_extracted_jni_libs)
# Include RS dynamically-generated libraries as well
# TODO: Add multilib support once RS supports generating multilib libraries.
@ -83,11 +83,11 @@ jni_shared_libraries += $(my_jni_shared_libraries)
jni_shared_libraries_abis += $(my_jni_shared_libraries_abi)
jni_shared_libraries_with_abis += $(addprefix $(my_jni_shared_libraries_abi):,\
$(my_jni_shared_libraries))
embedded_prebuilt_jni_libs += $(my_embedded_prebuilt_jni_libs)
extracted_jni_libs += $(my_extracted_jni_libs)
endif # my_add_jni
endif # TARGET_2ND_ARCH
jni_shared_libraries := $(strip $(jni_shared_libraries))
jni_shared_libraries_abis := $(sort $(jni_shared_libraries_abis))
jni_shared_libraries_with_abis := $(strip $(jni_shared_libraries_with_abis))
embedded_prebuilt_jni_libs := $(strip $(embedded_prebuilt_jni_libs))
extracted_jni_libs := $(strip $(extracted_jni_libs))

View File

@ -9,7 +9,7 @@
#
# Output variables:
# my_jni_shared_libraries, my_jni_shared_libraries_abi, if we are going to embed the libraries into the apk;
# my_embedded_prebuilt_jni_libs, prebuilt jni libs embedded in prebuilt apk.
# my_extracted_jni_libs, if we extract jni libs from prebuilt apk.
#
my_jni_shared_libraries := \
@ -19,7 +19,7 @@ my_jni_shared_libraries := \
# App-specific lib path.
my_app_lib_path := $(dir $(LOCAL_INSTALLED_MODULE))lib/$(TARGET_$(my_2nd_arch_prefix)ARCH)
my_embedded_prebuilt_jni_libs :=
my_extracted_jni_libs :=
ifdef my_embed_jni
# App explicitly requires the prebuilt NDK stl shared libraies.
@ -76,10 +76,34 @@ endif # $(my_jni_shared_libraries) not empty
endif # my_embed_jni
ifdef my_prebuilt_jni_libs
# Files like @lib/<abi>/libfoo.so (path inside the apk) are JNI libs embedded prebuilt apk;
# Install prebuilt JNI libs to the app specific lib path.
# Files like @path/to/libfoo.so (path inside the apk) are JNI libs extracted from the prebuilt apk;
# Files like path/to/libfoo.so (path relative to LOCAL_PATH) are prebuilts in the source tree.
my_embedded_prebuilt_jni_libs := $(patsubst @%,%, \
my_extracted_jni_libs := $(patsubst @%,%, \
$(filter @%, $(my_prebuilt_jni_libs)))
ifdef my_extracted_jni_libs
ifndef my_prebuilt_src_file
$(error No prebuilt apk to extract prebuilt jni libraries $(my_extracted_jni_libs))
endif
ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
$(warning Extracting files using LOCAL_PREBUILT_JNI_LIBS cannot be done while)
$(warning using LOCAL_CERTIFICATE:=PRESIGNED, as this would corrupt)
$(warning the APK or waste disk space. Instead, you should delete)
$(warning LOCAL_PREBUILT_JNI_LIBS and use LOCAL_PAGE_ALIGN_JNI_SHARED_LIBRARIES:=true)
$(warning This will allow loading of shared libraries directly from the APK,)
$(warning eliminating the need to separately extract them.)
$(error Failed to build: $(LOCAL_MODULE))
endif
# We use the first jni lib file as dependency.
my_installed_prebuilt_jni := $(my_app_lib_path)/$(notdir $(firstword $(my_extracted_jni_libs)))
$(my_installed_prebuilt_jni): PRIVATE_JNI_LIBS := $(my_extracted_jni_libs)
$(my_installed_prebuilt_jni): $(my_prebuilt_src_file)
@echo "Extract JNI libs ($@ <- $<)"
@mkdir -p $(dir $@)
$(hide) unzip -j -o -d $(dir $@) $< $(PRIVATE_JNI_LIBS) && touch $@
$(LOCAL_INSTALLED_MODULE) : | $(my_installed_prebuilt_jni)
endif
# prebuilt JNI exsiting as separate source files.
my_prebuilt_jni_libs := $(addprefix $(LOCAL_PATH)/, \

View File

@ -392,6 +392,7 @@ $(LOCAL_BUILT_MODULE): $(AAPT) | $(ZIPALIGN)
$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
# PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names.
$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
$(LOCAL_BUILT_MODULE): PRIVATE_PAGE_ALIGN_JNI_SHARED_LIBRARIES := $(LOCAL_PAGE_ALIGN_JNI_SHARED_LIBRARIES)
ifneq ($(TARGET_BUILD_APPS),)
# Include all resources for unbundled apps.
LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true

View File

@ -195,18 +195,14 @@ endif
include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
#######################################
# Sign and align non-presigned .apks.
# The embedded prebuilt jni to uncompress.
ifndef embedded_prebuilt_jni_libs
# No LOCAL_PREBUILT_JNI_LIBS, uncompress all.
embedded_prebuilt_jni_libs := 'lib/*.so'
endif
$(built_module): PRIVATE_EMBEDDED_JNI_LIBS := $(embedded_prebuilt_jni_libs)
$(built_module) : PRIVATE_PAGE_ALIGN_JNI_SHARED_LIBRARIES := $(LOCAL_PAGE_ALIGN_JNI_SHARED_LIBRARIES)
$(built_module) : $(my_prebuilt_src_file) | $(ACP) $(ZIPALIGN) $(SIGNAPK_JAR)
$(transform-prebuilt-to-target)
ifneq ($(LOCAL_CERTIFICATE),PRESIGNED)
@# Only strip out files if we can re-sign the package.
ifdef extracted_jni_libs
$(hide) zip -d $@ 'lib/*.so' # strip embedded JNI libraries.
endif
ifdef LOCAL_DEX_PREOPT
ifneq (nostripping,$(LOCAL_DEX_PREOPT))
$(call dexpreopt-remove-classes.dex,$@)
@ -214,7 +210,9 @@ endif
endif
$(sign-package)
endif
ifeq ($(LOCAL_PAGE_ALIGN_JNI_SHARED_LIBRARIES),true)
$(uncompress-shared-libs)
endif
$(align-package)
###############################