1# 2# Copyright (C) 2008 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# Standard rules for building a "static" java library. 18# Static java libraries are not installed, nor listed on any 19# classpaths. They can, however, be included wholesale in 20# other java modules. 21 22$(call record-module-type,STATIC_JAVA_LIBRARY) 23LOCAL_UNINSTALLABLE_MODULE := true 24LOCAL_IS_STATIC_JAVA_LIBRARY := true 25LOCAL_MODULE_CLASS := JAVA_LIBRARIES 26 27intermediates.COMMON := $(call local-intermediates-dir,COMMON) 28 29my_res_package := 30 31# Process Support Library dependencies. 32include $(BUILD_SYSTEM)/support_libraries.mk 33 34include $(BUILD_SYSTEM)/force_aapt2.mk 35 36# Hack to build static Java library with Android resource 37# See bug 5714516 38all_resources := 39need_compile_res := 40# A static Java library needs to explicily set LOCAL_RESOURCE_DIR. 41ifdef LOCAL_RESOURCE_DIR 42need_compile_res := true 43LOCAL_RESOURCE_DIR := $(foreach d,$(LOCAL_RESOURCE_DIR),$(call clean-path,$(d))) 44endif 45ifneq ($(strip $(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)),) 46need_compile_res := true 47endif 48 49ifeq ($(need_compile_res),true) 50all_resources := $(strip \ 51 $(foreach dir, $(LOCAL_RESOURCE_DIR), \ 52 $(addprefix $(dir)/, \ 53 $(patsubst res/%,%, \ 54 $(call find-subdir-assets,$(dir)) \ 55 ) \ 56 ) \ 57 )) 58 59# By default we should remove the R/Manifest classes from a static Java library, 60# because they will be regenerated in the app that uses it. 61# But if the static Java library will be used by a library, then we may need to 62# keep the generated classes with "LOCAL_JAR_EXCLUDE_FILES := none". 63ifndef LOCAL_JAR_EXCLUDE_FILES 64LOCAL_JAR_EXCLUDE_FILES := $(ANDROID_RESOURCE_GENERATED_CLASSES) 65endif 66ifeq (none,$(LOCAL_JAR_EXCLUDE_FILES)) 67LOCAL_JAR_EXCLUDE_FILES := 68endif 69 70proguard_options_file := 71 72ifneq ($(filter custom,$(LOCAL_PROGUARD_ENABLED)),custom) 73 proguard_options_file := $(intermediates.COMMON)/proguard_options 74endif 75 76LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS) 77LOCAL_PROGUARD_FLAGS_DEPS += $(proguard_options_file) 78 79R_file_stamp := $(intermediates.COMMON)/src/R.stamp 80LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp) 81 82ifneq ($(strip $(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)),) 83 # If we are using static android libraries, every source file becomes an overlay. 84 # This is to emulate old AAPT behavior which simulated library support. 85 my_res_resources := 86 my_overlay_resources := $(all_resources) 87else 88 # Otherwise, for a library we treat all the resource equal with no overlay. 89 my_res_resources := $(all_resources) 90 my_overlay_resources := 91endif 92# For libraries put everything in the COMMON intermediate directory. 93my_res_package := $(intermediates.COMMON)/package-res.apk 94 95LOCAL_INTERMEDIATE_TARGETS += $(my_res_package) 96 97endif # need_compile_res 98 99all_res_assets := $(all_resources) 100 101include $(BUILD_SYSTEM)/java_renderscript.mk 102 103ifeq (true,$(need_compile_res)) 104# work around missing manifests by creating a default one 105ifeq (,$(strip $(LOCAL_MANIFEST_FILE)$(LOCAL_FULL_MANIFEST_FILE))) 106 ifeq (,$(wildcard $(LOCAL_PATH)/AndroidManifest.xml)) 107 LOCAL_FULL_MANIFEST_FILE := $(call local-intermediates-dir,COMMON)/DefaultManifest.xml 108 $(call create-default-manifest-file,$(LOCAL_FULL_MANIFEST_FILE),$(call module-min-sdk-version)) 109 endif 110endif 111include $(BUILD_SYSTEM)/android_manifest.mk 112 113LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION)) 114ifeq ($(LOCAL_SDK_RES_VERSION),) 115 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION) 116endif 117 118framework_res_package_export := 119# Please refer to package.mk 120ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 121ifneq ($(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))),) 122framework_res_package_export := \ 123 $(call resolve-prebuilt-sdk-jar-path,$(LOCAL_SDK_RES_VERSION)) 124else 125framework_res_package_export := \ 126 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk 127endif 128endif 129 130import_proguard_flag_files := $(strip $(foreach l,$(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES),\ 131 $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/export_proguard_flags)) 132$(intermediates.COMMON)/export_proguard_flags: $(import_proguard_flag_files) $(addprefix $(LOCAL_PATH)/,$(LOCAL_EXPORT_PROGUARD_FLAG_FILES)) 133 @echo "Export proguard flags: $@" 134 rm -f $@ 135 touch $@ 136 for f in $+; do \ 137 echo -e "\n# including $$f" >>$@; \ 138 cat $$f >>$@; \ 139 done 140import_proguard_flag_files := 141 142include $(BUILD_SYSTEM)/aapt_flags.mk 143 144$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) 145$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_AAPT_CHARACTERISTICS := $(TARGET_AAPT_CHARACTERISTICS) 146$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_PACKAGE_NAME := $(LOCAL_MANIFEST_PACKAGE_NAME) 147$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_INSTRUMENTATION_FOR := $(LOCAL_MANIFEST_INSTRUMENTATION_FOR) 148 149# add --non-constant-id to prevent inlining constants. 150# AAR needs text symbol file R.txt. 151$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --static-lib --output-text-symbols $(intermediates.COMMON)/R.txt 152ifndef LOCAL_AAPT_NAMESPACES 153 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS += --no-static-lib-packages 154endif 155$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PRODUCT_AAPT_CONFIG := 156$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := 157$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_AAPT_CHARACTERISTICS := 158 159$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest) 160$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_PUBLICS_OUTPUT := $(intermediates.COMMON)/public_resources.xml 161$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR) 162$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export) 163 164$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR := 165$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file) 166$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_PACKAGE_NAME := 167$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_INSTRUMENTATION_FOR := 168 169# One more level with name res so we can zip up the flat resources that can be linked by apps. 170my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res/res 171ifneq (,$(filter-out current,$(renderscript_target_api))) 172 ifneq ($(call math_gt_or_eq,$(renderscript_target_api),21),true) 173 my_generated_res_zips := $(rs_generated_res_zip) 174 endif # renderscript_target_api < 21 175endif # renderscript_target_api is set 176include $(BUILD_SYSTEM)/aapt2.mk 177$(my_res_package) : $(framework_res_package_export) 178$(my_res_package): .KATI_IMPLICIT_OUTPUTS += $(intermediates.COMMON)/R.txt 179 180endif # need_compile_res 181 182include $(BUILD_SYSTEM)/java_library.mk 183 184ifeq (true,$(need_compile_res)) 185 186$(LOCAL_BUILT_MODULE): $(R_file_stamp) 187$(java_source_list_file): $(R_file_stamp) 188$(full_classes_compiled_jar): $(R_file_stamp) 189$(full_classes_turbine_jar): $(R_file_stamp) 190 191 192# if we have custom proguarding done use the proguarded classes jar instead of the normal classes jar 193ifeq ($(filter custom,$(LOCAL_PROGUARD_ENABLED)),custom) 194aar_classes_jar = $(full_classes_jar) 195else 196aar_classes_jar = $(full_classes_pre_proguard_jar) 197endif 198 199# Rule to build AAR, archive including classes.jar, resource, etc. 200built_aar := $(intermediates.COMMON)/javalib.aar 201$(built_aar): PRIVATE_MODULE := $(LOCAL_MODULE) 202$(built_aar): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest) 203$(built_aar): PRIVATE_CLASSES_JAR := $(aar_classes_jar) 204$(built_aar): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR) 205$(built_aar): PRIVATE_R_TXT := $(intermediates.COMMON)/R.txt 206$(built_aar): $(JAR_ARGS) 207$(built_aar) : $(aar_classes_jar) $(full_android_manifest) $(intermediates.COMMON)/R.txt 208 @echo "target AAR: $(PRIVATE_MODULE) ($@)" 209 $(hide) rm -rf $(dir $@)aar && mkdir -p $(dir $@)aar/res 210 $(hide) cp $(PRIVATE_ANDROID_MANIFEST) $(dir $@)aar/AndroidManifest.xml 211 $(hide) cp $(PRIVATE_CLASSES_JAR) $(dir $@)aar/classes.jar 212 # Note: Use "cp -n" to honor the resource overlay rules, if multiple res dirs exist. 213 $(hide) $(foreach res,$(PRIVATE_RESOURCE_DIR),cp -Rfn $(res)/* $(dir $@)aar/res;) 214 $(hide) cp $(PRIVATE_R_TXT) $(dir $@)aar/R.txt 215 $(hide) $(JAR) -cMf $@ \ 216 $(call jar-args-sorted-files-in-directory,$(dir $@)aar) 217 218# Register the aar file. 219ALL_MODULES.$(my_register_name).AAR := $(built_aar) 220endif # need_compile_res 221 222# Reset internal variables. 223aar_classes_jar := 224all_res_assets := 225LOCAL_IS_STATIC_JAVA_LIBRARY := 226