blob: 04f7a72d02fc8eae3b0b4dc8b140566d3b5a91e0 [file] [log] [blame]
Ying Wang956dccc2015-08-28 11:47:03 -07001# Target Java.
The Android Open Source Project88b60792009-03-03 19:28:42 -08002# Requires:
3# LOCAL_MODULE_SUFFIX
4# LOCAL_MODULE_CLASS
5# all_res_assets
6
Keun young Parkebb351e2012-04-19 15:36:18 -07007ifeq ($(TARGET_BUILD_PDK),true)
Keun young Parkefe02ce2012-06-06 17:19:29 -07008ifeq ($(TARGET_BUILD_PDK_JAVA_PLATFORM),)
Keun young Parkebb351e2012-04-19 15:36:18 -07009# LOCAL_SDK not defined or set to current
10ifeq ($(filter-out current,$(LOCAL_SDK_VERSION)),)
Ying Wang2fee3a82014-10-17 18:26:39 -070011ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
Keun young Parkebb351e2012-04-19 15:36:18 -070012LOCAL_SDK_VERSION := $(PDK_BUILD_SDK_VERSION)
Ying Wang2fee3a82014-10-17 18:26:39 -070013endif #!LOCAL_NO_STANDARD_LIBRARIES
Keun young Parkebb351e2012-04-19 15:36:18 -070014endif
Keun young Park816b9fd2012-05-16 10:32:41 -070015endif # !PDK_JAVA
Keun young Parkebb351e2012-04-19 15:36:18 -070016endif #PDK
17
The Android Open Source Project88b60792009-03-03 19:28:42 -080018LOCAL_NO_STANDARD_LIBRARIES:=$(strip $(LOCAL_NO_STANDARD_LIBRARIES))
19LOCAL_SDK_VERSION:=$(strip $(LOCAL_SDK_VERSION))
20
Ying Wanga5fc87a2010-11-02 18:43:16 -070021proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
22ifneq ($(proto_sources),)
23ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro)
Jeff Davidsonb8ddd552014-09-15 17:51:11 -070024 LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-micro
Ying Wanga5fc87a2010-11-02 18:43:16 -070025else
Ulas Kirazcibde274e2013-03-28 14:02:14 -070026 ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nano)
Jeff Davidsonb8ddd552014-09-15 17:51:11 -070027 LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-nano
Ulas Kirazcibde274e2013-03-28 14:02:14 -070028 else
Joe Onoratoc05a8ee2016-10-05 18:01:10 -070029 ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),stream)
30 # No library for stream protobufs
31 else
32 LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-lite
33 endif
Ulas Kirazcibde274e2013-03-28 14:02:14 -070034 endif
Ying Wanga5fc87a2010-11-02 18:43:16 -070035endif
36endif
37
Ying Wange295c3d2016-02-24 14:11:55 -080038# 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))
The Android Open Source Project88b60792009-03-03 19:28:42 -080044
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
Joe Onoratoe334d252009-07-17 15:33:40 -040053
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
Ying Wang957fea52010-09-23 11:48:38 -070062ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
63LOCAL_PROGUARD_ENABLED :=
64endif
65
Nan Zhangb3ec5342017-08-31 21:43:04 +000066full_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
Colin Crossa6e87822017-12-20 17:33:01 -080069full_classes_compiled_jar := $(intermediates.COMMON)/classes-full-debug.jar
Colin Crossf8a49c52017-05-22 16:21:49 -070070full_classes_processed_jar := $(intermediates.COMMON)/classes-processed.jar
Colin Cross950f1ef2017-04-05 15:30:42 -070071full_classes_desugar_jar := $(intermediates.COMMON)/classes-desugar.jar
Colin Crossa6e87822017-12-20 17:33:01 -080072full_classes_jarjar_jar := $(intermediates.COMMON)/classes-jarjar.jar
Colin Cross950f1ef2017-04-05 15:30:42 -070073full_classes_proguard_jar := $(intermediates.COMMON)/classes-proguard.jar
Nan Zhang9bd54052017-09-13 13:13:53 -070074full_classes_combined_jar := $(intermediates.COMMON)/classes-combined.jar
Colin Crossa6e87822017-12-20 17:33:01 -080075built_dex_intermediate := $(intermediates.COMMON)/dex/classes.dex
Ying Wang957fea52010-09-23 11:48:38 -070076full_classes_stubs_jar := $(intermediates.COMMON)/stubs.jar
Colin Crossdfc45ec2017-05-26 15:22:02 -070077java_source_list_file := $(intermediates.COMMON)/java-source-list
78
Ying Wang957fea52010-09-23 11:48:38 -070079
Ying Wang37b82aa2013-08-28 17:28:36 -070080ifeq ($(LOCAL_MODULE_CLASS)$(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),APPS)
81# If this is an apk without any Java code (e.g. framework-res), we should skip compiling Java.
Ying Wang990cf5e2013-08-28 13:04:46 -070082full_classes_jar :=
83built_dex :=
84else
Ying Wang957fea52010-09-23 11:48:38 -070085full_classes_jar := $(intermediates.COMMON)/classes.jar
Ying Wang7b7929a2013-09-12 17:35:21 -070086built_dex := $(intermediates.COMMON)/classes.dex
Ying Wang990cf5e2013-08-28 13:04:46 -070087endif
Joe Onoratoe334d252009-07-17 15:33:40 -040088
89LOCAL_INTERMEDIATE_TARGETS += \
Nan Zhangb3ec5342017-08-31 21:43:04 +000090 $(full_classes_turbine_jar) \
Joe Onoratoe334d252009-07-17 15:33:40 -040091 $(full_classes_compiled_jar) \
Colin Crosseac5ce42016-12-21 17:11:03 -080092 $(full_classes_desugar_jar) \
Ying Wang957fea52010-09-23 11:48:38 -070093 $(full_classes_jarjar_jar) \
Ying Wang957fea52010-09-23 11:48:38 -070094 $(full_classes_jar) \
Nan Zhang9bd54052017-09-13 13:13:53 -070095 $(full_classes_combined_jar) \
Ying Wanga9c381e2010-10-02 18:35:51 -070096 $(full_classes_proguard_jar) \
Ying Wang957fea52010-09-23 11:48:38 -070097 $(built_dex_intermediate) \
Guang Zhu155afe32010-03-10 15:48:03 -080098 $(built_dex) \
Colin Crossdfc45ec2017-05-26 15:22:02 -070099 $(full_classes_stubs_jar) \
100 $(java_source_list_file)
Ying Wang957fea52010-09-23 11:48:38 -0700101
Joe Onorato77dc0a52010-05-17 18:16:11 -0700102LOCAL_INTERMEDIATE_SOURCE_DIR := $(intermediates.COMMON)/src
Joe Onoratoe334d252009-07-17 15:33:40 -0400103
Ying Wang0bd59a02010-07-15 17:17:52 -0700104###############################################################
105## .rs files: RenderScript sources to .java files and .bc files
Stephen Hines0ab6e3e2012-10-11 15:01:53 -0700106## .fs files: Filterscript sources to .java files and .bc files
Ying Wang0bd59a02010-07-15 17:17:52 -0700107###############################################################
Stephen Hines0ab6e3e2012-10-11 15:01:53 -0700108renderscript_sources := $(filter %.rs %.fs,$(LOCAL_SRC_FILES))
Ying Wang0bd59a02010-07-15 17:17:52 -0700109# Because names of the java files from RenderScript are unknown until the
110# .rs file(s) are compiled, we have to depend on a timestamp file.
111RenderScript_file_stamp :=
Ying Wangdd71c852015-12-04 13:59:18 -0800112rs_generated_res_dir :=
Stephen Hines3b0fa102013-02-06 16:19:30 -0800113rs_compatibility_jni_libs :=
Ying Wang0bd59a02010-07-15 17:17:52 -0700114ifneq ($(renderscript_sources),)
115renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
116RenderScript_file_stamp := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/RenderScript.stamp
Dan Willemsencf324af2016-12-21 17:37:00 -0800117renderscript_intermediate.COMMON := $(intermediates.COMMON)/renderscript
Ying Wang0bd59a02010-07-15 17:17:52 -0700118
Miao Wang302e9442015-07-28 17:43:51 -0700119# Defaulting to an empty string uses the latest available platform SDK.
Stephen Hinesc963eae2011-08-10 13:53:05 -0700120renderscript_target_api :=
Stephen Hinesa941d132011-08-29 18:53:53 -0700121
122ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API))
Miao Wang302e9442015-07-28 17:43:51 -0700123 renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API)
Stephen Hinesa941d132011-08-29 18:53:53 -0700124else
Miao Wang302e9442015-07-28 17:43:51 -0700125 ifneq (,$(LOCAL_SDK_VERSION))
126 # Set target-api for LOCAL_SDK_VERSIONs other than current.
Michael Wright0fb087f2015-11-06 15:20:51 +0000127 ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
Sundong Ahn5a44d1f2017-10-16 19:20:34 +0900128 renderscript_target_api := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
Miao Wang302e9442015-07-28 17:43:51 -0700129 endif
130 endif # LOCAL_SDK_VERSION is set
Stephen Hinesa941d132011-08-29 18:53:53 -0700131endif # LOCAL_RENDERSCRIPT_TARGET_API is set
Stephen Hinesc963eae2011-08-10 13:53:05 -0700132
Miao Wanga11f6c22015-07-29 11:46:23 -0700133# For 64-bit, we always have to upgrade to at least 21 for compat build.
134ifneq ($(LOCAL_RENDERSCRIPT_COMPATIBILITY),)
135 ifeq ($(TARGET_IS_64_BIT),true)
136 ifneq ($(filter $(RSCOMPAT_32BIT_ONLY_API_LEVELS),$(renderscript_target_api)),)
137 renderscript_target_api := 21
138 endif
Miao Wang302e9442015-07-28 17:43:51 -0700139 endif
140endif
141
Stephen Hinesc963eae2011-08-10 13:53:05 -0700142ifeq ($(LOCAL_RENDERSCRIPT_CC),)
143LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC)
144endif
145
Stephen Hines914f7a22011-12-06 18:43:24 -0800146# Turn on all warnings and warnings as errors for RS compiles.
147# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
148renderscript_flags := -Wall -Werror
149renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)
150
Ying Wang51280272010-09-01 13:28:52 -0700151# prepend the RenderScript system include path
Michael Wright0fb087f2015-11-06 15:20:51 +0000152ifneq ($(filter-out current system_current test_current,$(LOCAL_SDK_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current test_current,$(LOCAL_SDK_VERSION))),)
Ying Wang0ec188f2012-05-10 17:25:51 -0700153# if a numeric LOCAL_SDK_VERSION, or current LOCAL_SDK_VERSION with TARGET_BUILD_APPS
Ying Wangfcf00d52011-03-29 11:47:12 -0700154LOCAL_RENDERSCRIPT_INCLUDES := \
Stephen Hines5a4eb5f2012-03-06 21:48:36 -0800155 $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/clang-include \
156 $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/include \
Ying Wangfcf00d52011-03-29 11:47:12 -0700157 $(LOCAL_RENDERSCRIPT_INCLUDES)
158else
Ying Wang85aa5de2011-01-19 11:49:21 -0800159LOCAL_RENDERSCRIPT_INCLUDES := \
Stephen Hinesc963eae2011-08-10 13:53:05 -0700160 $(TOPDIR)external/clang/lib/Headers \
Jean-Luc Brouilleteba44932017-01-08 17:40:21 -0800161 $(TOPDIR)frameworks/rs/script_api/include \
Stephen Hinesc963eae2011-08-10 13:53:05 -0700162 $(LOCAL_RENDERSCRIPT_INCLUDES)
Ying Wang7d83ef82011-05-25 17:16:22 -0700163endif
164
Stephen Hinesd4136c02011-08-23 22:01:49 -0700165ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),)
166LOCAL_RENDERSCRIPT_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE)
167endif
168
Ying Wangb9319562015-04-03 16:15:28 -0700169bc_files := $(patsubst %.fs,%.bc, $(patsubst %.rs,%.bc, $(notdir $(renderscript_sources))))
170bc_dep_files := $(addprefix $(renderscript_intermediate.COMMON)/,$(patsubst %.bc,%.d,$(bc_files)))
171
Ying Wang51280272010-09-01 13:28:52 -0700172$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES)
Ying Wang7d83ef82011-05-25 17:16:22 -0700173$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC)
Stephen Hines914f7a22011-12-06 18:43:24 -0800174$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags)
Ying Wang0bd59a02010-07-15 17:17:52 -0700175$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath)
176# By putting the generated java files into $(LOCAL_INTERMEDIATE_SOURCE_DIR), they will be
177# automatically found by the java compiling function transform-java-to-classes.jar.
Ying Wang370fa672013-02-25 16:06:42 -0800178$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate.COMMON)
Stephen Hinesc963eae2011-08-10 13:53:05 -0700179$(RenderScript_file_stamp): PRIVATE_RS_TARGET_API := $(renderscript_target_api)
Ying Wangb9319562015-04-03 16:15:28 -0700180$(RenderScript_file_stamp): PRIVATE_DEP_FILES := $(bc_dep_files)
Ying Wang7d83ef82011-05-25 17:16:22 -0700181$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC)
Ying Wang0bd59a02010-07-15 17:17:52 -0700182 $(transform-renderscripts-to-java-and-bc)
183
Ying Wangb9319562015-04-03 16:15:28 -0700184# include the dependency files (.d/.P) generated by llvm-rs-cc.
Shinichiro Hamaji52a1d6c2016-02-01 17:59:01 +0900185$(call include-depfile,$(RenderScript_file_stamp).P,$(RenderScript_file_stamp))
Ying Wangcddece62015-04-03 09:53:41 -0700186
Stephen Hinese719f282012-11-28 16:52:41 -0800187ifneq ($(LOCAL_RENDERSCRIPT_COMPATIBILITY),)
Miao Wange4359cf2015-01-07 18:18:41 -0800188
189
190ifeq ($(filter $(RSCOMPAT_32BIT_ONLY_API_LEVELS),$(renderscript_target_api)),)
191ifeq ($(TARGET_IS_64_BIT),true)
192renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/bc64/
193else
194renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/bc32/
195endif
196else
197renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/
198endif
199
Stephen Hinese719f282012-11-28 16:52:41 -0800200rs_generated_bc := $(addprefix \
Miao Wange4359cf2015-01-07 18:18:41 -0800201 $(renderscript_intermediate.bc_folder), $(bc_files))
Stephen Hinese719f282012-11-28 16:52:41 -0800202
Ying Wang370fa672013-02-25 16:06:42 -0800203renderscript_intermediate := $(intermediates)/renderscript
Tim Murray8e0567a2013-05-13 15:46:37 -0700204
205# We don't need the .so files in bundled branches
206# Prevent these from showing up on the device
Miao Wangc919b0b2015-02-12 16:22:59 -0800207# One exception is librsjni.so, which is needed for
208# both native path and compat path.
209rs_jni_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/librsjni.so
210LOCAL_JNI_SHARED_LIBRARIES += librsjni
211
Stephen Hinesc54e81c2013-09-30 15:57:36 -0700212ifneq (,$(TARGET_BUILD_APPS)$(FORCE_BUILD_RS_COMPAT))
Tim Murray8e0567a2013-05-13 15:46:37 -0700213
Stephen Hinese719f282012-11-28 16:52:41 -0800214rs_compatibility_jni_libs := $(addprefix \
Stephen Hinesec02b4f2013-02-15 23:02:20 -0800215 $(renderscript_intermediate)/librs., \
Stephen Hinese719f282012-11-28 16:52:41 -0800216 $(patsubst %.bc,%.so, $(bc_files)))
217
218$(rs_generated_bc) : $(RenderScript_file_stamp)
219
Stephen Hinesf6925132012-12-17 14:23:14 -0800220rs_support_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/libRSSupport.so
Miao Wangc919b0b2015-02-12 16:22:59 -0800221LOCAL_JNI_SHARED_LIBRARIES += libRSSupport
Stephen Hinesf6925132012-12-17 14:23:14 -0800222
Miao Wangec27a892014-11-20 11:05:18 -0800223rs_support_io_lib :=
224# check if the target api level support USAGE_IO
225ifeq ($(filter $(RSCOMPAT_NO_USAGEIO_API_LEVELS),$(renderscript_target_api)),)
226rs_support_io_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/libRSSupportIO.so
227LOCAL_JNI_SHARED_LIBRARIES += libRSSupportIO
228endif
Tim Murray8e0567a2013-05-13 15:46:37 -0700229
Miao Wang28e78f42017-08-16 16:05:26 -0700230my_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
231ifneq (,$(filter arm64 mips64 x86_64,$(my_arch)))
232 my_min_sdk_version := 21
233else
234 my_min_sdk_version := $(MIN_SUPPORTED_SDK_VERSION)
235endif
Tim Murray8e0567a2013-05-13 15:46:37 -0700236
Tim Murray1a6f09a2013-03-05 11:07:15 -0800237$(rs_compatibility_jni_libs): $(RenderScript_file_stamp) $(RS_PREBUILT_CLCORE) \
Miao Wangec27a892014-11-20 11:05:18 -0800238 $(rs_support_lib) $(rs_support_io_lib) $(rs_jni_lib) $(rs_compiler_rt)
Stephen Hines8db4cce2013-03-27 16:51:38 -0700239$(rs_compatibility_jni_libs): $(BCC_COMPAT)
Ying Wang57d90602015-07-20 18:40:18 -0700240$(rs_compatibility_jni_libs): PRIVATE_CXX := $(CXX_WRAPPER) $(TARGET_CXX)
Miao Wang28e78f42017-08-16 16:05:26 -0700241$(rs_compatibility_jni_libs): PRIVATE_SDK_VERSION := $(my_min_sdk_version)
Stephen Hinesec02b4f2013-02-15 23:02:20 -0800242$(rs_compatibility_jni_libs): $(renderscript_intermediate)/librs.%.so: \
Miao Wang28e78f42017-08-16 16:05:26 -0700243 $(renderscript_intermediate.bc_folder)%.bc \
244 $(SOONG_OUT_DIR)/ndk.timestamp
Stephen Hinese719f282012-11-28 16:52:41 -0800245 $(transform-bc-to-so)
246
247endif
248
Tim Murray8e0567a2013-05-13 15:46:37 -0700249endif
250
Ying Wang0bd59a02010-07-15 17:17:52 -0700251LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
252# Make sure the generated resource will be added to the apk.
Ying Wangdd71c852015-12-04 13:59:18 -0800253rs_generated_res_dir := $(renderscript_intermediate.COMMON)/res
254LOCAL_RESOURCE_DIR := $(rs_generated_res_dir) $(LOCAL_RESOURCE_DIR)
Ying Wang0bd59a02010-07-15 17:17:52 -0700255endif
256
Ying Wang956dccc2015-08-28 11:47:03 -0700257
258###########################################################
259## AIDL: Compile .aidl files to .java
260###########################################################
261aidl_sources := $(filter %.aidl,$(LOCAL_SRC_FILES))
Christopher Wileyd9205ba2016-06-23 16:44:47 -0700262aidl_java_sources :=
Ying Wang956dccc2015-08-28 11:47:03 -0700263
264ifneq ($(strip $(aidl_sources)),)
Ying Wang956dccc2015-08-28 11:47:03 -0700265
266aidl_preprocess_import :=
267ifdef LOCAL_SDK_VERSION
Michael Wright0fb087f2015-11-06 15:20:51 +0000268ifneq ($(filter current system_current test_current, $(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS)),)
Ying Wang956dccc2015-08-28 11:47:03 -0700269 # LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS
270 aidl_preprocess_import := $(TARGET_OUT_COMMON_INTERMEDIATES)/framework.aidl
271else
272 aidl_preprocess_import := $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_VERSION)/framework.aidl
273endif # not current or system_current
274else
275# build against the platform.
276LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)
277endif # LOCAL_SDK_VERSION
Ying Wang956dccc2015-08-28 11:47:03 -0700278
Christopher Wileyd9205ba2016-06-23 16:44:47 -0700279$(foreach s,$(aidl_sources),\
Dan Willemsen4d995272017-09-29 17:37:31 -0700280 $(eval $(call define-aidl-java-rule,$(s),$(intermediates.COMMON)/aidl,aidl_java_sources)))
Shinichiro Hamaji2a0d1fe2016-01-28 16:10:00 +0900281$(foreach java,$(aidl_java_sources), \
282 $(call include-depfile,$(java:%.java=%.P),$(java)))
Ying Wang956dccc2015-08-28 11:47:03 -0700283
Christopher Wileyd9205ba2016-06-23 16:44:47 -0700284$(aidl_java_sources) : $(LOCAL_ADDITIONAL_DEPENDENCIES) $(aidl_preprocess_import)
285
286$(aidl_java_sources): PRIVATE_AIDL_FLAGS := -b $(addprefix -p,$(aidl_preprocess_import)) -I$(LOCAL_PATH) -I$(LOCAL_PATH)/src $(addprefix -I,$(LOCAL_AIDL_INCLUDES))
Christopher Wileydc9e2672016-06-24 13:13:52 -0700287$(aidl_java_sources): PRIVATE_MODULE := $(LOCAL_MODULE)
Christopher Wileyd9205ba2016-06-23 16:44:47 -0700288
Ying Wang956dccc2015-08-28 11:47:03 -0700289endif
290
Ying Wang956dccc2015-08-28 11:47:03 -0700291##########################################
292
Ying Wang1d977e32013-01-30 11:22:06 -0800293# All of the rules after full_classes_compiled_jar are very unlikely
294# to fail except for bugs in their respective tools. If you would
295# like to run these rules, add the "all" modifier goal to the make
296# command line.
Ying Wang447d6962015-09-01 19:12:05 -0700297ifndef LOCAL_CHECKED_MODULE
Jean-Philippe Lesot0fbc9ff2015-01-20 14:18:48 +0000298ifdef full_classes_jar
Colin Crossb17f2852017-04-27 13:34:02 -0700299LOCAL_CHECKED_MODULE := $(full_classes_compiled_jar)
Ying Wang990cf5e2013-08-28 13:04:46 -0700300endif
Yohann Rousselee572682015-08-18 19:18:18 +0200301endif
Ying Wang1d977e32013-01-30 11:22:06 -0800302
The Android Open Source Project88b60792009-03-03 19:28:42 -0800303#######################################
304include $(BUILD_SYSTEM)/base_rules.mk
305#######################################
306
Yasuhiro Matsudaff82e822015-09-04 16:23:49 +0900307###########################################################
308## logtags: emit java source
309###########################################################
310ifneq ($(strip $(logtags_sources)),)
311
Dan Willemsen4d995272017-09-29 17:37:31 -0700312logtags_java_sources := $(patsubst %.logtags,%.java,$(addprefix $(intermediates.COMMON)/logtags/, $(logtags_sources)))
Yasuhiro Matsudaff82e822015-09-04 16:23:49 +0900313logtags_sources := $(addprefix $(LOCAL_PATH)/, $(logtags_sources))
314
Shinichiro Hamajid3ce14c2016-03-29 03:29:21 +0900315$(logtags_java_sources): PRIVATE_MERGED_TAG := $(TARGET_OUT_COMMON_INTERMEDIATES)/all-event-log-tags.txt
Colin Crossfdea8932017-12-06 14:38:40 -0800316$(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
Yasuhiro Matsudaff82e822015-09-04 16:23:49 +0900317 $(transform-logtags-to-java)
318
319else
320logtags_java_sources :=
321endif
322
Ying Wang956dccc2015-08-28 11:47:03 -0700323##########################################
324java_sources := $(addprefix $(LOCAL_PATH)/, $(filter %.java,$(LOCAL_SRC_FILES))) $(aidl_java_sources) $(logtags_java_sources) \
325 $(filter %.java,$(LOCAL_GENERATED_SOURCES))
Nan Zhangad818dc2017-10-04 09:26:06 -0700326java_intermediate_sources := $(addprefix $(TARGET_OUT_COMMON_INTERMEDIATES)/, $(filter %.java,$(LOCAL_INTERMEDIATE_SOURCES)))
327all_java_sources := $(java_sources) $(java_intermediate_sources)
328
329enable_sharding :=
330ifneq ($(TURBINE_ENABLED),false)
331ifneq ($(LOCAL_JAVAC_SHARD_SIZE),)
332ifneq ($(LOCAL_JAR_PROCESSOR),)
333$(call pretty-error,Cannot set both LOCAL_JAVAC_SHARD_SIZE and LOCAL_JAR_PROCESSOR!)
334endif # LOCAL_JAR_PROCESSOR is not empty
335enable_sharding := true
336
337num_shards := $(call int_divide,$(words $(java_sources)),$(LOCAL_JAVAC_SHARD_SIZE))
338ifneq ($(words $(java_sources)),$(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(num_shards)))
339# increment number of shards by 1.
340num_shards := $(call int_plus,$(num_shards),1)
341endif
342
343shard_idx_list := $(call int_range_list,1,$(num_shards))
344sharded_java_source_list_files += $(foreach x,$(shard_idx_list),$(java_source_list_file).shard.$(x))
345sharded_jar_list += $(foreach x,$(shard_idx_list),$(full_classes_compiled_jar).shard.$(x))
346
347# always put dynamically-located .java files (generated by Proto/resource, etc) in a new final shard.
348# increment number of shards by 1.
349num_shards := $(call int_plus,$(num_shards),1)
350sharded_java_source_list_files += $(java_source_list_file).shard.$(num_shards)
351sharded_jar_list += $(full_classes_compiled_jar).shard.$(num_shards)
352LOCAL_INTERMEDIATE_TARGETS += $(sharded_java_source_list_files)
353LOCAL_INTERMEDIATE_TARGETS += $(sharded_jar_list)
354endif # LOCAL_JAVAC_SHARD_SIZE is not empty
355endif # TURBINE_ENABLED != false
Ying Wang956dccc2015-08-28 11:47:03 -0700356
357include $(BUILD_SYSTEM)/java_common.mk
358
Dan Willemsencf324af2016-12-21 17:37:00 -0800359$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HAS_RS_SOURCES := $(if $(renderscript_sources),true)
360$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RS_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/renderscript
361
Narayan Kamathbbcdc072017-08-22 15:47:08 +0100362# Set the profile source so that the odex / profile code included from java.mk
363# can find it.
364#
365# TODO: b/64896089, this is broken when called from package_internal.mk, since the file
366# we preopt from is a temporary file. This will be addressed in a follow up, possibly
367# by disabling stripping for profile guided preopt (which may be desirable for other
368# reasons anyway).
369#
370# Note that we set this only when called from package_internal.mk and not in other cases.
371ifneq (,$(called_from_package_internal)
372dex_preopt_profile_src_file := $(LOCAL_BUILT_MODULE)
373endif
374
Brian Carlstromced4bff2013-11-14 23:44:56 -0800375#######################################
376# defines built_odex along with rule to install odex
377include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
378#######################################
379
Ying Wang990cf5e2013-08-28 13:04:46 -0700380# Make sure there's something to build.
381ifdef full_classes_jar
382ifndef need_compile_java
383$(error $(LOCAL_PATH): Target java module does not define any source or resource files)
384endif
385endif
386
The Android Open Source Project88b60792009-03-03 19:28:42 -0800387# Since we're using intermediates.COMMON, make sure that it gets cleaned
388# properly.
389$(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON)
390
Ying Wang990cf5e2013-08-28 13:04:46 -0700391ifdef full_classes_jar
The Android Open Source Project88b60792009-03-03 19:28:42 -0800392
Joe Onorato64d85d02009-04-09 19:31:12 -0700393# Droiddoc isn't currently able to generate stubs for modules, so we're just
394# allowing it to use the classes.jar as the "stubs" that would be use to link
395# against, for the cases where someone needs the jar to link against.
Colin Cross0e537342017-03-29 12:17:36 -0700396$(eval $(call copy-one-file,$(full_classes_jar),$(full_classes_stubs_jar)))
Joe Onorato64d85d02009-04-09 19:31:12 -0700397ALL_MODULES.$(LOCAL_MODULE).STUBS := $(full_classes_stubs_jar)
398
Joe Onorato0eccce92011-10-30 21:37:35 -0700399# The layers file allows you to enforce a layering between java packages.
Colin Crossfdea8932017-12-06 14:38:40 -0800400# Run build/make/tools/java-layers.py for more details.
Joe Onorato0eccce92011-10-30 21:37:35 -0700401layers_file := $(addprefix $(LOCAL_PATH)/, $(LOCAL_JAVA_LAYERS_FILE))
402$(full_classes_compiled_jar): PRIVATE_JAVA_LAYERS_FILE := $(layers_file)
Ying Wang057eba02012-10-18 10:54:49 -0700403$(full_classes_compiled_jar): PRIVATE_WARNINGS_ENABLE := $(LOCAL_WARNINGS_ENABLE)
Joe Onorato0eccce92011-10-30 21:37:35 -0700404
The Android Open Source Project88b60792009-03-03 19:28:42 -0800405# Compile the java files to a .jar file.
406# This intentionally depends on java_sources, not all_java_sources.
407# Deps for generated source files must be handled separately,
408# via deps on the target that generates the sources.
Paul Duffin3ca92982016-09-20 15:12:30 +0100409
410# If error prone is enabled then add LOCAL_ERROR_PRONE_FLAGS to LOCAL_JAVACFLAGS
411ifeq ($(RUN_ERROR_PRONE),true)
412LOCAL_JAVACFLAGS += $(LOCAL_ERROR_PRONE_FLAGS)
413endif
414
Przemyslaw Szczepaniak2e81b3c2017-06-30 14:51:12 +0100415# For user / userdebug builds, strip the local variable table and the local variable
416# type table. This has no bearing on stack traces, but will leave less information
417# available via JDWP.
418ifneq (,$(PRODUCT_MINIMIZE_JAVA_DEBUG_INFO))
419ifneq (,$(filter userdebug user,$(TARGET_BUILD_VARIANT)))
420LOCAL_JAVACFLAGS+= -g:source,lines
Przemyslaw Szczepaniak2e81b3c2017-06-30 14:51:12 +0100421endif
422endif
423
Colin Crossdfc45ec2017-05-26 15:22:02 -0700424# List of dependencies for anything that needs all java sources in place
425java_sources_deps := \
426 $(java_sources) \
427 $(java_resource_sources) \
428 $(RenderScript_file_stamp) \
429 $(proto_java_sources_file_stamp) \
430 $(LOCAL_ADDITIONAL_DEPENDENCIES)
431
432$(java_source_list_file): $(java_sources_deps)
433 $(write-java-source-list)
434
Nan Zhangad818dc2017-10-04 09:26:06 -0700435ifdef enable_sharding
436$(foreach x,$(shard_idx_list),\
437 $(eval $(call save-sharded-java-source-list,$(x),\
438 $(wordlist $(call int_plus,1,$(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(call int_subtract,$(x),1))),\
439 $(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(x)),$(sort $(java_sources))))))
440
441# always put dynamically-located .java files (generated by Proto/resource, etc) in a new final shard.
442$(java_source_list_file).shard.$(num_shards): PRIVATE_JAVA_INTERMEDIATE_SOURCES := $(java_intermediate_sources)
443$(java_source_list_file).shard.$(num_shards): $(java_resource_sources) \
444 $(RenderScript_file_stamp) \
445 $(proto_java_sources_file_stamp) \
446 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
447 $(NORMALIZE_PATH)
448 $(hide) rm -f $@
449 $(call dump-words-to-file,$(PRIVATE_JAVA_INTERMEDIATE_SOURCES),$@.tmp)
450 $(call fetch-additional-java-source,$@.tmp)
451 $(hide) tr ' ' '\n' < $@.tmp | $(NORMALIZE_PATH) | sort -u > $@
452
453# Javac sharding with header libs including its own header jar as one of dependency.
454$(foreach x,$(shard_idx_list),\
455 $(eval $(call create-classes-full-debug.jar,$(full_classes_compiled_jar).shard.$(x),\
456 $(java_source_list_file).shard.$(x),\
457 $(full_java_header_libs) $(full_classes_header_jar),$(x),\
458 $(wordlist $(call int_plus,1,$(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(call int_subtract,$(x),1))),\
459 $(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(x)),$(sort $(java_sources))))))
460
461# Javac sharding for last shard with additional Java dependencies.
462$(eval $(call create-classes-full-debug.jar,$(full_classes_compiled_jar).shard.$(num_shards),\
463 $(java_source_list_file).shard.$(num_shards),$(full_java_header_libs) $(full_classes_header_jar),$(strip \
464 $(num_shards)),$$(java_resource_sources) $$(RenderScript_file_stamp) \
465 $$(proto_java_sources_file_stamp) $$(LOCAL_ADDITIONAL_DEPENDENCIES)))
466
467$(full_classes_compiled_jar): PRIVATE_SHARDED_JAR_LIST := $(sharded_jar_list)
468$(full_classes_compiled_jar): $(sharded_jar_list) | $(MERGE_ZIPS)
469 $(MERGE_ZIPS) -j $@ $(PRIVATE_SHARDED_JAR_LIST)
470else
471# we can't use single $ for java_sources_deps since it may contain hash '#' sign.
472$(eval $(call create-classes-full-debug.jar,$(full_classes_compiled_jar),\
473 $(java_source_list_file),$(full_java_header_libs),,$$(java_sources_deps)))
474
475endif # ifdef enable_sharding
The Android Open Source Project88b60792009-03-03 19:28:42 -0800476
Colin Cross7dc90432017-09-26 16:17:24 -0700477ifneq ($(TURBINE_ENABLED),false)
478
Nan Zhangb3ec5342017-08-31 21:43:04 +0000479$(full_classes_turbine_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) $(annotation_processor_flags)
480$(full_classes_turbine_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
481$(full_classes_turbine_jar): \
482 $(java_source_list_file) \
483 $(java_sources_deps) \
484 $(full_java_header_libs) \
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700485 $(full_java_bootclasspath_libs) \
Colin Crossf9602572017-10-12 13:34:40 -0700486 $(full_java_system_modules_deps) \
Nan Zhangb3ec5342017-08-31 21:43:04 +0000487 $(NORMALIZE_PATH) \
488 $(JAR_ARGS) \
489 $(ZIPTIME) \
Nan Zhang9bd54052017-09-13 13:13:53 -0700490 | $(TURBINE) \
491 $(MERGE_ZIPS)
Nan Zhangb3ec5342017-08-31 21:43:04 +0000492 $(transform-java-to-header.jar)
493
494.KATI_RESTAT: $(full_classes_turbine_jar)
495
496# Run jarjar before generate classes-header.jar if necessary.
497ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
498$(full_classes_header_jarjar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
499$(full_classes_header_jarjar): $(full_classes_turbine_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
500 @echo Header JarJar: $@
501 $(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
502else
503full_classes_header_jarjar := $(full_classes_turbine_jar)
504endif
505
506$(eval $(call copy-one-file,$(full_classes_header_jarjar),$(full_classes_header_jar)))
507
Colin Cross7dc90432017-09-26 16:17:24 -0700508endif # TURBINE_ENABLED != false
509
Ying Wangcddeb6c2016-03-24 11:00:30 -0700510javac-check : $(full_classes_compiled_jar)
Paul Duffin32bd0ad2016-09-15 14:34:42 +0100511javac-check-$(LOCAL_MODULE) : $(full_classes_compiled_jar)
Ying Wangcddeb6c2016-03-24 11:00:30 -0700512
Nan Zhang9bd54052017-09-13 13:13:53 -0700513$(full_classes_combined_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
514$(full_classes_combined_jar): $(full_classes_compiled_jar) \
Nan Zhangb8801172017-09-20 14:56:48 -0700515 $(jar_manifest_file) \
Nan Zhang9bd54052017-09-13 13:13:53 -0700516 $(full_static_java_libs) | $(MERGE_ZIPS)
Nan Zhangb8801172017-09-20 14:56:48 -0700517 $(if $(PRIVATE_JAR_MANIFEST), $(hide) sed -e "s/%BUILD_NUMBER%/$(BUILD_NUMBER_FROM_FILE)/" \
518 $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf)
519 $(MERGE_ZIPS) -j $(if $(PRIVATE_JAR_MANIFEST),-m $(dir $@)/manifest.mf) \
520 $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,-stripDir META-INF -zipToNotStrip $<) \
521 $@ $< $(call reverse-list,$(PRIVATE_STATIC_JAVA_LIBRARIES))
Nan Zhang9bd54052017-09-13 13:13:53 -0700522
Colin Crossf8a49c52017-05-22 16:21:49 -0700523ifdef LOCAL_JAR_PROCESSOR
524# LOCAL_JAR_PROCESSOR_ARGS must be evaluated here to set up the rule-local
525# PRIVATE_JAR_PROCESSOR_ARGS variable, but $< and $@ are not available yet.
526# Set ${in} and ${out} so they can be referenced by LOCAL_JAR_PROCESSOR_ARGS
527# using deferred evaluation (LOCAL_JAR_PROCESSOR_ARGS = instead of :=).
Nan Zhang9bd54052017-09-13 13:13:53 -0700528in := $(full_classes_combined_jar)
Colin Crossf8a49c52017-05-22 16:21:49 -0700529out := $(full_classes_processed_jar).tmp
Colin Cross89b802b2017-07-13 19:25:47 -0700530my_jar_processor := $(HOST_OUT_JAVA_LIBRARIES)/$(LOCAL_JAR_PROCESSOR).jar
531
Colin Crossf8a49c52017-05-22 16:21:49 -0700532$(full_classes_processed_jar): PRIVATE_JAR_PROCESSOR_ARGS := $(LOCAL_JAR_PROCESSOR_ARGS)
Colin Cross89b802b2017-07-13 19:25:47 -0700533$(full_classes_processed_jar): PRIVATE_JAR_PROCESSOR := $(my_jar_processor)
Colin Crossf8a49c52017-05-22 16:21:49 -0700534$(full_classes_processed_jar): PRIVATE_TMP_OUT := $(out)
535in :=
536out :=
537
Nan Zhang9bd54052017-09-13 13:13:53 -0700538$(full_classes_processed_jar): $(full_classes_combined_jar) $(my_jar_processor)
Colin Crossf8a49c52017-05-22 16:21:49 -0700539 @echo Processing $@ with $(PRIVATE_JAR_PROCESSOR)
540 $(hide) rm -f $@ $(PRIVATE_TMP_OUT)
Colin Cross0851df82017-06-30 13:55:38 -0700541 $(hide) $(JAVA) -jar $(PRIVATE_JAR_PROCESSOR) $(PRIVATE_JAR_PROCESSOR_ARGS)
Colin Crossf8a49c52017-05-22 16:21:49 -0700542 $(hide) mv $(PRIVATE_TMP_OUT) $@
543
Colin Cross89b802b2017-07-13 19:25:47 -0700544my_jar_processor :=
Colin Crossf8a49c52017-05-22 16:21:49 -0700545else
Nan Zhang9bd54052017-09-13 13:13:53 -0700546full_classes_processed_jar := $(full_classes_combined_jar)
Colin Crossf8a49c52017-05-22 16:21:49 -0700547endif
548
Nan Zhang870025f2017-09-13 14:56:11 -0700549# Run jarjar if necessary
550ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
551$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
552$(full_classes_jarjar_jar): $(full_classes_processed_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
553 @echo JarJar: $@
554 $(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
555else
556full_classes_jarjar_jar := $(full_classes_processed_jar)
557endif
558
559$(eval $(call copy-one-file,$(full_classes_jarjar_jar),$(full_classes_jar)))
560
Colin Cross96873482017-12-22 16:51:23 -0800561LOCAL_FULL_CLASSES_PRE_JACOCO_JAR := $(full_classes_jar)
562
563#######################################
564include $(BUILD_SYSTEM)/jacoco.mk
565#######################################
566
Tobias Thierer7ef760b2017-11-17 13:02:12 +0000567# Temporarily enable --multi-dex until proguard supports v53 class files
568# ( http://b/67673860 ) or we move away from proguard altogether.
Tobias Thiererf6bd4952017-11-15 20:55:03 +0000569ifdef TARGET_OPENJDK9
Tobias Thierer89740662017-10-25 02:38:01 +0100570LOCAL_DX_FLAGS := $(filter-out --multi-dex,$(LOCAL_DX_FLAGS)) --multi-dex
571endif
572
Alan Leungeaafb3c2017-12-01 14:32:58 -0800573ifneq ($(USE_D8_DESUGAR),true)
Colin Crosseac5ce42016-12-21 17:11:03 -0800574my_desugaring :=
Colin Cross31060fd2017-03-21 10:17:04 -0700575ifndef LOCAL_IS_STATIC_JAVA_LIBRARY
Colin Crosseac5ce42016-12-21 17:11:03 -0800576my_desugaring := true
577$(full_classes_desugar_jar): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
Colin Cross96873482017-12-22 16:51:23 -0800578$(full_classes_desugar_jar): $(LOCAL_FULL_CLASSES_JACOCO_JAR) $(full_java_header_libs) $(DESUGAR)
Colin Crosseac5ce42016-12-21 17:11:03 -0800579 $(desugar-classes-jar)
580endif
Alan Leungeaafb3c2017-12-01 14:32:58 -0800581else
582my_desugaring :=
583endif
Colin Crosseac5ce42016-12-21 17:11:03 -0800584
585ifndef my_desugaring
Colin Cross96873482017-12-22 16:51:23 -0800586full_classes_desugar_jar := $(LOCAL_FULL_CLASSES_JACOCO_JAR)
Colin Crosseac5ce42016-12-21 17:11:03 -0800587endif
588
Colin Cross96873482017-12-22 16:51:23 -0800589full_classes_pre_proguard_jar := $(full_classes_desugar_jar)
Ying Wang3b2bdf12010-02-01 09:51:23 -0800590
Colin Cross950f1ef2017-04-05 15:30:42 -0700591# Keep a copy of the jar just before proguard processing.
592$(eval $(call copy-one-file,$(full_classes_pre_proguard_jar),$(intermediates.COMMON)/classes-pre-proguard.jar))
Shinichiro Hamaji89b255a2015-11-09 16:47:42 +0900593
Colin Cross0e537342017-03-29 12:17:36 -0700594# Run proguard if necessary
Ying Wang7311a342013-08-21 18:32:49 -0700595ifdef LOCAL_PROGUARD_ENABLED
Colin Crosse4936e12017-12-27 17:58:21 -0800596ifneq ($(filter-out full custom nosystem obfuscation optimization,$(LOCAL_PROGUARD_ENABLED)),)
Ying Wang7311a342013-08-21 18:32:49 -0700597 $(warning while processing: $(LOCAL_MODULE))
598 $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED))
599endif
Joe Onorato2daa2b32009-08-30 13:39:24 -0700600proguard_dictionary := $(intermediates.COMMON)/proguard_dictionary
Ying Wang4f5d0e62015-05-04 19:21:48 -0700601
Colin Crossb5f25a22017-10-20 19:16:41 -0700602# When an app contains references to APIs that are not in the SDK specified by
603# its LOCAL_SDK_VERSION for example added by support library or by runtime
604# classes added by desugar, we artifically raise the "SDK version" "linked" by
605# ProGuard, to
Ying Wang4f5d0e62015-05-04 19:21:48 -0700606# - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version.
607# - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version.
Colin Crossb5f25a22017-10-20 19:16:41 -0700608# See b/20667396
609my_proguard_sdk_raise :=
Ying Wang4f5d0e62015-05-04 19:21:48 -0700610ifdef LOCAL_SDK_VERSION
Ying Wang4f5d0e62015-05-04 19:21:48 -0700611ifdef TARGET_BUILD_APPS
Michael Wright0fb087f2015-11-06 15:20:51 +0000612ifeq (,$(filter current system_current test_current, $(LOCAL_SDK_VERSION)))
Colin Crossb5f25a22017-10-20 19:16:41 -0700613 my_proguard_sdk_raise := $(call java-lib-header-files, sdk_vcurrent)
Ying Wang742f5832015-06-26 12:33:06 -0700614endif
Ying Wang4f5d0e62015-05-04 19:21:48 -0700615else
616 # For platform build, we can't just raise to the "current" SDK,
617 # that would break apps that use APIs removed from the current SDK.
Colin Crossb5f25a22017-10-20 19:16:41 -0700618 my_proguard_sdk_raise := $(call java-lib-header-files,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES) $(TARGET_DEFAULT_JAVA_LIBRARIES))
Ying Wang4f5d0e62015-05-04 19:21:48 -0700619endif
620endif
Ying Wang4f5d0e62015-05-04 19:21:48 -0700621
Colin Crossb5f25a22017-10-20 19:16:41 -0700622legacy_proguard_flags := $(addprefix -libraryjars ,$(my_proguard_sdk_raise) \
623 $(filter-out $(my_proguard_sdk_raise), \
Colin Crossb541aae2017-09-23 19:52:43 -0700624 $(full_java_bootclasspath_libs) \
625 $(full_shared_java_header_libs)))
Nan Zhangb3ec5342017-08-31 21:43:04 +0000626
Colin Crossb5f25a22017-10-20 19:16:41 -0700627legacy_proguard_lib_deps := $(my_proguard_sdk_raise) \
628 $(filter-out $(my_proguard_sdk_raise),$(full_shared_java_header_libs))
Yohann Rousselb7de0fb2015-11-03 18:33:21 +0100629
630legacy_proguard_flags += -printmapping $(proguard_dictionary)
Yohann Rousselb7de0fb2015-11-03 18:33:21 +0100631
632common_proguard_flags := -forceprocessing
Ying Wang7311a342013-08-21 18:32:49 -0700633
Shinichiro Hamaji4eaeef82016-04-07 18:56:42 +0900634common_proguard_flag_files :=
Ying Wang7311a342013-08-21 18:32:49 -0700635ifeq ($(filter nosystem,$(LOCAL_PROGUARD_ENABLED)),)
Shinichiro Hamaji4eaeef82016-04-07 18:56:42 +0900636common_proguard_flag_files += $(BUILD_SYSTEM)/proguard.flags
Ying Wang7311a342013-08-21 18:32:49 -0700637ifneq ($(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS)),)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200638common_proguard_flags += -dontshrink # don't shrink tests by default
Ying Wang3b2bdf12010-02-01 09:51:23 -0800639endif # test package
Dan Willemsen1d646232017-11-17 13:11:26 -0800640ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
641 ifdef LOCAL_USE_AAPT2
642 common_proguard_flag_files += $(foreach l,$(LOCAL_STATIC_ANDROID_LIBRARIES),\
643 $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/export_proguard_flags)
644 endif
645endif
Shinichiro Hamaji4eaeef82016-04-07 18:56:42 +0900646ifneq ($(common_proguard_flag_files),)
647common_proguard_flags += $(addprefix -include , $(common_proguard_flag_files))
648# This is included from $(BUILD_SYSTEM)/proguard.flags
649common_proguard_flag_files += $(BUILD_SYSTEM)/proguard_basic_keeps.flags
650endif
651
Ying Wang7311a342013-08-21 18:32:49 -0700652ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
653# By default no obfuscation
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200654common_proguard_flags += -dontobfuscate
Ying Wang7311a342013-08-21 18:32:49 -0700655endif # No obfuscation
656ifeq ($(filter optimization,$(LOCAL_PROGUARD_ENABLED)),)
657# By default no optimization
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200658common_proguard_flags += -dontoptimize
Ying Wang7311a342013-08-21 18:32:49 -0700659endif # No optimization
Ying Wang3b2bdf12010-02-01 09:51:23 -0800660
Ying Wang7311a342013-08-21 18:32:49 -0700661ifdef LOCAL_INSTRUMENTATION_FOR
662ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
663# If no obfuscation, link in the instrmented package's classes.jar as a library.
664# link_instr_classes_jar is defined in base_rule.mk
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200665legacy_proguard_flags += -libraryjars $(link_instr_classes_jar)
Nan Zhangb3ec5342017-08-31 21:43:04 +0000666legacy_proguard_lib_deps += $(link_instr_classes_jar)
Ying Wang7311a342013-08-21 18:32:49 -0700667else # obfuscation
668# If obfuscation is enabled, the main app must be obfuscated too.
669# We need to run obfuscation using the main app's dictionary,
670# and treat the main app's class.jar as injars instead of libraryjars.
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200671legacy_proguard_flags := -injars $(link_instr_classes_jar) \
Ying Wang7311a342013-08-21 18:32:49 -0700672 -outjars $(intermediates.COMMON)/proguard.$(LOCAL_INSTRUMENTATION_FOR).jar \
673 -include $(link_instr_intermediates_dir.COMMON)/proguard_options \
674 -applymapping $(link_instr_intermediates_dir.COMMON)/proguard_dictionary \
675 -verbose \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200676 $(legacy_proguard_flags)
Ying Wang7311a342013-08-21 18:32:49 -0700677
678# Sometimes (test + main app) uses different keep rules from the main app -
679# apply the main app's dictionary anyway.
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200680legacy_proguard_flags += -ignorewarnings
Ying Wang7311a342013-08-21 18:32:49 -0700681
682# Make sure we run Proguard on the main app first
683$(full_classes_proguard_jar) : $(link_instr_intermediates_dir.COMMON)/proguard.classes.jar
684
685endif # no obfuscation
686endif # LOCAL_INSTRUMENTATION_FOR
687endif # LOCAL_PROGUARD_ENABLED is not nosystem
Joe Onorato2daa2b32009-08-30 13:39:24 -0700688
Ying Wang0b9382c2010-09-29 14:50:41 -0700689proguard_flag_files := $(addprefix $(LOCAL_PATH)/, $(LOCAL_PROGUARD_FLAG_FILES))
Søren Gjesse0c1fe642017-10-12 16:09:13 +0200690ifeq ($(USE_R8),true)
691proguard_flag_files += $(addprefix $(LOCAL_PATH)/, $(LOCAL_R8_FLAG_FILES))
692endif # USE_R8
Ying Wang0b9382c2010-09-29 14:50:41 -0700693LOCAL_PROGUARD_FLAGS += $(addprefix -include , $(proguard_flag_files))
694
Mihail Dumitrescu4df82b32014-02-07 15:18:59 +0000695ifdef LOCAL_TEST_MODULE_TO_PROGUARD_WITH
696extra_input_jar := $(call intermediates-dir-for,APPS,$(LOCAL_TEST_MODULE_TO_PROGUARD_WITH),,COMMON)/classes.jar
697else
698extra_input_jar :=
699endif
Paul Duffinf22aca12017-02-21 13:11:13 +0000700
Colin Crosse673deb2017-09-27 14:28:41 -0700701# If building against the current SDK version then filter out the junit,
702# android.test and c.a.i.u.Predicate classes that are to be removed from
703# the Android API as part of b/30188076 but which are still present in
704# the Android API. This is to allow changes to be made to the build to
705# statically include those classes into the application without
Paul Duffinf22aca12017-02-21 13:11:13 +0000706# simultaneously removing those classes from the API.
707proguard_injar_filters :=
Paul Duffinf22aca12017-02-21 13:11:13 +0000708ifdef LOCAL_SDK_VERSION
709ifeq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
Paul Duffin54747a72017-06-15 08:42:23 +0100710proguard_injar_filters := (!junit/framework/**,!junit/runner/**,!junit/textui/**,!android/test/**,!com/android/internal/util/*)
Paul Duffinf22aca12017-02-21 13:11:13 +0000711endif
712endif
Paul Duffinf22aca12017-02-21 13:11:13 +0000713
Dan Willemsenbdd6a752017-09-25 23:36:19 -0700714ifneq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
Søren Gjesse4ab5b022017-10-25 17:10:59 +0200715ifneq ($(USE_R8),true)
Dan Willemsenbdd6a752017-09-25 23:36:19 -0700716 $(full_classes_proguard_jar): .KATI_IMPLICIT_OUTPUTS := $(proguard_dictionary)
Søren Gjesse4ab5b022017-10-25 17:10:59 +0200717else
718 $(built_dex_intermediate): .KATI_IMPLICIT_OUTPUTS := $(proguard_dictionary)
719endif
Dan Willemsenbdd6a752017-09-25 23:36:19 -0700720endif
Søren Gjesse0c1fe642017-10-12 16:09:13 +0200721
722# If R8 is not enabled run Proguard.
723ifneq ($(USE_R8),true)
724# Changes to these dependencies need to be replicated below when using R8
725# instead of Proguard + dx.
Paul Duffinf22aca12017-02-21 13:11:13 +0000726$(full_classes_proguard_jar): PRIVATE_PROGUARD_INJAR_FILTERS := $(proguard_injar_filters)
Mihail Dumitrescu4df82b32014-02-07 15:18:59 +0000727$(full_classes_proguard_jar): PRIVATE_EXTRA_INPUT_JAR := $(extra_input_jar)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200728$(full_classes_proguard_jar): PRIVATE_PROGUARD_FLAGS := $(legacy_proguard_flags) $(common_proguard_flags) $(LOCAL_PROGUARD_FLAGS)
Colin Crossb5f25a22017-10-20 19:16:41 -0700729$(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)
Ying Wang3b2bdf12010-02-01 09:51:23 -0800730 $(call transform-jar-to-proguard)
Søren Gjesse0c1fe642017-10-12 16:09:13 +0200731else # !USE_R8
732# Running R8 instead of Proguard, proguarded jar is actually the pre-Proguarded jar.
733full_classes_proguard_jar := $(full_classes_pre_proguard_jar)
734endif # !USE_R8
Ying Wang3b2bdf12010-02-01 09:51:23 -0800735
Ying Wang7311a342013-08-21 18:32:49 -0700736else # LOCAL_PROGUARD_ENABLED not defined
ShuJie Wang76e93ba2017-11-06 14:35:52 +0800737proguard_flag_files :=
Colin Cross950f1ef2017-04-05 15:30:42 -0700738full_classes_proguard_jar := $(full_classes_pre_proguard_jar)
Ying Wang7311a342013-08-21 18:32:49 -0700739endif # LOCAL_PROGUARD_ENABLED defined
740
Colin Cross96476c12017-04-06 09:56:19 -0700741ifneq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
Colin Cross79e2f732016-12-21 14:29:13 -0800742$(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
Søren Gjesse0c1fe642017-10-12 16:09:13 +0200743
744my_r8 :=
745ifdef LOCAL_PROGUARD_ENABLED
746ifeq ($(USE_R8),true)
747# These are the dependencies for the proguarded jar when running
748# Proguard + dx. They are used for the generated dex when using R8, as
749# R8 does Proguard + dx
750my_r8 := true
751$(built_dex_intermediate): PRIVATE_PROGUARD_INJAR_FILTERS := $(proguard_injar_filters)
752$(built_dex_intermediate): PRIVATE_EXTRA_INPUT_JAR := $(extra_input_jar)
753$(built_dex_intermediate): PRIVATE_PROGUARD_FLAGS := $(legacy_proguard_flags) $(common_proguard_flags) $(LOCAL_PROGUARD_FLAGS)
Alan Leung7d6144d2017-11-16 15:51:07 -0800754$(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)
Søren Gjesse0c1fe642017-10-12 16:09:13 +0200755 $(transform-jar-to-dex-r8)
756endif # USE_R8
757endif # LOCAL_PROGUARD_ENABLED
758
759ifndef my_r8
Alan Leung5eb88c02017-12-20 20:03:58 -0800760$(built_dex_intermediate): $(full_classes_proguard_jar) $(DX) $(ZIP2ZIP)
Alan Leungeaafb3c2017-12-01 14:32:58 -0800761ifneq ($(USE_D8_DESUGAR),true)
Colin Cross79e2f732016-12-21 14:29:13 -0800762 $(transform-classes.jar-to-dex)
Alan Leungeaafb3c2017-12-01 14:32:58 -0800763else
764 $(transform-classes-d8.jar-to-dex)
765endif
Søren Gjesse0c1fe642017-10-12 16:09:13 +0200766endif
Colin Cross79e2f732016-12-21 14:29:13 -0800767
Colin Cross0e537342017-03-29 12:17:36 -0700768$(built_dex): $(built_dex_intermediate)
Guang Zhu155afe32010-03-10 15:48:03 -0800769 @echo Copying: $@
Yohann Roussel8ffe9c32013-08-20 17:05:27 +0200770 $(hide) mkdir -p $(dir $@)
771 $(hide) rm -f $(dir $@)/classes*.dex
Colin Cross0e537342017-03-29 12:17:36 -0700772 $(hide) cp -fp $(dir $<)/classes*.dex $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800773
Colin Cross9eff8302017-04-27 15:05:44 -0700774java-dex: $(built_dex)
775
Colin Cross96476c12017-04-06 09:56:19 -0700776endif # !LOCAL_IS_STATIC_JAVA_LIBRARY
777
The Android Open Source Project88b60792009-03-03 19:28:42 -0800778findbugs_xml := $(intermediates.COMMON)/findbugs.xml
Ying Wang702e01e2015-10-21 10:30:51 -0700779$(findbugs_xml): PRIVATE_AUXCLASSPATH := $(addprefix -auxclasspath ,$(strip \
780 $(call normalize-path-list,$(filter %.jar,$(full_java_libs)))))
781$(findbugs_xml): PRIVATE_FINDBUGS_FLAGS := $(LOCAL_FINDBUGS_FLAGS)
Colin Cross950f1ef2017-04-05 15:30:42 -0700782$(findbugs_xml) : $(full_classes_pre_proguard_jar) $(filter %.xml, $(LOCAL_FINDBUGS_FLAGS))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800783 @echo Findbugs: $@
784 $(hide) $(FINDBUGS) -textui -effort:min -xml:withMessages \
Ying Wang702e01e2015-10-21 10:30:51 -0700785 $(PRIVATE_AUXCLASSPATH) $(PRIVATE_FINDBUGS_FLAGS) \
Yohann Rousseld2a76c12015-02-05 16:10:58 +0100786 $< \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800787 > $@
788
789ALL_FINDBUGS_FILES += $(findbugs_xml)
790
791findbugs_html := $(PRODUCT_OUT)/findbugs/$(LOCAL_MODULE).html
792$(findbugs_html) : PRIVATE_XML_FILE := $(findbugs_xml)
793$(LOCAL_MODULE)-findbugs : $(findbugs_html)
794$(findbugs_html) : $(findbugs_xml)
795 @mkdir -p $(dir $@)
Andrew Stadlercef9ed92009-05-13 00:44:59 -0700796 @echo ConvertXmlToText: $@
Yuncheol Heo623d7062014-05-20 17:04:16 +0900797 $(hide) $(FINDBUGS_DIR)/convertXmlToText -html:fancy.xsl $(PRIVATE_XML_FILE) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800798 > $@
799
800$(LOCAL_MODULE)-findbugs : $(findbugs_html)
801
Ying Wang990cf5e2013-08-28 13:04:46 -0700802endif # full_classes_jar is defined
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200803
Colin Cross536ef4e2017-02-21 16:14:55 -0800804ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
Sundong Ahn5a44d1f2017-10-16 19:20:34 +0900805 my_default_app_target_sdk := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
806 my_sdk_version := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
Colin Cross536ef4e2017-02-21 16:14:55 -0800807else
Colin Cross9deb3312017-09-28 16:17:36 -0700808 my_default_app_target_sdk := $(DEFAULT_APP_TARGET_SDK)
809 my_sdk_version := $(PLATFORM_SDK_VERSION)
Colin Cross536ef4e2017-02-21 16:14:55 -0800810endif
811
Colin Cross9deb3312017-09-28 16:17:36 -0700812ifdef LOCAL_MIN_SDK_VERSION
813 my_min_sdk_version := $(LOCAL_MIN_SDK_VERSION)
814else
815 my_min_sdk_version := $(call codename-or-sdk-to-sdk,$(my_default_app_target_sdk))
816endif
817
818$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(my_default_app_target_sdk)
819$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SDK_VERSION := $(my_sdk_version)
820$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MIN_SDK_VERSION := $(my_min_sdk_version)