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