blob: 6efeb3507fc1ffb51daf4313d486de229bf0f5fd [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001#
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
Ying Wangba71aba2013-03-26 12:42:32 -070024LOCAL_MODULE_CLASS := JAVA_LIBRARIES
Ying Wang20e20832011-12-14 14:29:28 -080025
Ying Wanga8f28ff2016-01-11 13:34:16 -080026#################################
27include $(BUILD_SYSTEM)/configure_local_jack.mk
28#################################
29
Ying Wangdd71c852015-12-04 13:59:18 -080030intermediates.COMMON := $(call local-intermediates-dir,COMMON)
31
32my_res_package :=
33# A zip file that apps can link with aapt2
34# We need my_library_resources as dependency even if a library doesn't have resource.
35my_library_resources := $(intermediates.COMMON)/library-res.flata
36
Ying Wang20e20832011-12-14 14:29:28 -080037# Hack to build static Java library with Android resource
38# See bug 5714516
39all_resources :=
Ying Wang61291922014-06-25 13:23:58 -070040need_compile_res :=
41# A static Java library needs to explicily set LOCAL_RESOURCE_DIR.
Ying Wang20e20832011-12-14 14:29:28 -080042ifdef LOCAL_RESOURCE_DIR
Ying Wang61291922014-06-25 13:23:58 -070043need_compile_res := true
Ying Wangdd71c852015-12-04 13:59:18 -080044
Ying Wang20e20832011-12-14 14:29:28 -080045all_resources := $(strip \
46 $(foreach dir, $(LOCAL_RESOURCE_DIR), \
47 $(addprefix $(dir)/, \
48 $(patsubst res/%,%, \
49 $(call find-subdir-assets,$(dir)) \
50 ) \
51 ) \
52 ))
Ying Wang5758b8e2011-12-15 16:36:55 -080053
Ying Wangae25ec12012-06-19 10:40:37 -070054# By default we should remove the R/Manifest classes from a static Java library,
55# because they will be regenerated in the app that uses it.
56# But if the static Java library will be used by a library, then we may need to
57# keep the generated classes with "LOCAL_JAR_EXCLUDE_FILES := none".
58ifndef LOCAL_JAR_EXCLUDE_FILES
59LOCAL_JAR_EXCLUDE_FILES := $(ANDROID_RESOURCE_GENERATED_CLASSES)
Ying Wang5758b8e2011-12-15 16:36:55 -080060endif
Ying Wangae25ec12012-06-19 10:40:37 -070061ifeq (none,$(LOCAL_JAR_EXCLUDE_FILES))
62LOCAL_JAR_EXCLUDE_FILES :=
Ying Wang20e20832011-12-14 14:29:28 -080063endif
Ying Wangba71aba2013-03-26 12:42:32 -070064
65proguard_options_file :=
66
Ying Wangba71aba2013-03-26 12:42:32 -070067ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
68 proguard_options_file := $(intermediates.COMMON)/proguard_options
69endif
Yohann Rousselb4c49cb2014-09-08 14:45:14 +020070
Ying Wangba71aba2013-03-26 12:42:32 -070071LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
72
Yohann Roussel37822c42015-01-09 10:36:40 +010073ifdef LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +020074ifndef LOCAL_JACK_PROGUARD_FLAGS
75 LOCAL_JACK_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS)
76endif
77LOCAL_JACK_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_JACK_PROGUARD_FLAGS)
Yohann Roussel37822c42015-01-09 10:36:40 +010078endif # LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +020079
Ying Wangdd71c852015-12-04 13:59:18 -080080R_file_stamp := $(intermediates.COMMON)/src/R.stamp
81LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
82
83ifdef USE_AAPT2
84# For library we treat all the resource equal with no overlay.
85my_res_resources := $(all_resources)
86my_overlay_resources :=
87# For libraries put everything in the COMMON intermediate directory.
88my_res_package := $(intermediates.COMMON)/package-res.apk
89
90LOCAL_INTERMEDIATE_TARGETS += $(my_res_package)
91endif # USE_AAPT2
Ying Wangae25ec12012-06-19 10:40:37 -070092endif # LOCAL_RESOURCE_DIR
Ying Wang20e20832011-12-14 14:29:28 -080093
Ying Wang576e0142013-08-28 11:16:06 -070094all_res_assets := $(all_resources)
95
The Android Open Source Project88b60792009-03-03 19:28:42 -080096include $(BUILD_SYSTEM)/java_library.mk
Ying Wang20e20832011-12-14 14:29:28 -080097
Ying Wang61291922014-06-25 13:23:58 -070098ifeq (true,$(need_compile_res))
Ying Wangdc7fee92014-02-05 18:24:45 -080099include $(BUILD_SYSTEM)/android_manifest.mk
Ying Wang20e20832011-12-14 14:29:28 -0800100
Ying Wangaaa8f062012-01-03 11:52:26 -0800101LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
102ifeq ($(LOCAL_SDK_RES_VERSION),)
103 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
104endif
105
Ying Wang20e20832011-12-14 14:29:28 -0800106framework_res_package_export :=
107framework_res_package_export_deps :=
108# Please refer to package.mk
109ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
Michael Wright0fb087f2015-11-06 15:20:51 +0000110ifneq ($(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))),)
Ying Wang20e20832011-12-14 14:29:28 -0800111framework_res_package_export := \
112 $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar
113framework_res_package_export_deps := $(framework_res_package_export)
114else
115framework_res_package_export := \
116 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
117framework_res_package_export_deps := \
118 $(dir $(framework_res_package_export))src/R.stamp
119endif
120endif
121
Ying Wang20e20832011-12-14 14:29:28 -0800122# add --non-constant-id to prevent inlining constants.
Ying Wangf1db7e22014-12-17 17:00:53 -0800123# AAR needs text symbol file R.txt.
Ying Wangdd71c852015-12-04 13:59:18 -0800124ifdef USE_AAPT2
125$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --non-final-ids
Ying Wang20e20832011-12-14 14:29:28 -0800126else
Ying Wangdd71c852015-12-04 13:59:18 -0800127$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --non-constant-id --output-text-symbols $(LOCAL_INTERMEDIATE_SOURCE_DIR)
Ying Wang20e20832011-12-14 14:29:28 -0800128endif
Ying Wangdd71c852015-12-04 13:59:18 -0800129$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR)
130$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
131$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_PUBLICS_OUTPUT := $(intermediates.COMMON)/public_resources.xml
132$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
133$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
134ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
135$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION)
136else
137$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK)
138endif
139$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR :=
140$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
141$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_PACKAGE_NAME :=
142$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_INSTRUMENTATION_FOR :=
Ying Wang20e20832011-12-14 14:29:28 -0800143
Ying Wangdd71c852015-12-04 13:59:18 -0800144ifdef USE_AAPT2
145# For libraries don't use any product specific flags.
146my_aapt_characteristics :=
147# One more level with name res so we can zip up the flat resources that can be linked by apps.
148my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res/res
149include $(BUILD_SYSTEM)/aapt2.mk
150$(my_res_package) : $(framework_res_package_export_deps)
151else
Ying Wang20e20832011-12-14 14:29:28 -0800152$(R_file_stamp) : $(all_resources) $(full_android_manifest) $(AAPT) $(framework_res_package_export_deps)
153 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
154 $(create-resource-java-files)
155 $(hide) find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name R.java | xargs cat > $@
Ying Wangdd71c852015-12-04 13:59:18 -0800156endif # USE_AAPT2
Ying Wang20e20832011-12-14 14:29:28 -0800157
158$(LOCAL_BUILT_MODULE): $(R_file_stamp)
Yohann Roussel37822c42015-01-09 10:36:40 +0100159ifdef LOCAL_JACK_ENABLED
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200160$(noshrob_classes_jack): $(R_file_stamp)
161$(full_classes_jack): $(R_file_stamp)
Yohann Roussel37822c42015-01-09 10:36:40 +0100162endif # LOCAL_JACK_ENABLED
Ying Wang20e20832011-12-14 14:29:28 -0800163$(full_classes_compiled_jar): $(R_file_stamp)
Ying Wang20e20832011-12-14 14:29:28 -0800164
Ying Wangf1db7e22014-12-17 17:00:53 -0800165# Rule to build AAR, archive including classes.jar, resource, etc.
166built_aar := $(intermediates.COMMON)/javalib.aar
167$(built_aar): PRIVATE_MODULE := $(LOCAL_MODULE)
168$(built_aar): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
169$(built_aar): PRIVATE_CLASSES_JAR := $(LOCAL_BUILT_MODULE)
170$(built_aar): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
171$(built_aar): PRIVATE_R_TXT := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/R.txt
172$(built_aar) : $(LOCAL_BUILT_MODULE)
173 @echo "target AAR: $(PRIVATE_MODULE) ($@)"
174 $(hide) rm -rf $(dir $@)aar && mkdir -p $(dir $@)aar/res
175 $(hide) cp $(PRIVATE_ANDROID_MANIFEST) $(dir $@)aar/AndroidManifest.xml
176 $(hide) cp $(PRIVATE_CLASSES_JAR) $(dir $@)aar/classes.jar
177 # Note: Use "cp -n" to honor the resource overlay rules, if multiple res dirs exist.
178 $(hide) $(foreach res,$(PRIVATE_RESOURCE_DIR),cp -Rfn $(res)/* $(dir $@)aar/res;)
179 $(hide) cp $(PRIVATE_R_TXT) $(dir $@)aar/R.txt
180 $(hide) jar -cMf $@ \
181 -C $(dir $@)aar .
182
183# Register the aar file.
184ALL_MODULES.$(LOCAL_MODULE).AAR := $(built_aar)
Ying Wang61291922014-06-25 13:23:58 -0700185endif # need_compile_res
Ying Wang20e20832011-12-14 14:29:28 -0800186
Ying Wangdd71c852015-12-04 13:59:18 -0800187ifdef USE_AAPT2
188# If a static Java library has no resources, create empty package apps can depend on.
189$(my_library_resources): PRIVATE_RES_DIR := $(intermediates.COMMON)/flat-res/res
190$(my_library_resources) : $(my_res_package)
191 @echo "Package static library resources $@"
192 @rm -rf $@ && mkdir -p $(dir $@) $(PRIVATE_RES_DIR)
193 $(hide) cd $(dir $(PRIVATE_RES_DIR)) && zip -qrX $(abspath $@) $(notdir $(PRIVATE_RES_DIR))
194
195# Make sure my_library_resources is created when you run mm/mmm.
196$(LOCAL_BUILT_MODULE) : $(my_library_resources)
197endif # USE_AAPT2
198
Ying Wang990cf5e2013-08-28 13:04:46 -0700199# Reset internal variables.
200all_res_assets :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800201LOCAL_IS_STATIC_JAVA_LIBRARY :=