diff options
author | Ying Wang <wangying@google.com> | 2014-04-17 13:38:04 -0700 |
---|---|---|
committer | Ying Wang <wangying@google.com> | 2014-04-18 10:38:53 -0700 |
commit | 96bcad49f4c1d33f183dc9ad04eec3a4b8ab0b5e (patch) | |
tree | 050ad223c59c30eb1a6b5163f01f84c131df427c | |
parent | a376dd8b02adcf0c6dc1f584c3a28a97dd97bdd6 (diff) | |
download | build-96bcad49f4c1d33f183dc9ad04eec3a4b8ab0b5e.zip build-96bcad49f4c1d33f183dc9ad04eec3a4b8ab0b5e.tar.gz build-96bcad49f4c1d33f183dc9ad04eec3a4b8ab0b5e.tar.bz2 |
Update rules to install JNI libraries.
Previously we have to use LOCAL_REQUIRED_MODULES to install jni
libraries for an apk in bundled build.
With this change, we'll use LOCAL_JNI_SHARED_LIBRARIES alone to
install jni shared libraries.
The new rules are:
- If we are doing unbundled build, or the apk isn't going to be
installed to system partitions, we'll embed the jni libs in the
built apk.
- Otherwise, the jni libraries will be installed to the system
lib path, and symlinks created in the app specific lib path.
Change-Id: Id6bd5301eb632bda3593664acee580f0d8b1d5d4
-rw-r--r-- | core/install_jni_libs.mk | 85 | ||||
-rw-r--r-- | core/package_internal.mk | 45 | ||||
-rw-r--r-- | core/prebuilt_internal.mk | 3 |
3 files changed, 89 insertions, 44 deletions
diff --git a/core/install_jni_libs.mk b/core/install_jni_libs.mk new file mode 100644 index 0000000..464a2a2 --- /dev/null +++ b/core/install_jni_libs.mk @@ -0,0 +1,85 @@ +# Decides how to install the jni libraries needed by an apk. +# Input variables: +# LOCAL_JNI_SHARED_LIBRARIES +# LOCAL_INSTALLED_MODULE +# rs_compatibility_jni_libs (from java.mk) +# my_module_path (from base_rules.mk) +# partition_tag (from base_rules.mk) +# +# Output variables: +# jni_shared_libraries, jni_shared_libraries_abi, if we are going to embed the libraries into the apk. +# + +jni_shared_libraries := \ + $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES)/, \ + $(addsuffix .so, \ + $(LOCAL_JNI_SHARED_LIBRARIES))) + +# Include RS dynamically-generated libraries as well +# Keep this ifneq, as the += otherwise adds spaces that need to be stripped. +ifneq ($(rs_compatibility_jni_libs),) +jni_shared_libraries += $(rs_compatibility_jni_libs) +endif + +my_embed_jni := +ifneq ($(TARGET_BUILD_APPS),) +my_embed_jni := true +endif +ifneq ($(filter tests samples, $(LOCAL_MODULE_TAGS)),) +my_embed_jni := true +endif +ifeq ($(filter $(TARGET_OUT)/% $(TARGET_OUT_VENDOR)/% $(TARGET_OUT_OEM)/%, $(my_module_path)),) +# If this app isn't to be installed to system partitions. +my_embed_jni := true +endif + +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. +ifneq ($(filter $(LOCAL_NDK_STL_VARIANT), stlport_shared c++_shared),) +ifndef LOCAL_SDK_VERSION +$(error LOCAL_SDK_VERSION must be defined with LOCAL_NDK_STL_VARIANT, \ + LOCAL_PACKAGE_NAME=$(LOCAL_PACKAGE_NAME)) +endif +endif +ifeq (stlport_shared,$(LOCAL_NDK_STL_VARIANT)) +jni_shared_libraries += \ + $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources/cxx-stl/stlport/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/libstlport_shared.so +else ifeq (c++_shared,$(LOCAL_NDK_STL_VARIANT)) +jni_shared_libraries += \ + $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources/cxx-stl/llvm-libc++/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/libc++_shared.so +endif + +# Set the abi directory used by the local JNI shared libraries. +# (Doesn't change how the local shared libraries are compiled, just +# sets where they are stored in the apk.) +ifeq ($(LOCAL_JNI_SHARED_LIBRARIES_ABI),) + jni_shared_libraries_abi := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI) +else + jni_shared_libraries_abi := $(LOCAL_JNI_SHARED_LIBRARIES_ABI) +endif + +else # not my_embed_jni + +jni_shared_libraries := $(strip $(jni_shared_libraries)) +ifneq ($(jni_shared_libraries),) +# The jni libaries will be installed to the system.img. +my_jni_filenames := $(notdir $(jni_shared_libraries)) +# Make sure the JNI libraries get installed +$(LOCAL_INSTALLED_MODULE) : | $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET$(partition_tag)_OUT_SHARED_LIBRARIES)/, $(my_jni_filenames)) + +# Create symlink in the app specific lib path +ifdef LOCAL_POST_INSTALL_CMD +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 # my_embed_jni diff --git a/core/package_internal.mk b/core/package_internal.mk index 6e7e75c..598c065 100644 --- a/core/package_internal.mk +++ b/core/package_internal.mk @@ -307,50 +307,7 @@ $(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex) $(LOCAL_BUILT_MODULE): $(built_dex) endif # full_classes_jar - -# Get the list of jni libraries to be included in the apk file. - -so_suffix := $($(my_prefix)SHLIB_SUFFIX) - -jni_shared_libraries := \ - $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \ - $(addsuffix $(so_suffix), \ - $(LOCAL_JNI_SHARED_LIBRARIES))) - -# Include RS dynamically-generated libraries as well -# Keep this ifneq, as the += otherwise adds spaces that need to be stripped. -ifneq ($(rs_compatibility_jni_libs),) -jni_shared_libraries += $(rs_compatibility_jni_libs) -endif - -# App explicitly requires the prebuilt NDK libstlport_shared.so. -# libstlport_shared.so should never go to the system image. -# Instead it should be packaged into the apk. -ifneq ($(filter $(LOCAL_NDK_STL_VARIANT), stlport_shared c++_shared),) -ifndef LOCAL_SDK_VERSION -$(error LOCAL_SDK_VERSION has to be defined together with LOCAL_NDK_STL_VARIANT, \ - LOCAL_PACKAGE_NAME=$(LOCAL_PACKAGE_NAME)) -endif -endif -ifeq (stlport_shared,$(LOCAL_NDK_STL_VARIANT)) -jni_shared_libraries += \ - $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources/cxx-stl/stlport/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/libstlport_shared.so -else -ifeq (c++_shared,$(LOCAL_NDK_STL_VARIANT)) -jni_shared_libraries += \ - $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources/cxx-stl/llvm-libc++/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/libc++_shared.so -endif -endif - -# Set the abi directory used by the local JNI shared libraries. -# (Doesn't change how the local shared libraries are compiled, just -# sets where they are stored in the apk.) - -ifeq ($(LOCAL_JNI_SHARED_LIBRARIES_ABI),) - jni_shared_libraries_abi := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI) -else - jni_shared_libraries_abi := $(LOCAL_JNI_SHARED_LIBRARIES_ABI) -endif +include $(BUILD_SYSTEM)/install_jni_libs.mk # Pick a key to sign the package with. If this package hasn't specified # an explicit certificate, use the default. diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk index 2b515cf..985b6f3 100644 --- a/core/prebuilt_internal.mk +++ b/core/prebuilt_internal.mk @@ -108,6 +108,9 @@ endif # LOCAL_STRIP_MODULE not true ifeq ($(LOCAL_MODULE_CLASS),APPS) PACKAGES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES)) +rs_compatibility_jni_libs := +include $(BUILD_SYSTEM)/install_jni_libs.mk + ifeq ($(LOCAL_CERTIFICATE),EXTERNAL) # The magic string "EXTERNAL" means this package will be signed with # the default dev key throughout the build process, but we expect |