1# Install jni libraries for one arch. 2# Input variables: 3# my_2nd_arch_prefix: indicate if this is for TARGET_2ND_ARCH. 4# my_embed_jni: indicate if we want to embed the jni libs in the apk. 5# my_prebuilt_jni_libs 6# my_installed_module_stem (from configure_module_stem.mk) 7# partition_tag (from base_rules.mk) 8# partition_lib_pairs 9# my_prebuilt_src_file (from prebuilt_internal.mk) 10# 11# Output variables: 12# my_jni_shared_libraries, my_jni_shared_libraries_abi, if we are going to embed the libraries into the apk; 13# my_embedded_prebuilt_jni_libs, prebuilt jni libs embedded in prebuilt apk. 14# 15 16my_sdk_variant = $(1) 17ifneq (,$(and $(my_embed_jni),$(LOCAL_SDK_VERSION))) 18 # Soong produces $(lib).so in $(lib).sdk_intermediates so that the library 19 # has the correct name for embedding in an APK. Append .sdk to the name 20 # of the intermediates directory, but not the .so name. 21 my_sdk_variant = $(call use_soong_sdk_libraries,$(1)) 22endif 23 24my_jni_shared_libraries := $(strip \ 25 $(foreach lib,$(LOCAL_JNI_SHARED_LIBRARIES), \ 26 $(call intermediates-dir-for,SHARED_LIBRARIES,$(call my_sdk_variant,$(lib)),,,$(my_2nd_arch_prefix))/$(lib).so)) 27 28 29# App-specific lib path. 30my_app_lib_path := $(dir $(LOCAL_INSTALLED_MODULE))lib/$(TARGET_$(my_2nd_arch_prefix)ARCH) 31my_embedded_prebuilt_jni_libs := 32 33ifdef my_embed_jni 34 # App explicitly requires the prebuilt NDK stl shared libraies. 35 # The NDK stl shared libraries should never go to the system image. 36 ifeq ($(LOCAL_NDK_STL_VARIANT),c++_shared) 37 ifndef LOCAL_SDK_VERSION 38 $(error LOCAL_SDK_VERSION must be defined with LOCAL_NDK_STL_VARIANT, \ 39 LOCAL_PACKAGE_NAME=$(LOCAL_PACKAGE_NAME)) 40 endif 41 my_libcxx_arch := $($(LOCAL_2ND_ARCH_VAR_PREFIX)PREBUILT_LIBCXX_ARCH_DIR) 42 my_jni_shared_libraries += \ 43 $(LLVM_PREBUILTS_BASE)/$(BUILD_OS)-x86/$(LLVM_PREBUILTS_VERSION)/android_libc++/ndk/$(my_libcxx_arch)/lib/libc++_shared.so 44 endif 45 46 # Set the abi directory used by the local JNI shared libraries. 47 # (Doesn't change how the local shared libraries are compiled, just 48 # sets where they are stored in the apk.) 49 ifeq ($(LOCAL_JNI_SHARED_LIBRARIES_ABI),) 50 my_jni_shared_libraries_abi := $(TARGET_$(my_2nd_arch_prefix)CPU_ABI) 51 else 52 my_jni_shared_libraries_abi := $(LOCAL_JNI_SHARED_LIBRARIES_ABI) 53 endif 54 55else ifneq ($(my_jni_shared_libraries),) # not my_embed_jni 56 57 # The jni libaries will be installed to the system.img. 58 my_jni_filenames := $(notdir $(my_jni_shared_libraries)) 59 # Make sure the JNI libraries get installed 60 my_shared_library_path := $(call get_non_asan_path,\ 61 $($(my_2nd_arch_prefix)TARGET_OUT$(partition_tag)_SHARED_LIBRARIES)) 62 63 bit_suffix := $(if $(filter %64,$(TARGET_$(my_2nd_arch_prefix)ARCH)),:64,:32) 64 ALL_MODULES.$(my_register_name).REQUIRED_FROM_TARGET += $(addsuffix $(bit_suffix),$(LOCAL_JNI_SHARED_LIBRARIES)) 65 66 # Create symlink in the app specific lib path 67 # Skip creating this symlink when running the second part of a target sanitization build. 68 ifeq ($(filter address,$(SANITIZE_TARGET)),) 69 my_symlink_target_dir := $(patsubst $(PRODUCT_OUT)%,%,\ 70 $(my_shared_library_path)) 71 72 ifdef partition_lib_pairs 73 # Support cross-partition jni lib dependency for bp modules 74 # API domain check is done in Soong 75 $(foreach pl_pair,$(partition_lib_pairs),\ 76 $(eval lib_name := $(call word-colon, 1, $(pl_pair)))\ 77 $(eval lib_partition := $(call word-colon, 2, $(pl_pair)))\ 78 $(eval shared_library_path := $(call get_non_asan_path,\ 79 $($(my_2nd_arch_prefix)TARGET_OUT$(lib_partition)_SHARED_LIBRARIES)))\ 80 $(call symlink-file,\ 81 $(shared_library_path)/$(lib_name).so,\ 82 $(my_symlink_target_dir)/$(lib_name).so,\ 83 $(my_app_lib_path)/$(lib_name).so)\ 84 $(eval $$(LOCAL_INSTALLED_MODULE) : $$(my_app_lib_path)/$$(lib_name).so)\ 85 $(eval ALL_MODULES.$(my_register_name).INSTALLED += $$(my_app_lib_path)/$$(lib_name).so)) 86 87 else 88 # Cross-partition jni lib dependency currently not supported for mk modules 89 $(foreach lib,$(my_jni_filenames),\ 90 $(call symlink-file, \ 91 $(my_shared_library_path)/$(lib), \ 92 $(my_symlink_target_dir)/$(lib), \ 93 $(my_app_lib_path)/$(lib)) \ 94 $(eval $$(LOCAL_INSTALLED_MODULE) : $$(my_app_lib_path)/$$(lib)) \ 95 $(eval ALL_MODULES.$(my_register_name).INSTALLED += $$(my_app_lib_path)/$$(lib))) 96 endif # partition_lib_pairs 97 endif 98 99 # Clear jni_shared_libraries to not embed it into the apk. 100 my_jni_shared_libraries := 101endif # my_embed_jni 102 103ifdef my_prebuilt_jni_libs 104 # Files like @lib/<abi>/libfoo.so (path inside the apk) are JNI libs embedded prebuilt apk; 105 # Files like path/to/libfoo.so (path relative to LOCAL_PATH) are prebuilts in the source tree. 106 my_embedded_prebuilt_jni_libs := $(patsubst @%,%, \ 107 $(filter @%, $(my_prebuilt_jni_libs))) 108 109 # prebuilt JNI exsiting as separate source files. 110 my_prebuilt_jni_libs := $(addprefix $(LOCAL_PATH)/, \ 111 $(filter-out @%, $(my_prebuilt_jni_libs))) 112 ifdef my_prebuilt_jni_libs 113 ifdef my_embed_jni 114 # Embed my_prebuilt_jni_libs to the apk 115 my_jni_shared_libraries += $(my_prebuilt_jni_libs) 116 else # not my_embed_jni 117 # Install my_prebuilt_jni_libs as separate files. 118 $(foreach lib, $(my_prebuilt_jni_libs), \ 119 $(eval $(call copy-one-file, $(lib), $(my_app_lib_path)/$(notdir $(lib))))) 120 121 my_installed_library := $(addprefix $(my_app_lib_path)/, $(notdir $(my_prebuilt_jni_libs))) 122 $(LOCAL_INSTALLED_MODULE) : $(my_installed_library) 123 124 ALL_MODULES.$(my_register_name).INSTALLED += $(my_installed_library) 125 endif # my_embed_jni 126 endif # inner my_prebuilt_jni_libs 127endif # outer my_prebuilt_jni_libs 128 129# Verify that all included libraries are built against the NDK 130include $(BUILD_SYSTEM)/allowed_ndk_types.mk 131 132ifneq ($(strip $(LOCAL_JNI_SHARED_LIBRARIES)),) 133 ifneq ($(LOCAL_SDK_VERSION),) 134 my_link_type := app:sdk 135 my_warn_types := native:platform $(my_warn_ndk_types) 136 my_allowed_types := $(my_allowed_ndk_types) 137 ifneq (,$(filter true,$(LOCAL_VENDOR_MODULE) $(LOCAL_ODM_MODULE) $(LOCAL_PROPRIETARY_MODULE))) 138 my_allowed_types += native:vendor native:vndk native:platform_vndk 139 else ifeq ($(LOCAL_PRODUCT_MODULE),true) 140 my_allowed_types += native:product native:vndk native:platform_vndk 141 endif 142 else 143 my_link_type := app:platform 144 my_warn_types := $(my_warn_ndk_types) 145 my_allowed_types := $(my_allowed_ndk_types) native:platform native:product native:vendor native:vndk native:vndk_private native:platform_vndk 146 endif 147 148 ifeq ($(SOONG_ANDROID_MK),$(LOCAL_MODULE_MAKEFILE)) 149 # SOONG_SDK_VARIANT_MODULES isn't complete yet while parsing Soong modules, and Soong has 150 # already ensured that apps link against the correct SDK variants, don't check them. 151 else 152 ifneq (,$(LOCAL_SDK_VERSION)) 153 my_link_deps := $(addprefix SHARED_LIBRARIES:,$(call use_soong_sdk_libraries,$(LOCAL_JNI_SHARED_LIBRARIES))) 154 else 155 my_link_deps := $(addprefix SHARED_LIBRARIES:,$(LOCAL_JNI_SHARED_LIBRARIES)) 156 endif 157 endif 158 159 my_common := 160 include $(BUILD_SYSTEM)/link_type.mk 161endif 162