blob: 476cc208e285b0e575296eb65a19711bfe046434 [file] [log] [blame]
Ying Wang956dccc2015-08-28 11:47:03 -07001# Common to host and target Java modules.
2
3###########################################################
Neil Fullerad022512016-01-29 14:22:29 +00004## Java version
5###########################################################
Neil Fullerdecb7972016-03-04 18:00:00 +00006# Use the LOCAL_JAVA_LANGUAGE_VERSION if it is set, otherwise
7# use one based on the LOCAL_SDK_VERSION. If it is < 24
8# pass "1.7" to the tools, if it is unset, >= 24 or "current"
9# pass "1.8".
10#
11# The LOCAL_SDK_VERSION behavior is to ensure that, by default,
12# code that is expected to run on older releases of Android
13# does not use any 1.8 language features that are not supported
14# on earlier runtimes (like default / static interface methods).
15# Modules can override this logic by specifying
16# LOCAL_JAVA_LANGUAGE_VERSION explicitly.
Neil Fullerad022512016-01-29 14:22:29 +000017ifeq (,$(LOCAL_JAVA_LANGUAGE_VERSION))
Neil Fullerdecb7972016-03-04 18:00:00 +000018 private_sdk_versions_without_any_java_18_support := 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
19 ifneq (,$(filter $(LOCAL_SDK_VERSION), $(private_sdk_versions_without_any_java_18_support)))
Nicolas Geoffray8d772e22016-02-29 12:07:00 +000020 LOCAL_JAVA_LANGUAGE_VERSION := 1.7
Neil Fullerdecb7972016-03-04 18:00:00 +000021 else
Tobias Thiererd61f28b2017-07-18 16:37:07 +010022 ifneq ($(EXPERIMENTAL_USE_OPENJDK9),true)
23 LOCAL_JAVA_LANGUAGE_VERSION := 1.8
24 else
25 LOCAL_JAVA_LANGUAGE_VERSION := 1.9
26 endif
Nicolas Geoffray8d772e22016-02-29 12:07:00 +000027 endif
Neil Fullerad022512016-01-29 14:22:29 +000028endif
29LOCAL_JAVACFLAGS += -source $(LOCAL_JAVA_LANGUAGE_VERSION) -target $(LOCAL_JAVA_LANGUAGE_VERSION)
30
31###########################################################
Ying Wang956dccc2015-08-28 11:47:03 -070032## .proto files: Compile proto files to .java
33###########################################################
34proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
35# Because names of the .java files compiled from .proto files are unknown until the
36# .proto files are compiled, we use a timestamp file as depedency.
37proto_java_sources_file_stamp :=
38ifneq ($(proto_sources),)
39proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
40
Dan Willemsencf324af2016-12-21 17:37:00 -080041proto_java_intemediate_dir := $(intermediates.COMMON)/proto
Ying Wang956dccc2015-08-28 11:47:03 -070042proto_java_sources_file_stamp := $(proto_java_intemediate_dir)/Proto.stamp
43proto_java_sources_dir := $(proto_java_intemediate_dir)/src
44
45$(proto_java_sources_file_stamp): PRIVATE_PROTO_INCLUDES := $(TOP)
46$(proto_java_sources_file_stamp): PRIVATE_PROTO_SRC_FILES := $(proto_sources_fullpath)
47$(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_DIR := $(proto_java_sources_dir)
48ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro)
49$(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javamicro_out
50else
51 ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nano)
52$(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javanano_out
53 else
Joe Onoratoc05a8ee2016-10-05 18:01:10 -070054 ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),stream)
55$(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javastream_out
56$(proto_java_sources_file_stamp): $(HOST_OUT_EXECUTABLES)/protoc-gen-javastream
57 else
Ying Wang956dccc2015-08-28 11:47:03 -070058$(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --java_out
Joe Onoratoc05a8ee2016-10-05 18:01:10 -070059 endif
Ying Wang956dccc2015-08-28 11:47:03 -070060 endif
61endif
62$(proto_java_sources_file_stamp): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS)
63$(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_PARAMS := $(LOCAL_PROTO_JAVA_OUTPUT_PARAMS)
64$(proto_java_sources_file_stamp) : $(proto_sources_fullpath) $(PROTOC)
65 $(call transform-proto-to-java)
66
67#TODO: protoc should output the dependencies introduced by imports.
Ying Wangd5ffec92016-03-01 22:05:25 -080068
69ALL_MODULES.$(my_register_name).PROTO_FILES := $(proto_sources_fullpath)
Ying Wang956dccc2015-08-28 11:47:03 -070070endif # proto_sources
71
72#########################################
73## Java resources
74
75# Look for resource files in any specified directories.
76# Non-java and non-doc files will be picked up as resources
77# and included in the output jar file.
78java_resource_file_groups :=
79
80LOCAL_JAVA_RESOURCE_DIRS := $(strip $(LOCAL_JAVA_RESOURCE_DIRS))
81ifneq ($(LOCAL_JAVA_RESOURCE_DIRS),)
82 # This makes a list of words like
83 # <dir1>::<file1>:<file2> <dir2>::<file1> <dir3>:
84 # where each of the files is relative to the directory it's grouped with.
85 # Directories that don't contain any resource files will result in groups
86 # that end with a colon, and they are stripped out in the next step.
87 java_resource_file_groups += \
88 $(foreach dir,$(LOCAL_JAVA_RESOURCE_DIRS), \
89 $(subst $(space),:,$(strip \
90 $(LOCAL_PATH)/$(dir): \
Dan Willemsen7c3e3f82015-09-29 16:30:21 -070091 $(patsubst ./%,%,$(sort $(shell cd $(LOCAL_PATH)/$(dir) && \
Ying Wang956dccc2015-08-28 11:47:03 -070092 find . \
93 -type d -a -name ".svn" -prune -o \
94 -type f \
95 -a \! -name "*.java" \
96 -a \! -name "package.html" \
97 -a \! -name "overview.html" \
98 -a \! -name ".*.swp" \
99 -a \! -name ".DS_Store" \
100 -a \! -name "*~" \
101 -print \
Dan Willemsen7c3e3f82015-09-29 16:30:21 -0700102 ))) \
Ying Wang956dccc2015-08-28 11:47:03 -0700103 )) \
104 )
105 java_resource_file_groups := $(filter-out %:,$(java_resource_file_groups))
106endif # LOCAL_JAVA_RESOURCE_DIRS
107
Ying Wang956dccc2015-08-28 11:47:03 -0700108ifneq ($(LOCAL_JAVA_RESOURCE_FILES),)
Colin Cross34a98852017-09-22 13:34:10 -0700109 # Converts LOCAL_JAVA_RESOURCE_FILES := <file> to $(dir $(file))::$(notdir $(file))
110 # and LOCAL_JAVA_RESOURCE_FILES := <dir>:<file> to <dir>::<file>
111 java_resource_file_groups += $(strip $(foreach res,$(LOCAL_JAVA_RESOURCE_FILES), \
112 $(eval _file := $(call word-colon,2,$(res))) \
113 $(if $(_file), \
114 $(eval _base := $(call word-colon,1,$(res))), \
115 $(eval _base := $(dir $(res))) \
116 $(eval _file := $(notdir $(res)))) \
117 $(if $(filter /%, \
118 $(filter-out $(OUT_DIR)/%,$(_base) $(_file))), \
119 $(call pretty-error,LOCAL_JAVA_RESOURCE_FILES may not include absolute paths: $(_base) $(_file))) \
120 $(patsubst %/,%,$(_base))::$(_file)))
121
Ying Wang956dccc2015-08-28 11:47:03 -0700122endif # LOCAL_JAVA_RESOURCE_FILES
123
124ifdef java_resource_file_groups
125 # The full paths to all resources, used for dependencies.
126 java_resource_sources := \
127 $(foreach group,$(java_resource_file_groups), \
128 $(addprefix $(word 1,$(subst :,$(space),$(group)))/, \
129 $(wordlist 2,9999,$(subst :,$(space),$(group))) \
130 ) \
131 )
132 # The arguments to jar that will include these files in a jar file.
133 # Quote the file name to handle special characters (such as #) correctly.
134 extra_jar_args := \
135 $(foreach group,$(java_resource_file_groups), \
136 $(addprefix -C "$(word 1,$(subst :,$(space),$(group)))" , \
137 $(foreach w, $(wordlist 2,9999,$(subst :,$(space),$(group))), "$(w)" ) \
138 ) \
139 )
140 java_resource_file_groups :=
141else
142 java_resource_sources :=
143 extra_jar_args :=
144endif # java_resource_file_groups
145
Ying Wangf8d15d62016-04-26 15:49:56 -0700146#####################################
147## Warn if there is unrecognized file in LOCAL_SRC_FILES.
148my_unknown_src_files := $(filter-out \
149 %.java %.aidl %.proto %.logtags %.fs %.rs, \
150 $(LOCAL_SRC_FILES) $(LOCAL_INTERMEDIATE_SOURCES) $(LOCAL_GENERATED_SOURCES))
151ifneq ($(my_unknown_src_files),)
152$(warning $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): Unused source files: $(my_unknown_src_files))
153endif
154
Ying Wang956dccc2015-08-28 11:47:03 -0700155######################################
156## PRIVATE java vars
157# LOCAL_SOURCE_FILES_ALL_GENERATED is set only if the module does not have static source files,
158# but generated source files in its LOCAL_INTERMEDIATE_SOURCE_DIR.
159# You have to set up the dependency in some other way.
160need_compile_java := $(strip $(all_java_sources)$(all_res_assets)$(java_resource_sources))$(LOCAL_STATIC_JAVA_LIBRARIES)$(filter true,$(LOCAL_SOURCE_FILES_ALL_GENERATED))
161ifdef need_compile_java
162
Colin Crosse8ee68b2017-04-07 16:28:41 -0700163annotation_processor_flags :=
164annotation_processor_deps :=
165
166ifdef LOCAL_ANNOTATION_PROCESSORS
Nan Zhang9bd54052017-09-13 13:13:53 -0700167 annotation_processor_jars := $(call java-lib-files,$(LOCAL_ANNOTATION_PROCESSORS),true)
Colin Crosse8ee68b2017-04-07 16:28:41 -0700168 annotation_processor_flags += -processorpath $(call normalize-path-list,$(annotation_processor_jars))
169 annotation_processor_deps += $(annotation_processor_jars)
170
171 # b/25860419: annotation processors must be explicitly specified for grok
172 annotation_processor_flags += $(foreach class,$(LOCAL_ANNOTATION_PROCESSOR_CLASSES),-processor $(class))
173
174 annotation_processor_jars :=
175endif
176
Ying Wang956dccc2015-08-28 11:47:03 -0700177full_static_java_libs := \
178 $(foreach lib,$(LOCAL_STATIC_JAVA_LIBRARIES), \
179 $(call intermediates-dir-for, \
Colin Cross941b6822017-03-29 13:53:29 -0700180 JAVA_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),COMMON)/classes.jar)
Ying Wang956dccc2015-08-28 11:47:03 -0700181
Nan Zhangb3ec5342017-08-31 21:43:04 +0000182full_static_java_header_libs := \
183 $(foreach lib,$(LOCAL_STATIC_JAVA_LIBRARIES), \
184 $(call intermediates-dir-for, \
185 JAVA_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),COMMON)/classes-header.jar)
186
Ying Wang956dccc2015-08-28 11:47:03 -0700187$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_STATIC_JAVA_LIBRARIES := $(full_static_java_libs)
Nan Zhangb3ec5342017-08-31 21:43:04 +0000188$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_STATIC_JAVA_HEADER_LIBRARIES := $(full_static_java_header_libs)
Ying Wang956dccc2015-08-28 11:47:03 -0700189
190$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
191$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR := $(LOCAL_ASSET_DIR)
192
193$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CLASS_INTERMEDIATES_DIR := $(intermediates.COMMON)/classes
Colin Crosse8ee68b2017-04-07 16:28:41 -0700194$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ANNO_INTERMEDIATES_DIR := $(intermediates.COMMON)/anno
Ying Wang956dccc2015-08-28 11:47:03 -0700195$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/src
Dan Willemsencf324af2016-12-21 17:37:00 -0800196$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HAS_PROTO_SOURCES := $(if $(proto_sources),true)
197$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PROTO_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/proto
198$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HAS_RS_SOURCES :=
Ying Wang956dccc2015-08-28 11:47:03 -0700199$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAVA_SOURCES := $(all_java_sources)
Colin Crossdfc45ec2017-05-26 15:22:02 -0700200$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAVA_SOURCE_LIST := $(java_source_list_file)
Ying Wang956dccc2015-08-28 11:47:03 -0700201
202$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RMTYPEDEFS := $(LOCAL_RMTYPEDEFS)
203
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700204full_java_bootclasspath_libs :=
205empty_bootclasspath :=
206
Ying Wang956dccc2015-08-28 11:47:03 -0700207# full_java_libs: The list of files that should be used as the classpath.
208# Using this list as a dependency list WILL NOT WORK.
Ying Wang956dccc2015-08-28 11:47:03 -0700209ifndef LOCAL_IS_HOST_MODULE
Colin Crossf6bc1a12017-09-23 19:47:37 -0700210 ifeq ($(LOCAL_SDK_VERSION),)
211 ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
212 # No bootclasspath. But we still need "" to prevent javac from using default host bootclasspath.
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700213 empty_bootclasspath := ""
Colin Crossf6bc1a12017-09-23 19:47:37 -0700214 else # LOCAL_NO_STANDARD_LIBRARIES
Colin Crossb541aae2017-09-23 19:52:43 -0700215 full_java_bootclasspath_libs := $(call java-lib-header-files,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES))
Colin Crossf6bc1a12017-09-23 19:47:37 -0700216 endif # LOCAL_NO_STANDARD_LIBRARIES
217 else
Colin Crossb541aae2017-09-23 19:52:43 -0700218 ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
219 $(call pretty-error,Must not define both LOCAL_NO_STANDARD_LIBRARIES and LOCAL_SDK_VERSION)
220 endif
221 ifeq ($(strip $(filter $(LOCAL_SDK_VERSION),$(TARGET_AVAILABLE_SDK_VERSIONS))),)
222 $(call pretty-error,Invalid LOCAL_SDK_VERSION '$(LOCAL_SDK_VERSION)' \
223 Choices are: $(TARGET_AVAILABLE_SDK_VERSIONS))
224 endif
Colin Crossf6bc1a12017-09-23 19:47:37 -0700225 ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),current)
226 # LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS.
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700227 full_java_bootclasspath_libs := $(call java-lib-header-files,android_stubs_current)
Colin Crossf6bc1a12017-09-23 19:47:37 -0700228 else ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),system_current)
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700229 full_java_bootclasspath_libs := $(call java-lib-header-files,android_system_stubs_current)
Colin Crossf6bc1a12017-09-23 19:47:37 -0700230 else ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),test_current)
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700231 full_java_bootclasspath_libs := $(call java-lib-header-files,android_test_stubs_current)
Colin Crossf6bc1a12017-09-23 19:47:37 -0700232 else
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700233 full_java_bootclasspath_libs := $(call java-lib-header-files,sdk_v$(LOCAL_SDK_VERSION))
Colin Crossf6bc1a12017-09-23 19:47:37 -0700234 endif # current, system_current, or test_current
235 endif # LOCAL_SDK_VERSION
Ying Wang956dccc2015-08-28 11:47:03 -0700236
Colin Crossf6bc1a12017-09-23 19:47:37 -0700237 # In order to compile lambda code javac requires various invokedynamic-
238 # related classes to be present. This change adds stubs needed for
239 # javac to compile lambdas.
240 my_additional_javac_libs :=
241 ifndef TARGET_BUILD_APPS
242 # TODO: support to build lamdbas using javac in unbundled build.
243 # We may need to check in a prebuilt core-lambda-stubs to prebuilts/sdk.
244 ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
245 my_additional_javac_libs := core-lambda-stubs
246 endif
247 endif
Neil Fullerb08544e2016-02-19 10:37:22 +0000248
Colin Crossf6bc1a12017-09-23 19:47:37 -0700249 full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES) $(my_additional_javac_libs),$(LOCAL_IS_HOST_MODULE))
250 full_shared_java_header_libs := $(call java-lib-header-files,$(LOCAL_JAVA_LIBRARIES) $(my_additional_javac_libs),$(LOCAL_IS_HOST_MODULE))
Ying Wang956dccc2015-08-28 11:47:03 -0700251
252else # LOCAL_IS_HOST_MODULE
253
Colin Crossf6bc1a12017-09-23 19:47:37 -0700254 ifeq ($(USE_CORE_LIB_BOOTCLASSPATH),true)
255 ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700256 empty_bootclasspath := ""
Colin Crossf6bc1a12017-09-23 19:47:37 -0700257 else
Colin Crossb541aae2017-09-23 19:52:43 -0700258 full_java_bootclasspath_libs := $(call java-lib-header-files,$(addsuffix -hostdex,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES)),true)
Colin Crossf6bc1a12017-09-23 19:47:37 -0700259 endif
Ying Wang956dccc2015-08-28 11:47:03 -0700260
Colin Crossf6bc1a12017-09-23 19:47:37 -0700261 full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),true)
262 full_shared_java_header_libs := $(call java-lib-header-files,$(LOCAL_JAVA_LIBRARIES),true)
263 else # !USE_CORE_LIB_BOOTCLASSPATH
Ying Wang956dccc2015-08-28 11:47:03 -0700264
Colin Crossf6bc1a12017-09-23 19:47:37 -0700265 full_shared_java_libs := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/,\
266 $(addsuffix $(COMMON_JAVA_PACKAGE_SUFFIX),$(LOCAL_JAVA_LIBRARIES)))
267 endif # USE_CORE_LIB_BOOTCLASSPATH
Ying Wang956dccc2015-08-28 11:47:03 -0700268endif # !LOCAL_IS_HOST_MODULE
269
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700270ifdef empty_bootclasspath
271 ifdef full_java_bootclasspath_libs
272 $(call pretty-error,internal error: empty_bootclasspath and full_java_bootclasspath_libs should not both be set)
273 endif
274endif
275
Colin Crossb541aae2017-09-23 19:52:43 -0700276$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := $(full_java_bootclasspath_libs)
277$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EMPTY_BOOTCLASSPATH := $(empty_bootclasspath)
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700278
Ying Wang956dccc2015-08-28 11:47:03 -0700279full_java_libs := $(full_shared_java_libs) $(full_static_java_libs) $(LOCAL_CLASSPATH)
Nan Zhangb3ec5342017-08-31 21:43:04 +0000280full_java_header_libs := $(full_shared_java_header_libs) $(full_static_java_header_libs)
281
Ying Wang956dccc2015-08-28 11:47:03 -0700282ifndef LOCAL_IS_HOST_MODULE
283# This is set by packages that are linking to other packages that export
284# shared libraries, allowing them to make use of the code in the linked apk.
285apk_libraries := $(sort $(LOCAL_APK_LIBRARIES) $(LOCAL_RES_LIBRARIES))
286ifneq ($(apk_libraries),)
287 link_apk_libraries := \
288 $(foreach lib,$(apk_libraries), \
289 $(call intermediates-dir-for, \
Colin Cross950f1ef2017-04-05 15:30:42 -0700290 APPS,$(lib),,COMMON)/classes-pre-proguard.jar)
Nan Zhang9bd54052017-09-13 13:13:53 -0700291 link_apk_header_libs := \
292 $(foreach lib,$(apk_libraries), \
293 $(call intermediates-dir-for, \
294 APPS,$(lib),,COMMON)/classes-header.jar)
Ying Wang956dccc2015-08-28 11:47:03 -0700295
296 # link against the jar with full original names (before proguard processing).
297 full_shared_java_libs += $(link_apk_libraries)
298 full_java_libs += $(link_apk_libraries)
Nan Zhang9bd54052017-09-13 13:13:53 -0700299 full_java_header_libs += $(link_apk_header_libs)
Ying Wang956dccc2015-08-28 11:47:03 -0700300endif
301
302# This is set by packages that contain instrumentation, allowing them to
303# link against the package they are instrumenting. Currently only one such
304# package is allowed.
305LOCAL_INSTRUMENTATION_FOR := $(strip $(LOCAL_INSTRUMENTATION_FOR))
306ifdef LOCAL_INSTRUMENTATION_FOR
307 ifneq ($(words $(LOCAL_INSTRUMENTATION_FOR)),1)
308 $(error \
309 $(LOCAL_PATH): Multiple LOCAL_INSTRUMENTATION_FOR members defined)
310 endif
311
312 link_instr_intermediates_dir.COMMON := $(call intermediates-dir-for, \
313 APPS,$(LOCAL_INSTRUMENTATION_FOR),,COMMON)
314 # link against the jar with full original names (before proguard processing).
Colin Cross950f1ef2017-04-05 15:30:42 -0700315 link_instr_classes_jar := $(link_instr_intermediates_dir.COMMON)/classes-pre-proguard.jar
Nan Zhang9bd54052017-09-13 13:13:53 -0700316 link_instr_classes_header_jar := $(link_instr_intermediates_dir.COMMON)/classes-header.jar
Ying Wang956dccc2015-08-28 11:47:03 -0700317 full_java_libs += $(link_instr_classes_jar)
Nan Zhang9bd54052017-09-13 13:13:53 -0700318 full_java_header_libs += $(link_instr_classes_header_jar)
Ying Wang956dccc2015-08-28 11:47:03 -0700319endif # LOCAL_INSTRUMENTATION_FOR
320endif # LOCAL_IS_HOST_MODULE
321
322endif # need_compile_java
323
324# We may want to add jar manifest or jar resource files even if there is no java code at all.
325$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EXTRA_JAR_ARGS := $(extra_jar_args)
326jar_manifest_file :=
327ifneq ($(strip $(LOCAL_JAR_MANIFEST)),)
328jar_manifest_file := $(LOCAL_PATH)/$(LOCAL_JAR_MANIFEST)
329$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAR_MANIFEST := $(jar_manifest_file)
330else
331$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAR_MANIFEST :=
332endif
333
334##########################################################
335ifndef LOCAL_IS_HOST_MODULE
336## AAPT Flags
337# aapt doesn't accept multiple --extra-packages flags.
338# We have to collapse them into a single --extra-packages flag here.
339LOCAL_AAPT_FLAGS := $(strip $(LOCAL_AAPT_FLAGS))
340ifdef LOCAL_AAPT_FLAGS
341ifeq ($(filter 0 1,$(words $(filter --extra-packages,$(LOCAL_AAPT_FLAGS)))),)
342aapt_flags := $(subst --extra-packages$(space),--extra-packages@,$(LOCAL_AAPT_FLAGS))
343aapt_flags_extra_packages := $(patsubst --extra-packages@%,%,$(filter --extra-packages@%,$(aapt_flags)))
344aapt_flags_extra_packages := $(sort $(subst :,$(space),$(aapt_flags_extra_packages)))
345LOCAL_AAPT_FLAGS := $(filter-out --extra-packages@%,$(aapt_flags)) \
346 --extra-packages $(subst $(space),:,$(aapt_flags_extra_packages))
347aapt_flags_extra_packages :=
348aapt_flags :=
349endif
350endif
351
Ying Wang6f9bd2a2016-03-29 12:41:42 -0700352$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) $(PRODUCT_AAPT_FLAGS)
353$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_AAPT_CHARACTERISTICS := $(TARGET_AAPT_CHARACTERISTICS)
354$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_PACKAGE_NAME := $(LOCAL_MANIFEST_PACKAGE_NAME)
355$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_INSTRUMENTATION_FOR := $(LOCAL_MANIFEST_INSTRUMENTATION_FOR)
Ying Wang956dccc2015-08-28 11:47:03 -0700356
Ying Wang956dccc2015-08-28 11:47:03 -0700357ifdef aidl_sources
358ALL_MODULES.$(my_register_name).AIDL_FILES := $(aidl_sources)
359endif
Ying Wangd5ffec92016-03-01 22:05:25 -0800360ifdef renderscript_sources
361ALL_MODULES.$(my_register_name).RS_FILES := $(renderscript_sources_fullpath)
362endif
Ying Wang956dccc2015-08-28 11:47:03 -0700363endif # !LOCAL_IS_HOST_MODULE
364
Ying Wang6f9bd2a2016-03-29 12:41:42 -0700365$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_JAVA_LIBRARIES := $(full_java_libs)
Nan Zhangb3ec5342017-08-31 21:43:04 +0000366$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_JAVA_HEADER_LIBRARIES := $(full_java_header_libs)
Ying Wang956dccc2015-08-28 11:47:03 -0700367
368ALL_MODULES.$(my_register_name).INTERMEDIATE_SOURCE_DIR := \
369 $(ALL_MODULES.$(my_register_name).INTERMEDIATE_SOURCE_DIR) $(LOCAL_INTERMEDIATE_SOURCE_DIR)
370
371###########################################################
372# JACK
373###########################################################
Colin Cross79e2f732016-12-21 14:29:13 -0800374ifdef LOCAL_JACK_ENABLED
Ying Wang956dccc2015-08-28 11:47:03 -0700375ifdef need_compile_java
376
Neil Fullerad022512016-01-29 14:22:29 +0000377LOCAL_JACK_FLAGS += -D jack.java.source.version=$(LOCAL_JAVA_LANGUAGE_VERSION)
378
Ying Wang956dccc2015-08-28 11:47:03 -0700379full_static_jack_libs := \
380 $(foreach lib,$(LOCAL_STATIC_JAVA_LIBRARIES), \
381 $(call intermediates-dir-for, \
382 JAVA_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),COMMON)/classes.jack)
383
384$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_STATIC_JACK_LIBRARIES := $(full_static_jack_libs)
Ying Wang956dccc2015-08-28 11:47:03 -0700385
Ying Wang956dccc2015-08-28 11:47:03 -0700386full_shared_jack_libs := $(call jack-lib-files,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
Colin Crossb541aae2017-09-23 19:52:43 -0700387ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
388 my_jack_bootclasspath := $(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES)
389 ifdef LOCAL_IS_HOST_MODULE
390 my_jack_bootclasspath := $(addsuffix -hostdex,$(my_jack_bootclasspath))
391 endif
392 full_shared_jack_libs := $(call jack-lib-files,$(my_jack_bootclasspath),$(LOCAL_IS_HOST_MODULE)) $(full_shared_jack_libs)
393endif
Yohann Rousselae2fc812016-04-21 16:49:10 +0200394full_jack_deps := $(full_shared_jack_libs)
395
396ifndef LOCAL_IS_HOST_MODULE
Shinichiro Hamajif972a4a2015-12-09 18:06:20 +0900397# Turn off .toc optimization for apps build as we cannot build dexdump.
398ifeq (,$(TARGET_BUILD_APPS))
Yohann Rousselb7de0fb2015-11-03 18:33:21 +0100399full_jack_deps := $(patsubst %.jack, %.dex.toc, $(full_jack_deps))
Shinichiro Hamajif972a4a2015-12-09 18:06:20 +0900400endif
Ying Wang956dccc2015-08-28 11:47:03 -0700401endif # !LOCAL_IS_HOST_MODULE
Yohann Roussel2dc79b12016-04-21 16:30:18 +0200402full_shared_jack_libs += $(LOCAL_JACK_CLASSPATH)
Yohann Rousselb7de0fb2015-11-03 18:33:21 +0100403full_jack_deps += $(full_static_jack_libs) $(LOCAL_JACK_CLASSPATH)
Ying Wang956dccc2015-08-28 11:47:03 -0700404
405ifndef LOCAL_IS_HOST_MODULE
406# This is set by packages that are linking to other packages that export
407# shared libraries, allowing them to make use of the code in the linked apk.
408ifneq ($(apk_libraries),)
409 link_apk_jack_libraries := \
410 $(foreach lib,$(apk_libraries), \
411 $(call intermediates-dir-for, \
412 APPS,$(lib),,COMMON)/classes.jack)
413
414 # link against the jar with full original names (before proguard processing).
415 full_shared_jack_libs += $(link_apk_jack_libraries)
Yohann Rousselb7de0fb2015-11-03 18:33:21 +0100416 full_jack_deps += $(link_apk_jack_libraries)
Ying Wang956dccc2015-08-28 11:47:03 -0700417endif
418
419# This is set by packages that contain instrumentation, allowing them to
420# link against the package they are instrumenting. Currently only one such
421# package is allowed.
422ifdef LOCAL_INSTRUMENTATION_FOR
423 # link against the jar with full original names (before proguard processing).
424 link_instr_classes_jack := $(link_instr_intermediates_dir.COMMON)/classes.noshrob.jack
Yohann Roussel2dc79b12016-04-21 16:30:18 +0200425 full_shared_jack_libs += $(link_instr_classes_jack)
Yohann Rousselb7de0fb2015-11-03 18:33:21 +0100426 full_jack_deps += $(link_instr_classes_jack)
Ying Wang956dccc2015-08-28 11:47:03 -0700427endif # LOCAL_INSTRUMENTATION_FOR
428endif # !LOCAL_IS_HOST_MODULE
429
430# Propagate local configuration options to this target.
Yohann Rousselb6232d92016-04-22 18:45:45 +0200431$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_SHARED_LIBRARIES:= $(full_shared_jack_libs)
Ying Wang6f9bd2a2016-03-29 12:41:42 -0700432$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
Ying Wang956dccc2015-08-28 11:47:03 -0700433
434endif # need_compile_java
Colin Cross79e2f732016-12-21 14:29:13 -0800435endif # LOCAL_JACK_ENABLED
Dan Willemsen62dfb592016-07-08 21:33:05 -0700436
437
438###########################################################
439# Verify that all libraries are safe to use
440###########################################################
441ifndef LOCAL_IS_HOST_MODULE
Dan Willemsen62dfb592016-07-08 21:33:05 -0700442ifeq ($(LOCAL_SDK_VERSION),system_current)
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700443my_link_type := java:system
444my_warn_types := java:platform
445my_allowed_types := java:sdk java:system
Dan Willemsen62dfb592016-07-08 21:33:05 -0700446else ifneq ($(LOCAL_SDK_VERSION),)
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700447my_link_type := java:sdk
448my_warn_types := java:system java:platform
449my_allowed_types := java:sdk
Dan Willemsen62dfb592016-07-08 21:33:05 -0700450else
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700451my_link_type := java:platform
452my_warn_types :=
453my_allowed_types := java:sdk java:system java:platform
Dan Willemsen62dfb592016-07-08 21:33:05 -0700454endif
Dan Willemsen62dfb592016-07-08 21:33:05 -0700455
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700456my_link_deps := $(addprefix JAVA_LIBRARIES:,$(LOCAL_STATIC_JAVA_LIBRARIES))
457my_link_deps += $(addprefix APPS:,$(apk_libraries))
458
459my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
460my_common := COMMON
461include $(BUILD_SYSTEM)/link_type.mk
Dan Willemsen62dfb592016-07-08 21:33:05 -0700462endif # !LOCAL_IS_HOST_MODULE