• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
27intermediates.COMMON := $(call local-intermediates-dir,COMMON)
28
29my_res_package :=
30
31# Process Support Library dependencies.
32include $(BUILD_SYSTEM)/support_libraries.mk
33
34include $(BUILD_SYSTEM)/force_aapt2.mk
35
36# Hack to build static Java library with Android resource
37# See bug 5714516
38all_resources :=
39need_compile_res :=
40# A static Java library needs to explicily set LOCAL_RESOURCE_DIR.
41ifdef LOCAL_RESOURCE_DIR
42need_compile_res := true
43LOCAL_RESOURCE_DIR := $(foreach d,$(LOCAL_RESOURCE_DIR),$(call clean-path,$(d)))
44endif
45ifneq ($(strip $(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)),)
46need_compile_res := true
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)
77LOCAL_PROGUARD_FLAGS_DEPS += $(proguard_options_file)
78
79R_file_stamp := $(intermediates.COMMON)/src/R.stamp
80LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
81
82ifneq ($(strip $(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)),)
83  # If we are using static android libraries, every source file becomes an overlay.
84  # This is to emulate old AAPT behavior which simulated library support.
85  my_res_resources :=
86  my_overlay_resources := $(all_resources)
87else
88  # Otherwise, for a library we treat all the resource equal with no overlay.
89  my_res_resources := $(all_resources)
90  my_overlay_resources :=
91endif
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)
96
97endif  # need_compile_res
98
99all_res_assets := $(all_resources)
100
101include $(BUILD_SYSTEM)/java_renderscript.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 :=
112# Please refer to package.mk
113ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
114ifneq ($(filter-out current system_current test_current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_APPS_USE_PREBUILT_SDK),$(filter current system_current test_current,$(LOCAL_SDK_RES_VERSION))),)
115framework_res_package_export := \
116    $(call resolve-prebuilt-sdk-jar-path,$(LOCAL_SDK_RES_VERSION))
117else
118framework_res_package_export := \
119    $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
120endif
121endif
122
123import_proguard_flag_files := $(strip $(foreach l,$(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES),\
124    $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/export_proguard_flags))
125$(intermediates.COMMON)/export_proguard_flags: $(import_proguard_flag_files) $(addprefix $(LOCAL_PATH)/,$(LOCAL_EXPORT_PROGUARD_FLAG_FILES))
126	@echo "Export proguard flags: $@"
127	rm -f $@
128	touch $@
129	for f in $+; do \
130		echo -e "\n# including $$f" >>$@; \
131		cat $$f >>$@; \
132	done
133import_proguard_flag_files :=
134
135include $(BUILD_SYSTEM)/aapt_flags.mk
136
137$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS)
138$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_AAPT_CHARACTERISTICS := $(TARGET_AAPT_CHARACTERISTICS)
139$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_PACKAGE_NAME := $(LOCAL_MANIFEST_PACKAGE_NAME)
140$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_INSTRUMENTATION_FOR := $(LOCAL_MANIFEST_INSTRUMENTATION_FOR)
141
142# add --non-constant-id to prevent inlining constants.
143# AAR needs text symbol file R.txt.
144$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --static-lib --output-text-symbols $(intermediates.COMMON)/R.txt
145ifndef LOCAL_AAPT_NAMESPACES
146  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS += --no-static-lib-packages
147endif
148$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PRODUCT_AAPT_CONFIG :=
149$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
150$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_AAPT_CHARACTERISTICS :=
151
152$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
153$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_PUBLICS_OUTPUT := $(intermediates.COMMON)/public_resources.xml
154$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
155$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
156
157$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR :=
158$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
159$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_PACKAGE_NAME :=
160$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_INSTRUMENTATION_FOR :=
161
162# One more level with name res so we can zip up the flat resources that can be linked by apps.
163my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res/res
164ifneq (,$(filter-out current,$(renderscript_target_api)))
165  ifneq ($(call math_gt_or_eq,$(renderscript_target_api),21),true)
166    my_generated_res_zips := $(rs_generated_res_zip)
167  endif  # renderscript_target_api < 21
168endif  # renderscript_target_api is set
169include $(BUILD_SYSTEM)/aapt2.mk
170$(my_res_package) : $(framework_res_package_export)
171$(my_res_package): .KATI_IMPLICIT_OUTPUTS += $(intermediates.COMMON)/R.txt
172
173endif # need_compile_res
174
175include $(BUILD_SYSTEM)/java_library.mk
176
177ifeq (true,$(need_compile_res))
178
179$(LOCAL_BUILT_MODULE): $(R_file_stamp)
180$(java_source_list_file): $(R_file_stamp)
181$(full_classes_compiled_jar): $(R_file_stamp)
182$(full_classes_turbine_jar): $(R_file_stamp)
183
184
185# if we have custom proguarding done use the proguarded classes jar instead of the normal classes jar
186ifeq ($(filter custom,$(LOCAL_PROGUARD_ENABLED)),custom)
187aar_classes_jar = $(full_classes_jar)
188else
189aar_classes_jar = $(full_classes_pre_proguard_jar)
190endif
191
192# Rule to build AAR, archive including classes.jar, resource, etc.
193built_aar := $(intermediates.COMMON)/javalib.aar
194$(built_aar): PRIVATE_MODULE := $(LOCAL_MODULE)
195$(built_aar): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
196$(built_aar): PRIVATE_CLASSES_JAR := $(aar_classes_jar)
197$(built_aar): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
198$(built_aar): PRIVATE_R_TXT := $(intermediates.COMMON)/R.txt
199$(built_aar): $(JAR_ARGS)
200$(built_aar) : $(aar_classes_jar) $(full_android_manifest) $(intermediates.COMMON)/R.txt
201	@echo "target AAR:  $(PRIVATE_MODULE) ($@)"
202	$(hide) rm -rf $(dir $@)aar && mkdir -p $(dir $@)aar/res
203	$(hide) cp $(PRIVATE_ANDROID_MANIFEST) $(dir $@)aar/AndroidManifest.xml
204	$(hide) cp $(PRIVATE_CLASSES_JAR) $(dir $@)aar/classes.jar
205	# Note: Use "cp -n" to honor the resource overlay rules, if multiple res dirs exist.
206	$(hide) $(foreach res,$(PRIVATE_RESOURCE_DIR),cp -Rfn $(res)/* $(dir $@)aar/res;)
207	$(hide) cp $(PRIVATE_R_TXT) $(dir $@)aar/R.txt
208	$(hide) $(JAR) -cMf $@ \
209	  $(call jar-args-sorted-files-in-directory,$(dir $@)aar)
210
211# Register the aar file.
212ALL_MODULES.$(LOCAL_MODULE).AAR := $(built_aar)
213endif  # need_compile_res
214
215# Reset internal variables.
216aar_classes_jar :=
217all_res_assets :=
218LOCAL_IS_STATIC_JAVA_LIBRARY :=
219