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 27################################# 28include $(BUILD_SYSTEM)/configure_local_jack.mk 29################################# 30 31intermediates.COMMON := $(call local-intermediates-dir,COMMON) 32 33my_res_package := 34 35# Hack to build static Java library with Android resource 36# See bug 5714516 37all_resources := 38need_compile_res := 39# A static Java library needs to explicily set LOCAL_RESOURCE_DIR. 40ifdef LOCAL_RESOURCE_DIR 41need_compile_res := true 42endif 43ifdef LOCAL_USE_AAPT2 44ifneq ($(LOCAL_STATIC_ANDROID_LIBRARIES),) 45need_compile_res := true 46endif 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) 77 78ifdef LOCAL_JACK_ENABLED 79ifndef LOCAL_JACK_PROGUARD_FLAGS 80 LOCAL_JACK_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS) 81endif 82LOCAL_JACK_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_JACK_PROGUARD_FLAGS) 83endif # LOCAL_JACK_ENABLED 84 85R_file_stamp := $(intermediates.COMMON)/src/R.stamp 86LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp) 87 88ifdef LOCAL_USE_AAPT2 89# For library we treat all the resource equal with no overlay. 90my_res_resources := $(all_resources) 91my_overlay_resources := 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) 96endif # LOCAL_USE_AAPT2 97endif # LOCAL_RESOURCE_DIR 98 99all_res_assets := $(all_resources) 100 101include $(BUILD_SYSTEM)/java_library.mk 102 103ifeq (true,$(need_compile_res)) 104include $(BUILD_SYSTEM)/android_manifest.mk 105 106LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION)) 107ifeq ($(LOCAL_SDK_RES_VERSION),) 108 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION) 109endif 110 111framework_res_package_export := 112framework_res_package_export_deps := 113# Please refer to package.mk 114ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 115ifneq ($(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))),) 116framework_res_package_export := \ 117 $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar 118framework_res_package_export_deps := $(framework_res_package_export) 119else 120framework_res_package_export := \ 121 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk 122framework_res_package_export_deps := \ 123 $(dir $(framework_res_package_export))src/R.stamp 124endif 125endif 126 127# add --non-constant-id to prevent inlining constants. 128# AAR needs text symbol file R.txt. 129ifdef LOCAL_USE_AAPT2 130$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --static-lib --no-static-lib-packages 131$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PRODUCT_AAPT_CONFIG := 132$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := 133$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_AAPT_CHARACTERISTICS := 134else 135$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --non-constant-id --output-text-symbols $(LOCAL_INTERMEDIATE_SOURCE_DIR) 136endif 137 138$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR) 139$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest) 140$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_PUBLICS_OUTPUT := $(intermediates.COMMON)/public_resources.xml 141$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR) 142$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export) 143 144$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR := 145$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file) 146$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_PACKAGE_NAME := 147$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_INSTRUMENTATION_FOR := 148 149ifdef LOCAL_USE_AAPT2 150# One more level with name res so we can zip up the flat resources that can be linked by apps. 151my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res/res 152renderscript_target_api := 153ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API)) 154renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API) 155else 156ifneq (,$(LOCAL_SDK_VERSION)) 157# Set target-api for LOCAL_SDK_VERSIONs other than current. 158ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION))) 159renderscript_target_api := $(LOCAL_SDK_VERSION) 160endif 161endif # LOCAL_SDK_VERSION is set 162endif # LOCAL_RENDERSCRIPT_TARGET_API is set 163ifneq (,$(renderscript_target_api)) 164ifneq ($(call math_gt_or_eq,$(renderscript_target_api),21),true) 165my_generated_res_dirs := $(rs_generated_res_dir) 166my_generated_res_dirs_deps := $(RenderScript_file_stamp) 167endif # renderscript_target_api < 21 168endif # renderscript_target_api is set 169include $(BUILD_SYSTEM)/aapt2.mk 170$(my_res_package) : $(framework_res_package_export_deps) 171else 172$(R_file_stamp) : $(all_resources) $(full_android_manifest) $(AAPT) $(framework_res_package_export_deps) 173 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)" 174 $(create-resource-java-files) 175 $(hide) find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name R.java | xargs cat > $@ 176endif # LOCAL_USE_AAPT2 177 178$(LOCAL_BUILT_MODULE): $(R_file_stamp) 179ifdef LOCAL_JACK_ENABLED 180$(noshrob_classes_jack): $(R_file_stamp) 181$(full_classes_jack): $(R_file_stamp) 182$(jack_check_timestamp): $(R_file_stamp) 183endif # LOCAL_JACK_ENABLED 184$(full_classes_compiled_jar): $(R_file_stamp) 185 186 187# if we have custom proguarding done use the proguarded classes jar instead of the normal classes jar 188ifeq ($(filter custom,$(LOCAL_PROGUARD_ENABLED)),custom) 189aar_classes_jar = $(full_classes_jar) 190else 191aar_classes_jar = $(full_classes_pre_proguard_jar) 192endif 193 194# Rule to build AAR, archive including classes.jar, resource, etc. 195built_aar := $(intermediates.COMMON)/javalib.aar 196$(built_aar): PRIVATE_MODULE := $(LOCAL_MODULE) 197$(built_aar): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest) 198$(built_aar): PRIVATE_CLASSES_JAR := $(aar_classes_jar) 199$(built_aar): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR) 200$(built_aar): PRIVATE_R_TXT := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/R.txt 201$(built_aar) : $(aar_classes_jar) $(full_android_manifest) 202 @echo "target AAR: $(PRIVATE_MODULE) ($@)" 203 $(hide) rm -rf $(dir $@)aar && mkdir -p $(dir $@)aar/res 204 $(hide) cp $(PRIVATE_ANDROID_MANIFEST) $(dir $@)aar/AndroidManifest.xml 205 $(hide) cp $(PRIVATE_CLASSES_JAR) $(dir $@)aar/classes.jar 206 # Note: Use "cp -n" to honor the resource overlay rules, if multiple res dirs exist. 207 $(hide) $(foreach res,$(PRIVATE_RESOURCE_DIR),cp -Rfn $(res)/* $(dir $@)aar/res;) 208 $(hide) cp $(PRIVATE_R_TXT) $(dir $@)aar/R.txt 209 $(hide) jar -cMf $@ \ 210 -C $(dir $@)aar . 211 212# Register the aar file. 213ALL_MODULES.$(LOCAL_MODULE).AAR := $(built_aar) 214endif # need_compile_res 215 216# Reset internal variables. 217aar_classes_jar := 218all_res_assets := 219LOCAL_IS_STATIC_JAVA_LIBRARY := 220