| The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 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 | 
| Ying Wang | ba71aba | 2013-03-26 12:42:32 -0700 | [diff] [blame] | 24 | LOCAL_MODULE_CLASS := JAVA_LIBRARIES | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 25 |  | 
|  | 26 | # Hack to build static Java library with Android resource | 
|  | 27 | # See bug 5714516 | 
|  | 28 | all_resources := | 
| Ying Wang | 6129192 | 2014-06-25 13:23:58 -0700 | [diff] [blame] | 29 | need_compile_res := | 
|  | 30 | # A static Java library needs to explicily set LOCAL_RESOURCE_DIR. | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 31 | ifdef LOCAL_RESOURCE_DIR | 
| Ying Wang | 6129192 | 2014-06-25 13:23:58 -0700 | [diff] [blame] | 32 | need_compile_res := true | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 33 | all_resources := $(strip \ | 
|  | 34 | $(foreach dir, $(LOCAL_RESOURCE_DIR), \ | 
|  | 35 | $(addprefix $(dir)/, \ | 
|  | 36 | $(patsubst res/%,%, \ | 
|  | 37 | $(call find-subdir-assets,$(dir)) \ | 
|  | 38 | ) \ | 
|  | 39 | ) \ | 
|  | 40 | )) | 
| Ying Wang | 5758b8e | 2011-12-15 16:36:55 -0800 | [diff] [blame] | 41 |  | 
| Ying Wang | ae25ec1 | 2012-06-19 10:40:37 -0700 | [diff] [blame] | 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". | 
|  | 46 | ifndef LOCAL_JAR_EXCLUDE_FILES | 
|  | 47 | LOCAL_JAR_EXCLUDE_FILES := $(ANDROID_RESOURCE_GENERATED_CLASSES) | 
| Ying Wang | 5758b8e | 2011-12-15 16:36:55 -0800 | [diff] [blame] | 48 | endif | 
| Ying Wang | ae25ec1 | 2012-06-19 10:40:37 -0700 | [diff] [blame] | 49 | ifeq (none,$(LOCAL_JAR_EXCLUDE_FILES)) | 
|  | 50 | LOCAL_JAR_EXCLUDE_FILES := | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 51 | endif | 
| Ying Wang | ba71aba | 2013-03-26 12:42:32 -0700 | [diff] [blame] | 52 |  | 
|  | 53 | proguard_options_file := | 
|  | 54 |  | 
|  | 55 | intermediates.COMMON := $(call local-intermediates-dir,COMMON) | 
|  | 56 | ifneq ($(LOCAL_PROGUARD_ENABLED),custom) | 
|  | 57 | proguard_options_file := $(intermediates.COMMON)/proguard_options | 
|  | 58 | endif | 
| Yohann Roussel | b4c49cb | 2014-09-08 14:45:14 +0200 | [diff] [blame] | 59 |  | 
| Ying Wang | ba71aba | 2013-03-26 12:42:32 -0700 | [diff] [blame] | 60 | LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS) | 
|  | 61 |  | 
| Yohann Roussel | d2a76c1 | 2015-02-05 16:10:58 +0100 | [diff] [blame] | 62 | ################################# | 
|  | 63 | include $(BUILD_SYSTEM)/configure_local_jack.mk | 
|  | 64 | ################################# | 
|  | 65 |  | 
| Yohann Roussel | 37822c4 | 2015-01-09 10:36:40 +0100 | [diff] [blame] | 66 | ifdef LOCAL_JACK_ENABLED | 
| Yohann Roussel | b4c49cb | 2014-09-08 14:45:14 +0200 | [diff] [blame] | 67 | ifndef LOCAL_JACK_PROGUARD_FLAGS | 
|  | 68 | LOCAL_JACK_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS) | 
|  | 69 | endif | 
|  | 70 | LOCAL_JACK_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_JACK_PROGUARD_FLAGS) | 
| Yohann Roussel | 37822c4 | 2015-01-09 10:36:40 +0100 | [diff] [blame] | 71 | endif # LOCAL_JACK_ENABLED | 
| Yohann Roussel | b4c49cb | 2014-09-08 14:45:14 +0200 | [diff] [blame] | 72 |  | 
| Ying Wang | ae25ec1 | 2012-06-19 10:40:37 -0700 | [diff] [blame] | 73 | endif  # LOCAL_RESOURCE_DIR | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 74 |  | 
| Ying Wang | 576e014 | 2013-08-28 11:16:06 -0700 | [diff] [blame] | 75 | all_res_assets := $(all_resources) | 
|  | 76 |  | 
| The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 77 | include $(BUILD_SYSTEM)/java_library.mk | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 78 |  | 
| Ying Wang | 6129192 | 2014-06-25 13:23:58 -0700 | [diff] [blame] | 79 | ifeq (true,$(need_compile_res)) | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 80 | R_file_stamp := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/R.stamp | 
|  | 81 |  | 
| Ying Wang | dc7fee9 | 2014-02-05 18:24:45 -0800 | [diff] [blame] | 82 | include $(BUILD_SYSTEM)/android_manifest.mk | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 83 |  | 
| Ying Wang | aaa8f06 | 2012-01-03 11:52:26 -0800 | [diff] [blame] | 84 | LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION)) | 
|  | 85 | ifeq ($(LOCAL_SDK_RES_VERSION),) | 
|  | 86 | LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION) | 
|  | 87 | endif | 
|  | 88 |  | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 89 | framework_res_package_export := | 
|  | 90 | framework_res_package_export_deps := | 
|  | 91 | # Please refer to package.mk | 
|  | 92 | ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) | 
| Ying Wang | efb9358 | 2014-07-19 17:00:50 -0700 | [diff] [blame] | 93 | ifneq ($(filter-out current system_current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current,$(LOCAL_SDK_RES_VERSION))),) | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 94 | framework_res_package_export := \ | 
|  | 95 | $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar | 
|  | 96 | framework_res_package_export_deps := $(framework_res_package_export) | 
|  | 97 | else | 
|  | 98 | framework_res_package_export := \ | 
|  | 99 | $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk | 
|  | 100 | framework_res_package_export_deps := \ | 
|  | 101 | $(dir $(framework_res_package_export))src/R.stamp | 
|  | 102 | endif | 
|  | 103 | endif | 
|  | 104 |  | 
|  | 105 | $(R_file_stamp): PRIVATE_MODULE := $(LOCAL_MODULE) | 
|  | 106 | # add --non-constant-id to prevent inlining constants. | 
| Ying Wang | f1db7e2 | 2014-12-17 17:00:53 -0800 | [diff] [blame] | 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) | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 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) | 
| Ying Wang | efb9358 | 2014-07-19 17:00:50 -0700 | [diff] [blame] | 114 | ifneq (,$(filter-out current system_current, $(LOCAL_SDK_VERSION))) | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 115 | $(R_file_stamp): PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION) | 
|  | 116 | else | 
|  | 117 | $(R_file_stamp): PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK) | 
|  | 118 | endif | 
|  | 119 | $(R_file_stamp): PRIVATE_ASSET_DIR := | 
| Ying Wang | ba71aba | 2013-03-26 12:42:32 -0700 | [diff] [blame] | 120 | $(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file) | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 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) | 
| Yohann Roussel | 37822c4 | 2015-01-09 10:36:40 +0100 | [diff] [blame] | 130 | ifdef LOCAL_JACK_ENABLED | 
| Yohann Roussel | b4c49cb | 2014-09-08 14:45:14 +0200 | [diff] [blame] | 131 | $(noshrob_classes_jack): $(R_file_stamp) | 
|  | 132 | $(full_classes_jack): $(R_file_stamp) | 
| Yohann Roussel | 37822c4 | 2015-01-09 10:36:40 +0100 | [diff] [blame] | 133 | endif # LOCAL_JACK_ENABLED | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 134 | $(full_classes_compiled_jar): $(R_file_stamp) | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 135 |  | 
| Ying Wang | f1db7e2 | 2014-12-17 17:00:53 -0800 | [diff] [blame] | 136 | # Rule to build AAR, archive including classes.jar, resource, etc. | 
|  | 137 | built_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. | 
|  | 155 | ALL_MODULES.$(LOCAL_MODULE).AAR := $(built_aar) | 
|  | 156 |  | 
| Ying Wang | 6129192 | 2014-06-25 13:23:58 -0700 | [diff] [blame] | 157 | endif  # need_compile_res | 
| Ying Wang | 20e2083 | 2011-12-14 14:29:28 -0800 | [diff] [blame] | 158 |  | 
| Ying Wang | 990cf5e | 2013-08-28 13:04:46 -0700 | [diff] [blame] | 159 | # Reset internal variables. | 
|  | 160 | all_res_assets := | 
| The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 161 | LOCAL_IS_STATIC_JAVA_LIBRARY := |