1 # Target Java. 2 # Requires: 3 # LOCAL_MODULE_SUFFIX 4 # LOCAL_MODULE_CLASS 5 # all_res_assets 6 7 ifeq ($(TARGET_BUILD_PDK),true) 8 ifeq ($(TARGET_BUILD_PDK_JAVA_PLATFORM),) 9 # LOCAL_SDK not defined or set to current 10 ifeq ($(filter-out current,$(LOCAL_SDK_VERSION)),) 11 ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 12 LOCAL_SDK_VERSION := $(PDK_BUILD_SDK_VERSION) 13 endif #!LOCAL_NO_STANDARD_LIBRARIES 14 endif 15 endif # !PDK_JAVA 16 endif #PDK 17 18 LOCAL_NO_STANDARD_LIBRARIES:=$(strip $(LOCAL_NO_STANDARD_LIBRARIES)) 19 LOCAL_SDK_VERSION:=$(strip $(LOCAL_SDK_VERSION)) 20 21 proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES)) 22 ifneq ($(proto_sources),) 23 ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro) 24 LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-micro 25 else 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 35 endif 36 endif 37 38 # LOCAL_STATIC_JAVA_AAR_LIBRARIES and LOCAL_STATIC_ANDROID_LIBRARIES are also LOCAL_STATIC_JAVA_LIBRARIES. 39 LOCAL_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. 43 LOCAL_JAVA_LIBRARIES := $(sort $(LOCAL_JAVA_LIBRARIES) $(LOCAL_SHARED_ANDROID_LIBRARIES)) 44 45 LOCAL_BUILT_MODULE_STEM := $(strip $(LOCAL_BUILT_MODULE_STEM)) 46 ifeq ($(LOCAL_BUILT_MODULE_STEM),) 47 $(error $(LOCAL_PATH): Target java template must define LOCAL_BUILT_MODULE_STEM) 48 endif 49 ifneq ($(filter classes-compiled.jar classes.jar,$(LOCAL_BUILT_MODULE_STEM)),) 50 $(error LOCAL_BUILT_MODULE_STEM may not be "$(LOCAL_BUILT_MODULE_STEM)") 51 endif 52 53 54 ############################################################################## 55 # Define the intermediate targets before including base_rules so they get 56 # the correct environment. 57 ############################################################################## 58 59 intermediates := $(call local-intermediates-dir) 60 intermediates.COMMON := $(call local-intermediates-dir,COMMON) 61 62 ifeq ($(LOCAL_PROGUARD_ENABLED),disabled) 63 LOCAL_PROGUARD_ENABLED := 64 endif 65 66 full_classes_turbine_jar := $(intermediates.COMMON)/classes-turbine.jar 67 full_classes_header_jarjar := $(intermediates.COMMON)/classes-header-jarjar.jar 68 full_classes_header_jar := $(intermediates.COMMON)/classes-header.jar 69 full_classes_compiled_jar := $(intermediates.COMMON)/classes-full-debug.jar 70 full_classes_processed_jar := $(intermediates.COMMON)/classes-processed.jar 71 full_classes_desugar_jar := $(intermediates.COMMON)/classes-desugar.jar 72 full_classes_jarjar_jar := $(intermediates.COMMON)/classes-jarjar.jar 73 full_classes_proguard_jar := $(intermediates.COMMON)/classes-proguard.jar 74 full_classes_combined_jar := $(intermediates.COMMON)/classes-combined.jar 75 built_dex_intermediate := $(intermediates.COMMON)/dex/classes.dex 76 built_dex_hiddenapi := $(intermediates.COMMON)/dex-hiddenapi/classes.dex 77 full_classes_stubs_jar := $(intermediates.COMMON)/stubs.jar 78 java_source_list_file := $(intermediates.COMMON)/java-source-list 79 80 81 ifeq ($(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. 83 full_classes_jar := 84 built_dex := 85 else 86 full_classes_jar := $(intermediates.COMMON)/classes.jar 87 built_dex := $(intermediates.COMMON)/classes.dex 88 endif 89 90 LOCAL_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 103 LOCAL_INTERMEDIATE_SOURCE_DIR := $(intermediates.COMMON)/src 104 105 ########################################################### 106 ## AIDL: Compile .aidl files to .java 107 ########################################################### 108 aidl_sources := $(filter %.aidl,$(LOCAL_SRC_FILES)) 109 aidl_java_sources := 110 111 ifneq ($(strip $(aidl_sources)),) 112 113 aidl_preprocess_import := 114 ifdef LOCAL_SDK_VERSION 115 ifneq ($(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 118 else 119 aidl_preprocess_import := $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_VERSION)/framework.aidl 120 endif # not current or system_current 121 else 122 # build against the platform. 123 LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS) 124 endif # 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 136 endif 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. 144 ifndef LOCAL_CHECKED_MODULE 145 ifdef full_classes_jar 146 LOCAL_CHECKED_MODULE := $(full_classes_compiled_jar) 147 endif 148 endif 149 150 ####################################### 151 include $(BUILD_SYSTEM)/base_rules.mk 152 ####################################### 153 154 ########################################################### 155 ## logtags: emit java source 156 ########################################################### 157 ifneq ($(strip $(logtags_sources)),) 158 159 logtags_java_sources := $(patsubst %.logtags,%.java,$(addprefix $(intermediates.COMMON)/logtags/, $(logtags_sources))) 160 logtags_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 166 else 167 logtags_java_sources := 168 endif 169 170 ########################################## 171 java_sources := $(addprefix $(LOCAL_PATH)/, $(filter %.java,$(LOCAL_SRC_FILES))) $(aidl_java_sources) $(logtags_java_sources) \ 172 $(filter %.java,$(LOCAL_GENERATED_SOURCES)) 173 java_intermediate_sources := $(addprefix $(TARGET_OUT_COMMON_INTERMEDIATES)/, $(filter %.java,$(LOCAL_INTERMEDIATE_SOURCES))) 174 all_java_sources := $(java_sources) $(java_intermediate_sources) 175 176 include $(BUILD_SYSTEM)/java_common.mk 177 178 include $(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. 189 ifneq (,$(called_from_package_internal) 190 dex_preopt_profile_src_file := $(LOCAL_BUILT_MODULE) 191 endif 192 193 ####################################### 194 # defines built_odex along with rule to install odex 195 include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk 196 ####################################### 197 198 # Make sure there's something to build. 199 ifdef full_classes_jar 200 ifndef need_compile_java 201 $(call pretty-error,Target java module does not define any source or resource files) 202 endif 203 endif 204 205 # Since we're using intermediates.COMMON, make sure that it gets cleaned 206 # properly. 207 $(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON) 208 209 ifdef 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))) 215 ALL_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. 219 layers_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 229 ifeq ($(RUN_ERROR_PRONE),true) 230 LOCAL_JAVACFLAGS += $(LOCAL_ERROR_PRONE_FLAGS) 231 endif 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. 236 ifneq (,$(PRODUCT_MINIMIZE_JAVA_DEBUG_INFO)) 237 ifneq (,$(filter userdebug user,$(TARGET_BUILD_VARIANT))) 238 LOCAL_JAVACFLAGS+= -g:source,lines 239 endif 240 endif 241 242 # List of dependencies for anything that needs all java sources in place 243 java_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 253 ifneq ($(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. 274 ifneq ($(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) $< $@ 279 else 280 full_classes_header_jarjar := $(full_classes_turbine_jar) 281 endif 282 283 $(eval $(call copy-one-file,$(full_classes_header_jarjar),$(full_classes_header_jar))) 284 285 endif # 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 312 javac-check : $(full_classes_compiled_jar) 313 javac-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 325 ifdef 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 :=). 330 in := $(full_classes_combined_jar) 331 out := $(full_classes_processed_jar).tmp 332 my_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) 337 in := 338 out := 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 346 my_jar_processor := 347 else 348 full_classes_processed_jar := $(full_classes_combined_jar) 349 endif 350 351 # Run jarjar if necessary 352 ifneq ($(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) $< $@ 357 else 358 full_classes_jarjar_jar := $(full_classes_processed_jar) 359 endif 360 361 $(eval $(call copy-one-file,$(full_classes_jarjar_jar),$(full_classes_jar))) 362 363 ####################################### 364 LOCAL_FULL_CLASSES_PRE_JACOCO_JAR := $(full_classes_jar) 365 366 include $(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. 371 ifdef TARGET_OPENJDK9 372 LOCAL_DX_FLAGS := $(filter-out --multi-dex,$(LOCAL_DX_FLAGS)) --multi-dex 373 endif 374 375 ifneq ($(USE_D8_DESUGAR),true) 376 my_desugaring := 377 ifndef LOCAL_IS_STATIC_JAVA_LIBRARY 378 my_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) 382 endif 383 else 384 my_desugaring := 385 endif 386 387 ifndef my_desugaring 388 full_classes_desugar_jar := $(LOCAL_FULL_CLASSES_JACOCO_JAR) 389 endif 390 391 full_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 397 ifdef LOCAL_PROGUARD_ENABLED 398 ifneq ($(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)) 401 endif 402 proguard_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 411 my_proguard_sdk_raise := 412 ifdef LOCAL_SDK_VERSION 413 ifdef TARGET_BUILD_APPS 414 ifeq (,$(filter current system_current test_current core_current, $(LOCAL_SDK_VERSION))) 415 my_proguard_sdk_raise := $(call java-lib-header-files, sdk_vcurrent) 416 endif 417 else 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)) 421 endif 422 endif 423 424 ifeq ($(USE_R8),true) 425 proguard_jars_prefix := -libraryjars 426 else 427 proguard_jars_prefix := -systemjars 428 endif 429 legacy_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 434 legacy_proguard_lib_deps := $(my_proguard_sdk_raise) \ 435 $(filter-out $(my_proguard_sdk_raise),$(full_shared_java_header_libs)) 436 437 legacy_proguard_flags += -printmapping $(proguard_dictionary) 438 439 common_proguard_flags := -forceprocessing 440 441 common_proguard_flag_files := $(BUILD_SYSTEM)/proguard.flags 442 ifneq ($(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS)),) 443 common_proguard_flags += -dontshrink # don't shrink tests by default 444 endif # test package 445 ifneq ($(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 450 endif 451 ifneq ($(common_proguard_flag_files),) 452 common_proguard_flags += $(addprefix -include , $(common_proguard_flag_files)) 453 # This is included from $(BUILD_SYSTEM)/proguard.flags 454 common_proguard_flag_files += $(BUILD_SYSTEM)/proguard_basic_keeps.flags 455 endif 456 457 ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),) 458 # By default no obfuscation 459 common_proguard_flags += -dontobfuscate 460 endif # No obfuscation 461 ifeq ($(filter optimization,$(LOCAL_PROGUARD_ENABLED)),) 462 # By default no optimization 463 common_proguard_flags += -dontoptimize 464 endif # No optimization 465 466 ifdef LOCAL_INSTRUMENTATION_FOR 467 ifeq ($(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 470 legacy_proguard_flags += -libraryjars $(link_instr_classes_jar) 471 legacy_proguard_lib_deps += $(link_instr_classes_jar) 472 else # 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. 476 legacy_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. 485 legacy_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 490 endif # no obfuscation 491 endif # LOCAL_INSTRUMENTATION_FOR 492 493 proguard_flag_files := $(addprefix $(LOCAL_PATH)/, $(LOCAL_PROGUARD_FLAG_FILES)) 494 ifeq ($(USE_R8),true) 495 proguard_flag_files += $(addprefix $(LOCAL_PATH)/, $(LOCAL_R8_FLAG_FILES)) 496 endif # USE_R8 497 LOCAL_PROGUARD_FLAGS += $(addprefix -include , $(proguard_flag_files)) 498 499 ifdef LOCAL_TEST_MODULE_TO_PROGUARD_WITH 500 extra_input_jar := $(call intermediates-dir-for,APPS,$(LOCAL_TEST_MODULE_TO_PROGUARD_WITH),,COMMON)/classes.jar 501 else 502 extra_input_jar := 503 endif 504 505 ifneq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),) 506 ifneq ($(USE_R8),true) 507 $(full_classes_proguard_jar): .KATI_IMPLICIT_OUTPUTS := $(proguard_dictionary) 508 else 509 $(built_dex_intermediate): .KATI_IMPLICIT_OUTPUTS := $(proguard_dictionary) 510 endif 511 endif 512 513 # If R8 is not enabled run Proguard. 514 ifneq ($(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) 521 else # !USE_R8 522 # Running R8 instead of Proguard, proguarded jar is actually the pre-Proguarded jar. 523 full_classes_proguard_jar := $(full_classes_pre_proguard_jar) 524 endif # !USE_R8 525 526 else # LOCAL_PROGUARD_ENABLED not defined 527 proguard_flag_files := 528 full_classes_proguard_jar := $(full_classes_pre_proguard_jar) 529 endif # LOCAL_PROGUARD_ENABLED defined 530 531 ifneq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) 532 $(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS) 533 534 my_r8 := 535 ifdef LOCAL_PROGUARD_ENABLED 536 ifeq ($(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 540 my_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) 545 endif # USE_R8 546 endif # LOCAL_PROGUARD_ENABLED 547 548 ifndef my_r8 549 $(built_dex_intermediate): $(full_classes_proguard_jar) $(DX) $(ZIP2ZIP) 550 ifneq ($(USE_D8_DESUGAR),true) 551 $(transform-classes.jar-to-dex) 552 else 553 $(transform-classes-d8.jar-to-dex) 554 endif 555 endif 556 557 ifneq ($(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) 560 else # !is_boot_jar 561 built_dex_copy_from := $(built_dex_intermediate) 562 endif # 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 570 java-dex: $(built_dex) 571 572 endif # !LOCAL_IS_STATIC_JAVA_LIBRARY 573 574 findbugs_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 585 ALL_FINDBUGS_FILES += $(findbugs_xml) 586 587 findbugs_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 598 endif # full_classes_jar is defined 599 600 ifneq (,$(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)) 603 else 604 my_default_app_target_sdk := $(DEFAULT_APP_TARGET_SDK) 605 my_sdk_version := $(PLATFORM_SDK_VERSION) 606 endif 607 608 ifdef LOCAL_MIN_SDK_VERSION 609 my_min_sdk_version := $(LOCAL_MIN_SDK_VERSION) 610 else 611 my_min_sdk_version := $(call codename-or-sdk-to-sdk,$(my_default_app_target_sdk)) 612 endif 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