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 22LOCAL_UNINSTALLABLE_MODULE := true 23LOCAL_IS_STATIC_JAVA_LIBRARY := true 24LOCAL_MODULE_CLASS := JAVA_LIBRARIES 25 26# Hack to build static Java library with Android resource 27# See bug 5714516 28all_resources := 29need_compile_res := 30# A static Java library needs to explicily set LOCAL_RESOURCE_DIR. 31ifdef LOCAL_RESOURCE_DIR 32need_compile_res := true 33all_resources := $(strip \ 34 $(foreach dir, $(LOCAL_RESOURCE_DIR), \ 35 $(addprefix $(dir)/, \ 36 $(patsubst res/%,%, \ 37 $(call find-subdir-assets,$(dir)) \ 38 ) \ 39 ) \ 40 )) 41 42# By default we should remove the R/Manifest classes from a static Java library, 43# because they will be regenerated in the app that uses it. 44# But if the static Java library will be used by a library, then we may need to 45# keep the generated classes with "LOCAL_JAR_EXCLUDE_FILES := none". 46ifndef LOCAL_JAR_EXCLUDE_FILES 47LOCAL_JAR_EXCLUDE_FILES := $(ANDROID_RESOURCE_GENERATED_CLASSES) 48endif 49ifeq (none,$(LOCAL_JAR_EXCLUDE_FILES)) 50LOCAL_JAR_EXCLUDE_FILES := 51endif 52 53proguard_options_file := 54 55intermediates.COMMON := $(call local-intermediates-dir,COMMON) 56ifneq ($(LOCAL_PROGUARD_ENABLED),custom) 57 proguard_options_file := $(intermediates.COMMON)/proguard_options 58endif 59 60LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS) 61 62################################# 63include $(BUILD_SYSTEM)/configure_local_jack.mk 64################################# 65 66ifdef LOCAL_JACK_ENABLED 67ifndef LOCAL_JACK_PROGUARD_FLAGS 68 LOCAL_JACK_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS) 69endif 70LOCAL_JACK_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_JACK_PROGUARD_FLAGS) 71endif # LOCAL_JACK_ENABLED 72 73endif # LOCAL_RESOURCE_DIR 74 75all_res_assets := $(all_resources) 76 77include $(BUILD_SYSTEM)/java_library.mk 78 79ifeq (true,$(need_compile_res)) 80R_file_stamp := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/R.stamp 81 82include $(BUILD_SYSTEM)/android_manifest.mk 83 84LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION)) 85ifeq ($(LOCAL_SDK_RES_VERSION),) 86 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION) 87endif 88 89framework_res_package_export := 90framework_res_package_export_deps := 91# Please refer to package.mk 92ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 93ifneq ($(filter-out current system_current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current,$(LOCAL_SDK_RES_VERSION))),) 94framework_res_package_export := \ 95 $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar 96framework_res_package_export_deps := $(framework_res_package_export) 97else 98framework_res_package_export := \ 99 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk 100framework_res_package_export_deps := \ 101 $(dir $(framework_res_package_export))src/R.stamp 102endif 103endif 104 105$(R_file_stamp): PRIVATE_MODULE := $(LOCAL_MODULE) 106# add --non-constant-id to prevent inlining constants. 107# AAR needs text symbol file R.txt. 108$(R_file_stamp): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --non-constant-id --output-text-symbols $(LOCAL_INTERMEDIATE_SOURCE_DIR) 109$(R_file_stamp): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR) 110$(R_file_stamp): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest) 111$(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := $(intermediates.COMMON)/public_resources.xml 112$(R_file_stamp): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR) 113$(R_file_stamp): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export) 114ifneq (,$(filter-out current system_current, $(LOCAL_SDK_VERSION))) 115$(R_file_stamp): PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION) 116else 117$(R_file_stamp): PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK) 118endif 119$(R_file_stamp): PRIVATE_ASSET_DIR := 120$(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file) 121$(R_file_stamp): PRIVATE_MANIFEST_PACKAGE_NAME := 122$(R_file_stamp): PRIVATE_MANIFEST_INSTRUMENTATION_FOR := 123 124$(R_file_stamp) : $(all_resources) $(full_android_manifest) $(AAPT) $(framework_res_package_export_deps) 125 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)" 126 $(create-resource-java-files) 127 $(hide) find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name R.java | xargs cat > $@ 128 129$(LOCAL_BUILT_MODULE): $(R_file_stamp) 130ifdef LOCAL_JACK_ENABLED 131$(noshrob_classes_jack): $(R_file_stamp) 132$(full_classes_jack): $(R_file_stamp) 133endif # LOCAL_JACK_ENABLED 134$(full_classes_compiled_jar): $(R_file_stamp) 135 136# Rule to build AAR, archive including classes.jar, resource, etc. 137built_aar := $(intermediates.COMMON)/javalib.aar 138$(built_aar): PRIVATE_MODULE := $(LOCAL_MODULE) 139$(built_aar): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest) 140$(built_aar): PRIVATE_CLASSES_JAR := $(LOCAL_BUILT_MODULE) 141$(built_aar): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR) 142$(built_aar): PRIVATE_R_TXT := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/R.txt 143$(built_aar) : $(LOCAL_BUILT_MODULE) 144 @echo "target AAR: $(PRIVATE_MODULE) ($@)" 145 $(hide) rm -rf $(dir $@)aar && mkdir -p $(dir $@)aar/res 146 $(hide) cp $(PRIVATE_ANDROID_MANIFEST) $(dir $@)aar/AndroidManifest.xml 147 $(hide) cp $(PRIVATE_CLASSES_JAR) $(dir $@)aar/classes.jar 148 # Note: Use "cp -n" to honor the resource overlay rules, if multiple res dirs exist. 149 $(hide) $(foreach res,$(PRIVATE_RESOURCE_DIR),cp -Rfn $(res)/* $(dir $@)aar/res;) 150 $(hide) cp $(PRIVATE_R_TXT) $(dir $@)aar/R.txt 151 $(hide) jar -cMf $@ \ 152 -C $(dir $@)aar . 153 154# Register the aar file. 155ALL_MODULES.$(LOCAL_MODULE).AAR := $(built_aar) 156 157endif # need_compile_res 158 159# Reset internal variables. 160all_res_assets := 161LOCAL_IS_STATIC_JAVA_LIBRARY := 162