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 38$(foreach pair,$(PRODUCT_BOOT_JARS), \ 39 $(if $(filter $(LOCAL_MODULE),$(call word-colon,2,$(pair))), \ 40 $(call pretty-error,Modules in PRODUCT_BOOT_JARS must be defined in Android.bp files))) 41 42ALL_MODULES.$(my_register_name).CLASSES_JAR := $(common_classes_jar) 43 44####################################### 45# defines built_odex along with rule to install odex 46my_manifest_or_apk := $(my_prebuilt_src_file) 47include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk 48my_manifest_or_apk := 49####################################### 50$(built_module) : $(my_prebuilt_src_file) 51 $(call copy-file-to-target) 52 53else # ! prebuilt_module_is_dex_javalib 54$(built_module) : $(my_prebuilt_src_file) 55 $(transform-prebuilt-to-target) 56endif # ! prebuilt_module_is_dex_javalib 57 58my_src_jar := $(my_prebuilt_src_file) 59 60ifdef LOCAL_IS_HOST_MODULE 61# for host java libraries deps should be in the common dir, so we make a copy in 62# the common dir. 63common_classes_jar := $(intermediates.COMMON)/classes.jar 64common_header_jar := $(intermediates.COMMON)/classes-header.jar 65 66$(common_classes_jar): PRIVATE_MODULE := $(LOCAL_MODULE) 67$(common_classes_jar): PRIVATE_PREFIX := $(my_prefix) 68 69$(common_classes_jar) : $(my_src_jar) 70 $(transform-prebuilt-to-target) 71 72ifneq ($(TURBINE_ENABLED),false) 73$(common_header_jar) : $(my_src_jar) 74 $(transform-prebuilt-to-target) 75endif 76 77else # !LOCAL_IS_HOST_MODULE 78# for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir, 79# while the deps should be in the common dir, so we make a copy in the common dir. 80common_classes_jar := $(intermediates.COMMON)/classes.jar 81common_header_jar := $(intermediates.COMMON)/classes-header.jar 82common_classes_pre_proguard_jar := $(intermediates.COMMON)/classes-pre-proguard.jar 83common_javalib_jar := $(intermediates.COMMON)/javalib.jar 84 85$(common_classes_jar) $(common_classes_pre_proguard_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE) 86$(common_classes_jar) $(common_classes_pre_proguard_jar) $(common_javalib_jar): PRIVATE_PREFIX := $(my_prefix) 87 88ifeq ($(LOCAL_SDK_VERSION),system_current) 89my_link_type := java:system 90else ifneq (,$(call has-system-sdk-version,$(LOCAL_SDK_VERSION))) 91my_link_type := java:system 92else ifeq ($(LOCAL_SDK_VERSION),core_current) 93my_link_type := java:core 94else ifneq ($(LOCAL_SDK_VERSION),) 95my_link_type := java:sdk 96else 97my_link_type := java:platform 98endif 99 100# TODO: check dependencies of prebuilt files 101my_link_deps := 102 103my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) 104my_common := COMMON 105include $(BUILD_SYSTEM)/link_type.mk 106 107ifeq ($(prebuilt_module_is_dex_javalib),true) 108# For prebuilt shared Java library we don't have classes.jar. 109$(common_javalib_jar) : $(my_src_jar) 110 $(transform-prebuilt-to-target) 111 112else # ! prebuilt_module_is_dex_javalib 113 114my_src_aar := $(filter %.aar, $(my_prebuilt_src_file)) 115ifneq ($(my_src_aar),) 116# This is .aar file, archive of classes.jar and Android resources. 117 118# run Jetifier if needed 119LOCAL_JETIFIER_INPUT_FILE := $(my_src_aar) 120include $(BUILD_SYSTEM)/jetifier.mk 121my_src_aar := $(LOCAL_JETIFIER_OUTPUT_FILE) 122 123my_src_jar := $(intermediates.COMMON)/aar/classes.jar 124my_src_proguard_options := $(intermediates.COMMON)/aar/proguard.txt 125my_src_android_manifest := $(intermediates.COMMON)/aar/AndroidManifest.xml 126 127$(my_src_jar) : .KATI_IMPLICIT_OUTPUTS := $(my_src_proguard_options) 128$(my_src_jar) : .KATI_IMPLICIT_OUTPUTS += $(my_src_android_manifest) 129$(my_src_jar) : $(my_src_aar) 130 $(hide) rm -rf $(dir $@) && mkdir -p $(dir $@) $(dir $@)/res 131 $(hide) unzip -qoDD -d $(dir $@) $< 132 # Make sure the proguard and AndroidManifest.xml files exist 133 $(hide) touch $(dir $@)/proguard.txt 134 $(hide) touch $(dir $@)/AndroidManifest.xml 135 136my_prebuilt_android_manifest := $(intermediates.COMMON)/manifest/AndroidManifest.xml 137$(eval $(call copy-one-file,$(my_src_android_manifest),$(my_prebuilt_android_manifest))) 138$(call add-dependency,$(LOCAL_BUILT_MODULE),$(my_prebuilt_android_manifest)) 139 140else 141 142# run Jetifier if needed 143LOCAL_JETIFIER_INPUT_FILE := $(my_src_jar) 144include $(BUILD_SYSTEM)/jetifier.mk 145my_src_jar := $(LOCAL_JETIFIER_OUTPUT_FILE) 146 147endif 148 149$(common_classes_jar) : $(my_src_jar) 150 $(transform-prebuilt-to-target) 151 152ifneq ($(TURBINE_ENABLED),false) 153$(common_header_jar) : $(my_src_jar) 154 $(transform-prebuilt-to-target) 155endif 156 157$(common_classes_pre_proguard_jar) : $(my_src_jar) 158 $(transform-prebuilt-to-target) 159 160$(common_javalib_jar) : $(common_classes_jar) 161 $(transform-prebuilt-to-target) 162 163include $(BUILD_SYSTEM)/force_aapt2.mk 164 165ifneq ($(my_src_aar),) 166 167$(intermediates.COMMON)/export_proguard_flags : $(my_src_proguard_options) 168 $(transform-prebuilt-to-target) 169 170LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION)) 171ifeq ($(LOCAL_SDK_RES_VERSION),) 172 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION) 173endif 174 175framework_res_package_export := 176# Please refer to package.mk 177ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 178ifneq ($(filter-out current system_current test_current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_USE_PREBUILT_SDKS),$(filter current system_current test_current,$(LOCAL_SDK_RES_VERSION))),) 179framework_res_package_export := \ 180 $(call resolve-prebuilt-sdk-jar-path,$(LOCAL_SDK_RES_VERSION)) 181else 182framework_res_package_export := \ 183 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk 184endif 185endif 186 187my_res_package := $(intermediates.COMMON)/package-res.apk 188 189# We needed only very few PRIVATE variables and aapt2.mk input variables. Reset the unnecessary ones. 190$(my_res_package): PRIVATE_AAPT2_CFLAGS := 191$(my_res_package): PRIVATE_AAPT_FLAGS := --static-lib --no-static-lib-packages --auto-add-overlay 192$(my_res_package): PRIVATE_ANDROID_MANIFEST := $(my_src_android_manifest) 193$(my_res_package): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export) 194$(my_res_package): PRIVATE_SOURCE_INTERMEDIATES_DIR := 195$(my_res_package): PRIVATE_PROGUARD_OPTIONS_FILE := 196$(my_res_package): PRIVATE_DEFAULT_APP_TARGET_SDK := 197$(my_res_package): PRIVATE_DEFAULT_APP_TARGET_SDK := 198$(my_res_package): PRIVATE_PRODUCT_AAPT_CONFIG := 199$(my_res_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := 200$(my_res_package): PRIVATE_TARGET_AAPT_CHARACTERISTICS := 201$(my_res_package) : $(framework_res_package_export) 202$(my_res_package) : $(my_src_android_manifest) 203 204full_android_manifest := 205my_res_resources := 206my_overlay_resources := 207my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res 208R_file_stamp := 209proguard_options_file := 210my_generated_res_dirs := $(intermediates.COMMON)/aar/res 211my_generated_res_dirs_deps := $(my_src_jar) 212include $(BUILD_SYSTEM)/aapt2.mk 213 214# Make sure my_res_package is created when you run mm/mmm. 215$(built_module) : $(my_res_package) 216endif # $(my_src_aar) 217 218# make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE) 219$(built_module) : $(common_javalib_jar) 220 221my_exported_sdk_libs_file := $(intermediates.COMMON)/exported-sdk-libs 222$(my_exported_sdk_libs_file): PRIVATE_EXPORTED_SDK_LIBS := $(LOCAL_EXPORT_SDK_LIBRARIES) 223$(my_exported_sdk_libs_file): 224 @echo "Export SDK libs $@" 225 $(hide) mkdir -p $(dir $@) && rm -f $@ 226 $(if $(PRIVATE_EXPORTED_SDK_LIBS),\ 227 $(hide) echo $(PRIVATE_EXPORTED_SDK_LIBS) | tr ' ' '\n' > $@,\ 228 $(hide) touch $@) 229 230endif # ! prebuilt_module_is_dex_javalib 231endif # LOCAL_IS_HOST_MODULE is not set 232