1# 2# Copyright (C) 2019 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17############################################################ 18# Internal build rules for JAVA_LIBRARIES prebuilt modules 19############################################################ 20 21ifneq (JAVA_LIBRARIES,$(LOCAL_MODULE_CLASS)) 22$(call pretty-error,java_prebuilt_internal.mk is for JAVA_LIBRARIES modules only) 23endif 24 25include $(BUILD_SYSTEM)/base_rules.mk 26built_module := $(LOCAL_BUILT_MODULE) 27 28ifeq (,$(LOCAL_IS_HOST_MODULE)$(filter true,$(LOCAL_UNINSTALLABLE_MODULE))) 29 prebuilt_module_is_dex_javalib := true 30else 31 prebuilt_module_is_dex_javalib := 32endif 33 34ifeq ($(prebuilt_module_is_dex_javalib),true) 35my_dex_jar := $(my_prebuilt_src_file) 36# This is a target shared library, i.e. a jar with classes.dex. 37 38ifneq ($(filter $(LOCAL_MODULE),$(PRODUCT_BOOT_JARS)),) 39 $(call pretty-error,Modules in PRODUCT_BOOT_JARS must be defined in Android.bp files) 40endif 41 42ALL_MODULES.$(my_register_name).CLASSES_JAR := $(common_classes_jar) 43 44####################################### 45# defines built_odex along with rule to install odex 46include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk 47####################################### 48$(built_module) : $(my_prebuilt_src_file) 49 $(call copy-file-to-target) 50 51else # ! prebuilt_module_is_dex_javalib 52$(built_module) : $(my_prebuilt_src_file) 53 $(transform-prebuilt-to-target) 54endif # ! prebuilt_module_is_dex_javalib 55 56my_src_jar := $(my_prebuilt_src_file) 57 58ifdef LOCAL_IS_HOST_MODULE 59# for host java libraries deps should be in the common dir, so we make a copy in 60# the common dir. 61common_classes_jar := $(intermediates.COMMON)/classes.jar 62common_header_jar := $(intermediates.COMMON)/classes-header.jar 63 64$(common_classes_jar): PRIVATE_MODULE := $(LOCAL_MODULE) 65$(common_classes_jar): PRIVATE_PREFIX := $(my_prefix) 66 67$(common_classes_jar) : $(my_src_jar) 68 $(transform-prebuilt-to-target) 69 70ifneq ($(TURBINE_ENABLED),false) 71$(common_header_jar) : $(my_src_jar) 72 $(transform-prebuilt-to-target) 73endif 74 75else # !LOCAL_IS_HOST_MODULE 76# for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir, 77# while the deps should be in the common dir, so we make a copy in the common dir. 78common_classes_jar := $(intermediates.COMMON)/classes.jar 79common_header_jar := $(intermediates.COMMON)/classes-header.jar 80common_classes_pre_proguard_jar := $(intermediates.COMMON)/classes-pre-proguard.jar 81common_javalib_jar := $(intermediates.COMMON)/javalib.jar 82 83$(common_classes_jar) $(common_classes_pre_proguard_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE) 84$(common_classes_jar) $(common_classes_pre_proguard_jar) $(common_javalib_jar): PRIVATE_PREFIX := $(my_prefix) 85 86ifeq ($(LOCAL_SDK_VERSION),system_current) 87my_link_type := java:system 88else ifneq (,$(call has-system-sdk-version,$(LOCAL_SDK_VERSION))) 89my_link_type := java:system 90else ifeq ($(LOCAL_SDK_VERSION),core_current) 91my_link_type := java:core 92else ifneq ($(LOCAL_SDK_VERSION),) 93my_link_type := java:sdk 94else 95my_link_type := java:platform 96endif 97 98# TODO: check dependencies of prebuilt files 99my_link_deps := 100 101my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) 102my_common := COMMON 103include $(BUILD_SYSTEM)/link_type.mk 104 105ifeq ($(prebuilt_module_is_dex_javalib),true) 106# For prebuilt shared Java library we don't have classes.jar. 107$(common_javalib_jar) : $(my_src_jar) 108 $(transform-prebuilt-to-target) 109 110else # ! prebuilt_module_is_dex_javalib 111 112my_src_aar := $(filter %.aar, $(my_prebuilt_src_file)) 113ifneq ($(my_src_aar),) 114# This is .aar file, archive of classes.jar and Android resources. 115 116# run Jetifier if needed 117LOCAL_JETIFIER_INPUT_FILE := $(my_src_aar) 118include $(BUILD_SYSTEM)/jetifier.mk 119my_src_aar := $(LOCAL_JETIFIER_OUTPUT_FILE) 120 121my_src_jar := $(intermediates.COMMON)/aar/classes.jar 122my_src_proguard_options := $(intermediates.COMMON)/aar/proguard.txt 123my_src_android_manifest := $(intermediates.COMMON)/aar/AndroidManifest.xml 124 125$(my_src_jar) : .KATI_IMPLICIT_OUTPUTS := $(my_src_proguard_options) 126$(my_src_jar) : .KATI_IMPLICIT_OUTPUTS += $(my_src_android_manifest) 127$(my_src_jar) : $(my_src_aar) 128 $(hide) rm -rf $(dir $@) && mkdir -p $(dir $@) $(dir $@)/res 129 $(hide) unzip -qoDD -d $(dir $@) $< 130 # Make sure the proguard and AndroidManifest.xml files exist 131 $(hide) touch $(dir $@)/proguard.txt 132 $(hide) touch $(dir $@)/AndroidManifest.xml 133 134my_prebuilt_android_manifest := $(intermediates.COMMON)/manifest/AndroidManifest.xml 135$(eval $(call copy-one-file,$(my_src_android_manifest),$(my_prebuilt_android_manifest))) 136$(call add-dependency,$(LOCAL_BUILT_MODULE),$(my_prebuilt_android_manifest)) 137 138else 139 140# run Jetifier if needed 141LOCAL_JETIFIER_INPUT_FILE := $(my_src_jar) 142include $(BUILD_SYSTEM)/jetifier.mk 143my_src_jar := $(LOCAL_JETIFIER_OUTPUT_FILE) 144 145endif 146 147$(common_classes_jar) : $(my_src_jar) 148 $(transform-prebuilt-to-target) 149 150ifneq ($(TURBINE_ENABLED),false) 151$(common_header_jar) : $(my_src_jar) 152 $(transform-prebuilt-to-target) 153endif 154 155$(common_classes_pre_proguard_jar) : $(my_src_jar) 156 $(transform-prebuilt-to-target) 157 158$(common_javalib_jar) : $(common_classes_jar) 159 $(transform-prebuilt-to-target) 160 161include $(BUILD_SYSTEM)/force_aapt2.mk 162 163ifneq ($(my_src_aar),) 164 165$(intermediates.COMMON)/export_proguard_flags : $(my_src_proguard_options) 166 $(transform-prebuilt-to-target) 167 168LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION)) 169ifeq ($(LOCAL_SDK_RES_VERSION),) 170 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION) 171endif 172 173framework_res_package_export := 174# Please refer to package.mk 175ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 176ifneq ($(filter-out current system_current test_current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current test_current,$(LOCAL_SDK_RES_VERSION))),) 177framework_res_package_export := \ 178 $(call resolve-prebuilt-sdk-jar-path,$(LOCAL_SDK_RES_VERSION)) 179else 180framework_res_package_export := \ 181 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk 182endif 183endif 184 185my_res_package := $(intermediates.COMMON)/package-res.apk 186 187# We needed only very few PRIVATE variables and aapt2.mk input variables. Reset the unnecessary ones. 188$(my_res_package): PRIVATE_AAPT2_CFLAGS := 189$(my_res_package): PRIVATE_AAPT_FLAGS := --static-lib --no-static-lib-packages --auto-add-overlay 190$(my_res_package): PRIVATE_ANDROID_MANIFEST := $(my_src_android_manifest) 191$(my_res_package): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export) 192$(my_res_package): PRIVATE_SOURCE_INTERMEDIATES_DIR := 193$(my_res_package): PRIVATE_PROGUARD_OPTIONS_FILE := 194$(my_res_package): PRIVATE_DEFAULT_APP_TARGET_SDK := 195$(my_res_package): PRIVATE_DEFAULT_APP_TARGET_SDK := 196$(my_res_package): PRIVATE_PRODUCT_AAPT_CONFIG := 197$(my_res_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := 198$(my_res_package): PRIVATE_TARGET_AAPT_CHARACTERISTICS := 199$(my_res_package) : $(framework_res_package_export) 200$(my_res_package) : $(my_src_android_manifest) 201 202full_android_manifest := 203my_res_resources := 204my_overlay_resources := 205my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res 206R_file_stamp := 207proguard_options_file := 208my_generated_res_dirs := $(intermediates.COMMON)/aar/res 209my_generated_res_dirs_deps := $(my_src_jar) 210include $(BUILD_SYSTEM)/aapt2.mk 211 212# Make sure my_res_package is created when you run mm/mmm. 213$(built_module) : $(my_res_package) 214endif # $(my_src_aar) 215 216# make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE) 217$(built_module) : $(common_javalib_jar) 218 219my_exported_sdk_libs_file := $(intermediates.COMMON)/exported-sdk-libs 220$(my_exported_sdk_libs_file): PRIVATE_EXPORTED_SDK_LIBS := $(LOCAL_EXPORT_SDK_LIBRARIES) 221$(my_exported_sdk_libs_file): 222 @echo "Export SDK libs $@" 223 $(hide) mkdir -p $(dir $@) && rm -f $@ 224 $(if $(PRIVATE_EXPORTED_SDK_LIBS),\ 225 $(hide) echo $(PRIVATE_EXPORTED_SDK_LIBS) | tr ' ' '\n' > $@,\ 226 $(hide) touch $@) 227 228endif # ! prebuilt_module_is_dex_javalib 229endif # LOCAL_IS_HOST_MODULE is not set 230