• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Target Java.
2# Requires:
3# LOCAL_MODULE_SUFFIX
4# LOCAL_MODULE_CLASS
5# all_res_assets
6
7LOCAL_NO_STANDARD_LIBRARIES:=$(strip $(LOCAL_NO_STANDARD_LIBRARIES))
8LOCAL_SDK_VERSION:=$(strip $(LOCAL_SDK_VERSION))
9
10proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
11ifneq ($(proto_sources),)
12ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro)
13    LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-micro
14else
15  ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nano)
16    LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-nano
17  else
18    ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),stream)
19      # No library for stream protobufs
20    else
21      LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-lite
22    endif
23  endif
24endif
25endif
26
27# LOCAL_STATIC_JAVA_AAR_LIBRARIES and LOCAL_STATIC_ANDROID_LIBRARIES are also LOCAL_STATIC_JAVA_LIBRARIES.
28LOCAL_STATIC_JAVA_LIBRARIES := $(strip $(LOCAL_STATIC_JAVA_LIBRARIES) \
29    $(LOCAL_STATIC_JAVA_AAR_LIBRARIES) \
30    $(LOCAL_STATIC_ANDROID_LIBRARIES))
31# LOCAL_SHARED_ANDROID_LIBRARIES are also LOCAL_JAVA_LIBRARIES.
32LOCAL_JAVA_LIBRARIES := $(sort $(LOCAL_JAVA_LIBRARIES) $(LOCAL_SHARED_ANDROID_LIBRARIES))
33
34LOCAL_BUILT_MODULE_STEM := $(strip $(LOCAL_BUILT_MODULE_STEM))
35ifeq ($(LOCAL_BUILT_MODULE_STEM),)
36$(error $(LOCAL_PATH): Target java template must define LOCAL_BUILT_MODULE_STEM)
37endif
38ifneq ($(filter classes-compiled.jar classes.jar,$(LOCAL_BUILT_MODULE_STEM)),)
39$(error LOCAL_BUILT_MODULE_STEM may not be "$(LOCAL_BUILT_MODULE_STEM)")
40endif
41
42
43##############################################################################
44# Define the intermediate targets before including base_rules so they get
45# the correct environment.
46##############################################################################
47
48intermediates := $(call local-intermediates-dir)
49intermediates.COMMON := $(call local-intermediates-dir,COMMON)
50
51ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
52LOCAL_PROGUARD_ENABLED :=
53endif
54
55full_classes_turbine_jar := $(intermediates.COMMON)/classes-turbine.jar
56full_classes_header_jarjar := $(intermediates.COMMON)/classes-header-jarjar.jar
57full_classes_header_jar := $(intermediates.COMMON)/classes-header.jar
58full_classes_compiled_jar := $(intermediates.COMMON)/classes-full-debug.jar
59full_classes_processed_jar := $(intermediates.COMMON)/classes-processed.jar
60full_classes_jarjar_jar := $(intermediates.COMMON)/classes-jarjar.jar
61full_classes_combined_jar := $(intermediates.COMMON)/classes-combined.jar
62built_dex_intermediate := $(intermediates.COMMON)/dex/classes.dex
63full_classes_stubs_jar := $(intermediates.COMMON)/stubs.jar
64java_source_list_file := $(intermediates.COMMON)/java-source-list
65
66ifeq ($(LOCAL_MODULE_CLASS)$(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),APPS)
67# If this is an apk without any Java code (e.g. framework-res), we should skip compiling Java.
68full_classes_jar :=
69built_dex :=
70else
71full_classes_jar := $(intermediates.COMMON)/classes.jar
72built_dex := $(intermediates.COMMON)/classes.dex
73endif
74
75LOCAL_INTERMEDIATE_TARGETS += \
76    $(full_classes_turbine_jar) \
77    $(full_classes_compiled_jar) \
78    $(full_classes_jarjar_jar) \
79    $(full_classes_jar) \
80    $(full_classes_combined_jar) \
81    $(built_dex_intermediate) \
82    $(built_dex) \
83    $(full_classes_stubs_jar) \
84    $(java_source_list_file)
85
86LOCAL_INTERMEDIATE_SOURCE_DIR := $(intermediates.COMMON)/src
87
88###########################################################
89## AIDL: Compile .aidl files to .java
90###########################################################
91aidl_sources := $(filter %.aidl,$(LOCAL_SRC_FILES))
92aidl_java_sources :=
93
94ifneq ($(strip $(aidl_sources)),)
95
96aidl_preprocess_import :=
97ifdef LOCAL_SDK_VERSION
98ifneq ($(filter current system_current test_current core_current, $(LOCAL_SDK_VERSION)$(TARGET_BUILD_USE_PREBUILT_SDKS)),)
99  # LOCAL_SDK_VERSION is current and no TARGET_BUILD_USE_PREBUILT_SDKS
100  aidl_preprocess_import := $(FRAMEWORK_AIDL)
101else
102  aidl_preprocess_import := $(call resolve-prebuilt-sdk-aidl-path,$(LOCAL_SDK_VERSION))
103endif # not current or system_current
104else
105# build against the platform.
106LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)
107endif # LOCAL_SDK_VERSION
108
109$(foreach s,$(aidl_sources),\
110    $(eval $(call define-aidl-java-rule,$(s),$(intermediates.COMMON)/aidl,aidl_java_sources)))
111$(foreach java,$(aidl_java_sources), \
112    $(call include-depfile,$(java:%.java=%.P),$(java)))
113
114$(aidl_java_sources) : $(LOCAL_ADDITIONAL_DEPENDENCIES) $(aidl_preprocess_import)
115
116$(aidl_java_sources): PRIVATE_AIDL_FLAGS := $(addprefix -p,$(aidl_preprocess_import)) -I$(LOCAL_PATH) -I$(LOCAL_PATH)/src $(addprefix -I,$(LOCAL_AIDL_INCLUDES))
117$(aidl_java_sources): PRIVATE_MODULE := $(LOCAL_MODULE)
118
119endif
120
121##########################################
122
123# All of the rules after full_classes_compiled_jar are very unlikely
124# to fail except for bugs in their respective tools.  If you would
125# like to run these rules, add the "all" modifier goal to the make
126# command line.
127ifndef LOCAL_CHECKED_MODULE
128ifdef full_classes_jar
129LOCAL_CHECKED_MODULE := $(full_classes_compiled_jar)
130endif
131endif
132
133#######################################
134include $(BUILD_SYSTEM)/base_rules.mk
135#######################################
136
137###########################################################
138## logtags: emit java source
139###########################################################
140ifneq ($(strip $(logtags_sources)),)
141
142logtags_java_sources := $(patsubst %.logtags,%.java,$(addprefix $(intermediates.COMMON)/logtags/, $(logtags_sources)))
143logtags_sources := $(addprefix $(LOCAL_PATH)/, $(logtags_sources))
144
145$(logtags_java_sources): PRIVATE_MERGED_TAG := $(TARGET_OUT_COMMON_INTERMEDIATES)/all-event-log-tags.txt
146$(logtags_java_sources): $(intermediates.COMMON)/logtags/%.java: $(LOCAL_PATH)/%.logtags $(TARGET_OUT_COMMON_INTERMEDIATES)/all-event-log-tags.txt $(JAVATAGS) build/make/tools/event_log_tags.py
147	$(transform-logtags-to-java)
148
149else
150logtags_java_sources :=
151endif
152
153##########################################
154java_sources := $(addprefix $(LOCAL_PATH)/, $(filter %.java,$(LOCAL_SRC_FILES))) $(aidl_java_sources) $(logtags_java_sources) \
155                $(filter %.java,$(LOCAL_GENERATED_SOURCES))
156java_intermediate_sources := $(addprefix $(TARGET_OUT_COMMON_INTERMEDIATES)/, $(filter %.java,$(LOCAL_INTERMEDIATE_SOURCES)))
157all_java_sources := $(java_sources) $(java_intermediate_sources)
158ALL_MODULES.$(my_register_name).SRCS := $(ALL_MODULES.$(my_register_name).SRCS) $(all_java_sources)
159
160include $(BUILD_SYSTEM)/java_common.mk
161
162include $(BUILD_SYSTEM)/sdk_check.mk
163
164# Set the profile source so that the odex / profile code included from java.mk
165# can find it.
166#
167# TODO: b/64896089, this is broken when called from package_internal.mk, since the file
168# we preopt from is a temporary file. This will be addressed in a follow up, possibly
169# by disabling stripping for profile guided preopt (which may be desirable for other
170# reasons anyway).
171#
172# Note that we set this only when called from package_internal.mk and not in other cases.
173ifneq (,$(called_from_package_internal)
174dex_preopt_profile_src_file := $(LOCAL_BUILT_MODULE)
175endif
176
177#######################################
178# defines built_odex along with rule to install odex
179my_manifest_or_apk := $(full_android_manifest)
180include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
181my_manifest_or_apk :=
182#######################################
183
184# Make sure there's something to build.
185ifdef full_classes_jar
186ifndef need_compile_java
187$(call pretty-error,Target java module does not define any source or resource files)
188endif
189endif
190
191# Since we're using intermediates.COMMON, make sure that it gets cleaned
192# properly.
193$(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON)
194
195ifdef full_classes_jar
196
197# Droiddoc isn't currently able to generate stubs for modules, so we're just
198# allowing it to use the classes.jar as the "stubs" that would be use to link
199# against, for the cases where someone needs the jar to link against.
200$(eval $(call copy-one-file,$(full_classes_jar),$(full_classes_stubs_jar)))
201ALL_MODULES.$(my_register_name).STUBS := $(full_classes_stubs_jar)
202
203# The layers file allows you to enforce a layering between java packages.
204# Run build/make/tools/java-layers.py for more details.
205layers_file := $(addprefix $(LOCAL_PATH)/, $(LOCAL_JAVA_LAYERS_FILE))
206$(full_classes_compiled_jar): PRIVATE_JAVA_LAYERS_FILE := $(layers_file)
207$(full_classes_compiled_jar): PRIVATE_WARNINGS_ENABLE := $(LOCAL_WARNINGS_ENABLE)
208
209# Compile the java files to a .jar file.
210# This intentionally depends on java_sources, not all_java_sources.
211# Deps for generated source files must be handled separately,
212# via deps on the target that generates the sources.
213
214# For user / userdebug builds, strip the local variable table and the local variable
215# type table. This has no bearing on stack traces, but will leave less information
216# available via JDWP.
217ifneq (,$(PRODUCT_MINIMIZE_JAVA_DEBUG_INFO))
218ifneq (,$(filter userdebug user,$(TARGET_BUILD_VARIANT)))
219LOCAL_JAVACFLAGS+= -g:source,lines
220endif
221endif
222
223# List of dependencies for anything that needs all java sources in place
224java_sources_deps := \
225    $(java_sources) \
226    $(java_resource_sources) \
227    $(LOCAL_SRCJARS) \
228    $(LOCAL_ADDITIONAL_DEPENDENCIES)
229
230$(java_source_list_file): $(java_sources_deps) $(NORMALIZE_PATH)
231	$(write-java-source-list)
232
233ALL_MODULES.$(my_register_name).SRCJARS := $(LOCAL_SRCJARS)
234
235ifneq ($(TURBINE_ENABLED),false)
236
237$(full_classes_turbine_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) $(annotation_processor_flags)
238$(full_classes_turbine_jar): PRIVATE_SRCJARS := $(LOCAL_SRCJARS)
239$(full_classes_turbine_jar): \
240    $(java_source_list_file) \
241    $(java_sources_deps) \
242    $(full_java_header_libs) \
243    $(full_java_bootclasspath_libs) \
244    $(full_java_system_modules_deps) \
245    $(NORMALIZE_PATH) \
246    $(JAR_ARGS) \
247    $(ZIPTIME) \
248    | $(TURBINE) \
249    $(MERGE_ZIPS)
250	$(transform-java-to-header.jar)
251
252.KATI_RESTAT: $(full_classes_turbine_jar)
253
254# Run jarjar before generate classes-header.jar if necessary.
255ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
256$(full_classes_header_jarjar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
257$(full_classes_header_jarjar): $(full_classes_turbine_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
258	$(call transform-jarjar)
259else
260full_classes_header_jarjar := $(full_classes_turbine_jar)
261endif
262
263$(eval $(call copy-one-file,$(full_classes_header_jarjar),$(full_classes_header_jar)))
264
265endif # TURBINE_ENABLED != false
266
267# TODO(b/143658984): goma can't handle the --system argument to javac.
268#$(full_classes_compiled_jar): .KATI_NINJA_POOL := $(GOMA_POOL)
269$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) $(annotation_processor_flags)
270$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES := $(LOCAL_JAR_EXCLUDE_FILES)
271$(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES := $(LOCAL_JAR_PACKAGES)
272$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_PACKAGES := $(LOCAL_JAR_EXCLUDE_PACKAGES)
273$(full_classes_compiled_jar): PRIVATE_JAVA_SOURCE_LIST := $(java_source_list_file)
274$(full_classes_compiled_jar): PRIVATE_ALL_JAVA_HEADER_LIBRARIES := $(full_java_header_libs)
275$(full_classes_compiled_jar): PRIVATE_SRCJARS := $(LOCAL_SRCJARS)
276$(full_classes_compiled_jar): PRIVATE_SRCJAR_LIST_FILE := $(intermediates.COMMON)/srcjar-list
277$(full_classes_compiled_jar): PRIVATE_SRCJAR_INTERMEDIATES_DIR := $(intermediates.COMMON)/srcjars
278$(full_classes_compiled_jar): \
279    $(java_source_list_file) \
280    $(full_java_header_libs) \
281    $(java_sources_deps) \
282    $(full_java_bootclasspath_libs) \
283    $(full_java_system_modules_deps) \
284    $(layers_file) \
285    $(annotation_processor_deps) \
286    $(NORMALIZE_PATH) \
287    $(JAR_ARGS) \
288    $(ZIPSYNC) \
289    $(SOONG_ZIP) \
290    | $(SOONG_JAVAC_WRAPPER)
291	@echo "Target Java: $@
292	$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_ALL_JAVA_HEADER_LIBRARIES))
293
294javac-check : $(full_classes_compiled_jar)
295javac-check-$(LOCAL_MODULE) : $(full_classes_compiled_jar)
296.PHONY: javac-check-$(LOCAL_MODULE)
297
298$(full_classes_combined_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
299$(full_classes_combined_jar): $(full_classes_compiled_jar) \
300                              $(jar_manifest_file) \
301                              $(full_static_java_libs) | $(MERGE_ZIPS)
302	$(if $(PRIVATE_JAR_MANIFEST), $(hide) sed -e "s/%BUILD_NUMBER%/$(BUILD_NUMBER_FROM_FILE)/" \
303            $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf)
304	$(MERGE_ZIPS) -j --ignore-duplicates $(if $(PRIVATE_JAR_MANIFEST),-m $(dir $@)/manifest.mf) \
305            $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,-stripDir META-INF -zipToNotStrip $<) \
306            $@ $< $(PRIVATE_STATIC_JAVA_LIBRARIES)
307
308ifdef LOCAL_JAR_PROCESSOR
309# LOCAL_JAR_PROCESSOR_ARGS must be evaluated here to set up the rule-local
310# PRIVATE_JAR_PROCESSOR_ARGS variable, but $< and $@ are not available yet.
311# Set ${in} and ${out} so they can be referenced by LOCAL_JAR_PROCESSOR_ARGS
312# using deferred evaluation (LOCAL_JAR_PROCESSOR_ARGS = instead of :=).
313in := $(full_classes_combined_jar)
314out := $(full_classes_processed_jar).tmp
315my_jar_processor := $(HOST_OUT_JAVA_LIBRARIES)/$(LOCAL_JAR_PROCESSOR).jar
316
317$(full_classes_processed_jar): PRIVATE_JAR_PROCESSOR_ARGS := $(LOCAL_JAR_PROCESSOR_ARGS)
318$(full_classes_processed_jar): PRIVATE_JAR_PROCESSOR := $(my_jar_processor)
319$(full_classes_processed_jar): PRIVATE_TMP_OUT := $(out)
320in :=
321out :=
322
323$(full_classes_processed_jar): $(full_classes_combined_jar) $(my_jar_processor)
324	@echo Processing $@ with $(PRIVATE_JAR_PROCESSOR)
325	$(hide) rm -f $@ $(PRIVATE_TMP_OUT)
326	$(hide) $(JAVA) -jar $(PRIVATE_JAR_PROCESSOR) $(PRIVATE_JAR_PROCESSOR_ARGS)
327	$(hide) mv $(PRIVATE_TMP_OUT) $@
328
329my_jar_processor :=
330else
331full_classes_processed_jar := $(full_classes_combined_jar)
332endif
333
334# Run jarjar if necessary
335ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
336$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
337$(full_classes_jarjar_jar): $(full_classes_processed_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
338	$(call transform-jarjar)
339else
340full_classes_jarjar_jar := $(full_classes_processed_jar)
341endif
342
343$(eval $(call copy-one-file,$(full_classes_jarjar_jar),$(full_classes_jar)))
344
345#######################################
346LOCAL_FULL_CLASSES_PRE_JACOCO_JAR := $(full_classes_jar)
347
348include $(BUILD_SYSTEM)/jacoco.mk
349#######################################
350
351# Temporarily enable --multi-dex until proguard supports v53 class files
352# ( http://b/67673860 ) or we move away from proguard altogether.
353LOCAL_DX_FLAGS := $(filter-out --multi-dex,$(LOCAL_DX_FLAGS)) --multi-dex
354
355full_classes_pre_proguard_jar := $(LOCAL_FULL_CLASSES_JACOCO_JAR)
356
357# Keep a copy of the jar just before proguard processing.
358$(eval $(call copy-one-file,$(full_classes_pre_proguard_jar),$(intermediates.COMMON)/classes-pre-proguard.jar))
359
360# Run proguard if necessary
361ifdef LOCAL_PROGUARD_ENABLED
362ifneq ($(filter-out full custom obfuscation optimization,$(LOCAL_PROGUARD_ENABLED)),)
363    $(warning while processing: $(LOCAL_MODULE))
364    $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED))
365endif
366proguard_dictionary := $(intermediates.COMMON)/proguard_dictionary
367proguard_configuration := $(intermediates.COMMON)/proguard_configuration
368
369# When an app contains references to APIs that are not in the SDK specified by
370# its LOCAL_SDK_VERSION for example added by support library or by runtime
371# classes added by desugar, we artifically raise the "SDK version" "linked" by
372# ProGuard, to
373# - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version.
374# - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version.
375# See b/20667396
376my_proguard_sdk_raise :=
377ifdef LOCAL_SDK_VERSION
378ifdef TARGET_BUILD_APPS
379ifeq (,$(filter current system_current test_current core_current, $(LOCAL_SDK_VERSION)))
380  my_proguard_sdk_raise := $(call java-lib-header-files, $(call resolve-prebuilt-sdk-module,current))
381endif
382else
383  # For platform build, we can't just raise to the "current" SDK,
384  # that would break apps that use APIs removed from the current SDK.
385  my_proguard_sdk_raise := $(call java-lib-header-files,$(LEGACY_CORE_PLATFORM_BOOTCLASSPATH_LIBRARIES) $(FRAMEWORK_LIBRARIES))
386endif
387ifdef BOARD_SYSTEMSDK_VERSIONS
388ifneq (,$(filter true,$(LOCAL_VENDOR_MODULE) $(LOCAL_ODM_MODULE) $(LOCAL_PROPRIETARY_MODULE)))
389  # But for vendor or odm apks, don't raise SDK as the apks are required to
390  # use SDK APIs only
391  my_proguard_sdk_raise :=
392endif
393endif
394endif
395
396legacy_proguard_flags := $(addprefix -libraryjars ,$(my_proguard_sdk_raise) \
397  $(filter-out $(my_proguard_sdk_raise), \
398    $(full_java_bootclasspath_libs) \
399    $(full_shared_java_header_libs)))
400
401legacy_proguard_lib_deps := $(my_proguard_sdk_raise) \
402  $(filter-out $(my_proguard_sdk_raise),$(full_java_bootclasspath_libs) $(full_shared_java_header_libs))
403
404legacy_proguard_flags += -printmapping $(proguard_dictionary)
405legacy_proguard_flags += -printconfiguration $(proguard_configuration)
406
407common_proguard_flags :=
408common_proguard_flag_files := $(BUILD_SYSTEM)/proguard.flags
409ifneq ($(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS)),)
410common_proguard_flags += -dontshrink # don't shrink tests by default
411endif # test package
412ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
413  common_proguard_flag_files += $(foreach l,$(LOCAL_STATIC_ANDROID_LIBRARIES),\
414      $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/export_proguard_flags)
415endif
416ifneq ($(common_proguard_flag_files),)
417common_proguard_flags += $(addprefix -include , $(common_proguard_flag_files))
418# This is included from $(BUILD_SYSTEM)/proguard.flags
419common_proguard_flag_files += $(BUILD_SYSTEM)/proguard_basic_keeps.flags
420endif
421
422ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
423# By default no obfuscation
424common_proguard_flags += -dontobfuscate
425endif  # No obfuscation
426ifeq ($(filter optimization,$(LOCAL_PROGUARD_ENABLED)),)
427# By default no optimization
428common_proguard_flags += -dontoptimize
429endif  # No optimization
430
431ifdef LOCAL_INSTRUMENTATION_FOR
432ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
433# If no obfuscation, link in the instrmented package's classes.jar as a library.
434# link_instr_classes_jar is defined in base_rule.mk
435legacy_proguard_flags += -libraryjars $(link_instr_classes_jar)
436legacy_proguard_lib_deps += $(link_instr_classes_jar)
437else # obfuscation
438# If obfuscation is enabled, the main app must be obfuscated too.
439# We need to run obfuscation using the main app's dictionary,
440# and treat the main app's class.jar as injars instead of libraryjars.
441legacy_proguard_flags := -injars  $(link_instr_classes_jar) \
442    -outjars $(intermediates.COMMON)/proguard.$(LOCAL_INSTRUMENTATION_FOR).jar \
443    -include $(link_instr_intermediates_dir.COMMON)/proguard_options \
444    -applymapping $(link_instr_intermediates_dir.COMMON)/proguard_dictionary \
445    -verbose \
446    $(legacy_proguard_flags)
447legacy_proguard_lib_deps += \
448  $(link_instr_classes_jar) \
449  $(link_instr_intermediates_dir.COMMON)/proguard_options \
450  $(link_instr_intermediates_dir.COMMON)/proguard_dictionary \
451
452# Sometimes (test + main app) uses different keep rules from the main app -
453# apply the main app's dictionary anyway.
454legacy_proguard_flags += -ignorewarnings
455
456endif # no obfuscation
457endif # LOCAL_INSTRUMENTATION_FOR
458
459proguard_flag_files := $(addprefix $(LOCAL_PATH)/, $(LOCAL_PROGUARD_FLAG_FILES))
460proguard_flag_files += $(addprefix $(LOCAL_PATH)/, $(LOCAL_R8_FLAG_FILES))
461LOCAL_PROGUARD_FLAGS += $(addprefix -include , $(proguard_flag_files))
462LOCAL_PROGUARD_FLAGS_DEPS += $(proguard_flag_files)
463proguard_flag_files :=
464
465ifdef LOCAL_TEST_MODULE_TO_PROGUARD_WITH
466extra_input_jar := $(call intermediates-dir-for,APPS,$(LOCAL_TEST_MODULE_TO_PROGUARD_WITH),,COMMON)/classes.jar
467else
468extra_input_jar :=
469endif
470
471ifneq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
472  $(built_dex_intermediate): .KATI_IMPLICIT_OUTPUTS := $(proguard_dictionary) $(proguard_configuration)
473
474  # Make a rule to copy the proguard_dictionary to a packaging directory.
475  $(eval $(call copy-one-file,$(proguard_dictionary),\
476    $(call local-packaging-dir,proguard_dictionary)/proguard_dictionary))
477  $(call add-dependency,$(LOCAL_BUILT_MODULE),\
478    $(call local-packaging-dir,proguard_dictionary)/proguard_dictionary)
479
480  $(eval $(call copy-one-file,$(full_classes_pre_proguard_jar),\
481    $(call local-packaging-dir,proguard_dictionary)/classes.jar))
482  $(call add-dependency,$(LOCAL_BUILT_MODULE),\
483    $(call local-packaging-dir,proguard_dictionary)/classes.jar)
484endif
485
486endif # LOCAL_PROGUARD_ENABLED defined
487
488ifneq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
489$(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
490
491ifdef LOCAL_PROGUARD_ENABLED
492  $(built_dex_intermediate): PRIVATE_EXTRA_INPUT_JAR := $(extra_input_jar)
493  $(built_dex_intermediate): PRIVATE_PROGUARD_FLAGS := $(legacy_proguard_flags) $(common_proguard_flags) $(LOCAL_PROGUARD_FLAGS)
494  $(built_dex_intermediate): PRIVATE_PROGUARD_DICTIONARY := $(proguard_dictionary)
495  $(built_dex_intermediate) : $(full_classes_pre_proguard_jar) $(extra_input_jar) $(my_proguard_sdk_raise) $(common_proguard_flag_files) $(legacy_proguard_lib_deps) $(R8_COMPAT_PROGUARD) $(LOCAL_PROGUARD_FLAGS_DEPS)
496	$(transform-jar-to-dex-r8)
497else # !LOCAL_PROGUARD_ENABLED
498  $(built_dex_intermediate): PRIVATE_D8_LIBS := $(full_java_bootclasspath_libs) $(full_shared_java_header_libs)
499  $(built_dex_intermediate): $(full_java_bootclasspath_libs) $(full_shared_java_header_libs)
500  $(built_dex_intermediate): $(full_classes_pre_proguard_jar) $(DX) $(ZIP2ZIP)
501	$(transform-classes.jar-to-dex)
502endif
503
504$(foreach pair,$(PRODUCT_BOOT_JARS), \
505  $(if $(filter $(LOCAL_MODULE),$(call word-colon,2,$(pair))), \
506    $(call pretty-error,Modules in PRODUCT_BOOT_JARS must be defined in Android.bp files)))
507
508$(built_dex): $(built_dex_intermediate)
509	@echo Copying: $@
510	$(hide) mkdir -p $(dir $@)
511	$(hide) rm -f $(dir $@)/classes*.dex
512	$(hide) cp -fp $(dir $<)/classes*.dex $(dir $@)
513
514java-dex: $(built_dex)
515
516endif # !LOCAL_IS_STATIC_JAVA_LIBRARY
517
518findbugs_xml := $(intermediates.COMMON)/findbugs.xml
519$(findbugs_xml): PRIVATE_AUXCLASSPATH := $(addprefix -auxclasspath ,$(strip \
520    $(call normalize-path-list,$(filter %.jar,$(full_java_libs)))))
521$(findbugs_xml): PRIVATE_FINDBUGS_FLAGS := $(LOCAL_FINDBUGS_FLAGS)
522$(findbugs_xml) : $(full_classes_pre_proguard_jar) $(filter %.xml, $(LOCAL_FINDBUGS_FLAGS))
523	@echo Findbugs: $@
524	$(hide) $(FINDBUGS) -textui -effort:min -xml:withMessages \
525		$(PRIVATE_AUXCLASSPATH) $(PRIVATE_FINDBUGS_FLAGS) \
526		$< \
527		> $@
528
529ALL_FINDBUGS_FILES += $(findbugs_xml)
530
531findbugs_html := $(PRODUCT_OUT)/findbugs/$(LOCAL_MODULE).html
532$(findbugs_html) : PRIVATE_XML_FILE := $(findbugs_xml)
533$(LOCAL_MODULE)-findbugs : $(findbugs_html)
534.PHONY: $(LOCAL_MODULE)-findbugs
535$(findbugs_html) : $(findbugs_xml)
536	@mkdir -p $(dir $@)
537	@echo ConvertXmlToText: $@
538	$(hide) $(FINDBUGS_DIR)/convertXmlToText -html:fancy.xsl $(PRIVATE_XML_FILE) \
539	> $@
540
541$(LOCAL_MODULE)-findbugs : $(findbugs_html)
542
543endif  # full_classes_jar is defined
544
545$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(call module-target-sdk-version)
546$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SDK_VERSION := $(call module-sdk-version)
547$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MIN_SDK_VERSION := $(call codename-or-sdk-to-sdk,$(call module-min-sdk-version))
548