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