summaryrefslogtreecommitdiffstats
path: root/core/install_jni_libs.mk
diff options
context:
space:
mode:
authorYing Wang <wangying@google.com>2014-04-18 20:13:41 -0700
committerYing Wang <wangying@google.com>2014-05-20 18:02:17 -0700
commit7cf9f28b5f064f309a5023eb73234cecb5cf3de9 (patch)
tree006157be6369358584b57c69c9099dfc1d35930b /core/install_jni_libs.mk
parent0dbcff9599be1f999df467b7d17b4f2785a8452a (diff)
downloadbuild-7cf9f28b5f064f309a5023eb73234cecb5cf3de9.zip
build-7cf9f28b5f064f309a5023eb73234cecb5cf3de9.tar.gz
build-7cf9f28b5f064f309a5023eb73234cecb5cf3de9.tar.bz2
Support to extract JNI libs from prebuilt APK
Use LOCAL_PREBUILT_JNI_LIBS to install prebuilt JNI libraries extracted from the prebuilt apk, or prebuilts as source, to the app specific lib path. LOCAL_PREBUILT_JNI_LIBS accepts 2 kinds of files: - Files like @path/to/libfoo.so (path inside the apk) are JNI libs extracted from the prebuilt apk. In this case, all embedded JNI libs inside the prebuilt apk are stripped. - Files like path/to/libfoo.so (path relative to LOCAL_PATH) are prebuilts in the source tree. Those prebuilt JNI libs are not defined as modules in the build system, so this works around possible module name conflict. Bug: 13170859 Change-Id: I91bb844cc11b3621a85733bc7e8910f168957ef0
Diffstat (limited to 'core/install_jni_libs.mk')
-rw-r--r--core/install_jni_libs.mk42
1 files changed, 39 insertions, 3 deletions
diff --git a/core/install_jni_libs.mk b/core/install_jni_libs.mk
index 464a2a2..b9e70b1 100644
--- a/core/install_jni_libs.mk
+++ b/core/install_jni_libs.mk
@@ -5,9 +5,11 @@
# rs_compatibility_jni_libs (from java.mk)
# my_module_path (from base_rules.mk)
# partition_tag (from base_rules.mk)
+# my_prebuilt_src_file (from prebuilt_internal.mk)
#
# Output variables:
-# jni_shared_libraries, jni_shared_libraries_abi, if we are going to embed the libraries into the apk.
+# jni_shared_libraries, jni_shared_libraries_abi, if we are going to embed the libraries into the apk;
+# my_extracted_jni_libs, if we extract jni libs from prebuilt apk.
#
jni_shared_libraries := \
@@ -33,6 +35,10 @@ ifeq ($(filter $(TARGET_OUT)/% $(TARGET_OUT_VENDOR)/% $(TARGET_OUT_OEM)/%, $(my_
my_embed_jni := true
endif
+# App-specific lib path.
+my_app_lib_path := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET$(partition_tag)_OUT_SHARED_LIBRARIES)/$(basename $(LOCAL_INSTALLED_MODULE_STEM))
+my_extracted_jni_libs :=
+
ifdef my_embed_jni
# App explicitly requires the prebuilt NDK stl shared libraies.
# The NDK stl shared libraries should never go to the system image.
@@ -74,12 +80,42 @@ my_leading_separator := ;
else
my_leading_separator :=
endif
-my_app_lib_path := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET$(partition_tag)_OUT_SHARED_LIBRARIES)/$(basename $(LOCAL_INSTALLED_MODULE_STEM))
$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD += \
$(my_leading_separator)mkdir -p $(my_app_lib_path) \
$(foreach lib, $(my_jni_filenames), ;ln -sf ../$(lib) $(my_app_lib_path)/$(lib))
# Clear jni_shared_libraries to not embed it into the apk.
jni_shared_libraries :=
-endif # $(jni_shared_libraries) not empty
+endif # $(jni_shared_libraries) not empty
endif # my_embed_jni
+
+ifdef LOCAL_PREBUILT_JNI_LIBS
+# 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_extracted_jni_libs := $(patsubst @%,%, \
+ $(filter @%, $(LOCAL_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
+# 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
+
+my_prebulit_jni_libs := $(addprefix $(LOCAL_PATH)/, \
+ $(filter-out @%, $(LOCAL_PREBUILT_JNI_LIBS)))
+ifdef my_prebulit_jni_libs
+$(foreach lib, $(my_prebulit_jni_libs), \
+ $(eval $(call copy-one-file, $(lib), $(my_app_lib_path)/$(notdir $(lib)))))
+
+$(LOCAL_INSTALLED_MODULE) : | $(addprefix $(my_app_lib_path)/, $(notdir $(my_prebulit_jni_libs)))
+endif
+endif # LOCAL_PREBULT_JNI_LIBS