• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_jni_shared_libraries += \
42        $(HISTORICAL_NDK_VERSIONS_ROOT)/$(LOCAL_NDK_VERSION)/sources/cxx-stl/llvm-libc++/libs/$(TARGET_$(my_2nd_arch_prefix)CPU_ABI)/libc++_shared.so
43  endif
44
45  # Set the abi directory used by the local JNI shared libraries.
46  # (Doesn't change how the local shared libraries are compiled, just
47  # sets where they are stored in the apk.)
48  ifeq ($(LOCAL_JNI_SHARED_LIBRARIES_ABI),)
49    my_jni_shared_libraries_abi := $(TARGET_$(my_2nd_arch_prefix)CPU_ABI)
50  else
51    my_jni_shared_libraries_abi := $(LOCAL_JNI_SHARED_LIBRARIES_ABI)
52  endif
53
54else ifneq ($(my_jni_shared_libraries),) # not my_embed_jni
55
56  # The jni libaries will be installed to the system.img.
57  my_jni_filenames := $(notdir $(my_jni_shared_libraries))
58  # Make sure the JNI libraries get installed
59  my_shared_library_path := $(call get_non_asan_path,\
60      $($(my_2nd_arch_prefix)TARGET_OUT$(partition_tag)_SHARED_LIBRARIES))
61
62  bit_suffix := $(if $(filter %64,$(TARGET_$(my_2nd_arch_prefix)ARCH)),:64,:32)
63  ALL_MODULES.$(my_register_name).REQUIRED_FROM_TARGET += $(addsuffix $(bit_suffix),$(LOCAL_JNI_SHARED_LIBRARIES))
64
65  # Create symlink in the app specific lib path
66  # Skip creating this symlink when running the second part of a target sanitization build.
67  ifeq ($(filter address,$(SANITIZE_TARGET)),)
68    my_symlink_target_dir := $(patsubst $(PRODUCT_OUT)%,%,\
69      $(my_shared_library_path))
70
71    ifdef partition_lib_pairs
72      # Support cross-partition jni lib dependency for bp modules
73      # API domain check is done in Soong
74      $(foreach pl_pair,$(partition_lib_pairs),\
75        $(eval lib_name := $(call word-colon, 1, $(pl_pair)))\
76        $(eval lib_partition := $(call word-colon, 2, $(pl_pair)))\
77        $(eval shared_library_path := $(call get_non_asan_path,\
78        $($(my_2nd_arch_prefix)TARGET_OUT$(lib_partition)_SHARED_LIBRARIES)))\
79        $(call symlink-file,\
80          $(shared_library_path)/$(lib_name).so,\
81          $(my_symlink_target_dir)/$(lib_name).so,\
82          $(my_app_lib_path)/$(lib_name).so)\
83        $(eval $$(LOCAL_INSTALLED_MODULE) : $$(my_app_lib_path)/$$(lib_name).so)\
84        $(eval ALL_MODULES.$(my_register_name).INSTALLED += $$(my_app_lib_path)/$$(lib_name).so))
85
86    else
87      # Cross-partition jni lib dependency currently not supported for mk modules
88      $(foreach lib,$(my_jni_filenames),\
89        $(call symlink-file, \
90          $(my_shared_library_path)/$(lib), \
91          $(my_symlink_target_dir)/$(lib), \
92          $(my_app_lib_path)/$(lib)) \
93        $(eval $$(LOCAL_INSTALLED_MODULE) : $$(my_app_lib_path)/$$(lib)) \
94        $(eval ALL_MODULES.$(my_register_name).INSTALLED += $$(my_app_lib_path)/$$(lib)))
95    endif # partition_lib_pairs
96  endif
97
98  # Clear jni_shared_libraries to not embed it into the apk.
99  my_jni_shared_libraries :=
100endif  # my_embed_jni
101
102ifdef my_prebuilt_jni_libs
103  # Files like @lib/<abi>/libfoo.so (path inside the apk) are JNI libs embedded prebuilt apk;
104  # Files like path/to/libfoo.so (path relative to LOCAL_PATH) are prebuilts in the source tree.
105  my_embedded_prebuilt_jni_libs := $(patsubst @%,%, \
106      $(filter @%, $(my_prebuilt_jni_libs)))
107
108  # prebuilt JNI exsiting as separate source files.
109  my_prebuilt_jni_libs := $(addprefix $(LOCAL_PATH)/, \
110      $(filter-out @%, $(my_prebuilt_jni_libs)))
111  ifdef my_prebuilt_jni_libs
112    ifdef my_embed_jni
113      # Embed my_prebuilt_jni_libs to the apk
114      my_jni_shared_libraries += $(my_prebuilt_jni_libs)
115    else # not my_embed_jni
116      # Install my_prebuilt_jni_libs as separate files.
117      $(foreach lib, $(my_prebuilt_jni_libs), \
118          $(eval $(call copy-one-file, $(lib), $(my_app_lib_path)/$(notdir $(lib)))))
119
120      my_installed_library := $(addprefix $(my_app_lib_path)/, $(notdir $(my_prebuilt_jni_libs)))
121      $(LOCAL_INSTALLED_MODULE) : $(my_installed_library)
122
123      ALL_MODULES.$(my_register_name).INSTALLED += $(my_installed_library)
124    endif  # my_embed_jni
125  endif  # inner my_prebuilt_jni_libs
126endif  # outer my_prebuilt_jni_libs
127
128# Verify that all included libraries are built against the NDK
129include $(BUILD_SYSTEM)/allowed_ndk_types.mk
130
131ifneq ($(strip $(LOCAL_JNI_SHARED_LIBRARIES)),)
132  ifneq ($(LOCAL_SDK_VERSION),)
133    my_link_type := app:sdk
134    my_warn_types := native:platform $(my_warn_ndk_types)
135    my_allowed_types := $(my_allowed_ndk_types)
136    ifneq (,$(filter true,$(LOCAL_VENDOR_MODULE) $(LOCAL_ODM_MODULE) $(LOCAL_PROPRIETARY_MODULE)))
137      my_allowed_types += native:vendor native:vndk native:platform_vndk
138    else ifeq ($(LOCAL_PRODUCT_MODULE),true)
139      my_allowed_types += native:product native:vndk native:platform_vndk
140    endif
141  else
142    my_link_type := app:platform
143    my_warn_types := $(my_warn_ndk_types)
144    my_allowed_types := $(my_allowed_ndk_types) native:platform native:product native:vendor native:vndk native:vndk_private native:platform_vndk
145  endif
146
147  ifeq ($(SOONG_ANDROID_MK),$(LOCAL_MODULE_MAKEFILE))
148    # SOONG_SDK_VARIANT_MODULES isn't complete yet while parsing Soong modules, and Soong has
149    # already ensured that apps link against the correct SDK variants, don't check them.
150  else
151    ifneq (,$(LOCAL_SDK_VERSION))
152      my_link_deps := $(addprefix SHARED_LIBRARIES:,$(call use_soong_sdk_libraries,$(LOCAL_JNI_SHARED_LIBRARIES)))
153    else
154      my_link_deps := $(addprefix SHARED_LIBRARIES:,$(LOCAL_JNI_SHARED_LIBRARIES))
155    endif
156  endif
157
158  my_common :=
159  include $(BUILD_SYSTEM)/link_type.mk
160endif
161