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 LOCAL_UNINSTALLABLE_MODULE := true 23 LOCAL_IS_STATIC_JAVA_LIBRARY := true 24 LOCAL_MODULE_CLASS := JAVA_LIBRARIES 25 26 # Hack to build static Java library with Android resource 27 # See bug 5714516 28 all_resources := 29 ifdef LOCAL_RESOURCE_DIR 30 all_resources := $(strip \ 31 $(foreach dir, $(LOCAL_RESOURCE_DIR), \ 32 $(addprefix $(dir)/, \ 33 $(patsubst res/%,%, \ 34 $(call find-subdir-assets,$(dir)) \ 35 ) \ 36 ) \ 37 )) 38 39 ifneq (,$(all_resources)) 40 # By default we should remove the R/Manifest classes from a static Java library, 41 # because they will be regenerated in the app that uses it. 42 # But if the static Java library will be used by a library, then we may need to 43 # keep the generated classes with "LOCAL_JAR_EXCLUDE_FILES := none". 44 ifndef LOCAL_JAR_EXCLUDE_FILES 45 LOCAL_JAR_EXCLUDE_FILES := $(ANDROID_RESOURCE_GENERATED_CLASSES) 46 endif 47 ifeq (none,$(LOCAL_JAR_EXCLUDE_FILES)) 48 LOCAL_JAR_EXCLUDE_FILES := 49 endif 50 51 proguard_options_file := 52 53 intermediates.COMMON := $(call local-intermediates-dir,COMMON) 54 ifneq ($(LOCAL_PROGUARD_ENABLED),custom) 55 proguard_options_file := $(intermediates.COMMON)/proguard_options 56 endif 57 LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS) 58 59 endif # all_resources 60 endif # LOCAL_RESOURCE_DIR 61 62 all_res_assets := $(all_resources) 63 64 include $(BUILD_SYSTEM)/java_library.mk 65 66 ifneq (,$(all_resources)) 67 R_file_stamp := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/R.stamp 68 69 ifeq ($(strip $(LOCAL_MANIFEST_FILE)),) 70 LOCAL_MANIFEST_FILE := AndroidManifest.xml 71 endif 72 ifdef LOCAL_FULL_MANIFEST_FILE 73 full_android_manifest := $(LOCAL_FULL_MANIFEST_FILE) 74 else 75 full_android_manifest := $(LOCAL_PATH)/$(LOCAL_MANIFEST_FILE) 76 endif 77 78 LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION)) 79 ifeq ($(LOCAL_SDK_RES_VERSION),) 80 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION) 81 endif 82 83 framework_res_package_export := 84 framework_res_package_export_deps := 85 # Please refer to package.mk 86 ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 87 ifneq ($(filter-out current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current,$(LOCAL_SDK_RES_VERSION))),) 88 framework_res_package_export := \ 89 $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar 90 framework_res_package_export_deps := $(framework_res_package_export) 91 else 92 framework_res_package_export := \ 93 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk 94 framework_res_package_export_deps := \ 95 $(dir $(framework_res_package_export))src/R.stamp 96 endif 97 endif 98 99 $(R_file_stamp): PRIVATE_MODULE := $(LOCAL_MODULE) 100 # add --non-constant-id to prevent inlining constants. 101 $(R_file_stamp): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --non-constant-id 102 $(R_file_stamp): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR) 103 $(R_file_stamp): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest) 104 $(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := $(intermediates.COMMON)/public_resources.xml 105 $(R_file_stamp): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR) 106 $(R_file_stamp): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export) 107 ifneq (,$(filter-out current, $(LOCAL_SDK_VERSION))) 108 $(R_file_stamp): PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION) 109 else 110 $(R_file_stamp): PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK) 111 endif 112 $(R_file_stamp): PRIVATE_ASSET_DIR := 113 $(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file) 114 $(R_file_stamp): PRIVATE_MANIFEST_PACKAGE_NAME := 115 $(R_file_stamp): PRIVATE_MANIFEST_INSTRUMENTATION_FOR := 116 117 $(R_file_stamp) : $(all_resources) $(full_android_manifest) $(AAPT) $(framework_res_package_export_deps) 118 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)" 119 $(create-resource-java-files) 120 $(hide) find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name R.java | xargs cat > $@ 121 122 $(LOCAL_BUILT_MODULE): $(R_file_stamp) 123 ifneq ($(full_classes_jar),) 124 $(full_classes_compiled_jar): $(R_file_stamp) 125 endif 126 127 endif # $(all_resources) not empty 128 129 # Reset internal variables. 130 all_res_assets := 131 LOCAL_IS_STATIC_JAVA_LIBRARY := 132