blob: dc204440034dca4781120e2856f4124c8c6d6e12 [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
David Brazdilb8fa6dd2018-01-29 14:43:14 +000076built_dex_hiddenapi := $(intermediates.COMMON)/dex-hiddenapi/classes.dex
Ying Wang957fea52010-09-23 11:48:38 -070077full_classes_stubs_jar := $(intermediates.COMMON)/stubs.jar
Colin Crossdfc45ec2017-05-26 15:22:02 -070078java_source_list_file := $(intermediates.COMMON)/java-source-list
79
Ying Wang957fea52010-09-23 11:48:38 -070080
Ying Wang37b82aa2013-08-28 17:28:36 -070081ifeq ($(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.
Ying Wang990cf5e2013-08-28 13:04:46 -070083full_classes_jar :=
84built_dex :=
85else
Ying Wang957fea52010-09-23 11:48:38 -070086full_classes_jar := $(intermediates.COMMON)/classes.jar
Ying Wang7b7929a2013-09-12 17:35:21 -070087built_dex := $(intermediates.COMMON)/classes.dex
Ying Wang990cf5e2013-08-28 13:04:46 -070088endif
Joe Onoratoe334d252009-07-17 15:33:40 -040089
90LOCAL_INTERMEDIATE_TARGETS += \
Nan Zhangb3ec5342017-08-31 21:43:04 +000091 $(full_classes_turbine_jar) \
Joe Onoratoe334d252009-07-17 15:33:40 -040092 $(full_classes_compiled_jar) \
Colin Crosseac5ce42016-12-21 17:11:03 -080093 $(full_classes_desugar_jar) \
Ying Wang957fea52010-09-23 11:48:38 -070094 $(full_classes_jarjar_jar) \
Ying Wang957fea52010-09-23 11:48:38 -070095 $(full_classes_jar) \
Nan Zhang9bd54052017-09-13 13:13:53 -070096 $(full_classes_combined_jar) \
Ying Wanga9c381e2010-10-02 18:35:51 -070097 $(full_classes_proguard_jar) \
Ying Wang957fea52010-09-23 11:48:38 -070098 $(built_dex_intermediate) \
Guang Zhu155afe32010-03-10 15:48:03 -080099 $(built_dex) \
Colin Crossdfc45ec2017-05-26 15:22:02 -0700100 $(full_classes_stubs_jar) \
101 $(java_source_list_file)
Ying Wang957fea52010-09-23 11:48:38 -0700102
Joe Onorato77dc0a52010-05-17 18:16:11 -0700103LOCAL_INTERMEDIATE_SOURCE_DIR := $(intermediates.COMMON)/src
Joe Onoratoe334d252009-07-17 15:33:40 -0400104
Ying Wang0bd59a02010-07-15 17:17:52 -0700105###############################################################
106## .rs files: RenderScript sources to .java files and .bc files
Stephen Hines0ab6e3e2012-10-11 15:01:53 -0700107## .fs files: Filterscript sources to .java files and .bc files
Ying Wang0bd59a02010-07-15 17:17:52 -0700108###############################################################
Stephen Hines0ab6e3e2012-10-11 15:01:53 -0700109renderscript_sources := $(filter %.rs %.fs,$(LOCAL_SRC_FILES))
Ying Wang0bd59a02010-07-15 17:17:52 -0700110# Because names of the java files from RenderScript are unknown until the
111# .rs file(s) are compiled, we have to depend on a timestamp file.
112RenderScript_file_stamp :=
Ying Wangdd71c852015-12-04 13:59:18 -0800113rs_generated_res_dir :=
Stephen Hines3b0fa102013-02-06 16:19:30 -0800114rs_compatibility_jni_libs :=
Ying Wang0bd59a02010-07-15 17:17:52 -0700115ifneq ($(renderscript_sources),)
116renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
117RenderScript_file_stamp := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/RenderScript.stamp
Dan Willemsencf324af2016-12-21 17:37:00 -0800118renderscript_intermediate.COMMON := $(intermediates.COMMON)/renderscript
Ying Wang0bd59a02010-07-15 17:17:52 -0700119
Miao Wang302e9442015-07-28 17:43:51 -0700120# Defaulting to an empty string uses the latest available platform SDK.
Stephen Hinesc963eae2011-08-10 13:53:05 -0700121renderscript_target_api :=
Stephen Hinesa941d132011-08-29 18:53:53 -0700122
123ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API))
Miao Wang302e9442015-07-28 17:43:51 -0700124 renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API)
Stephen Hinesa941d132011-08-29 18:53:53 -0700125else
Miao Wang302e9442015-07-28 17:43:51 -0700126 ifneq (,$(LOCAL_SDK_VERSION))
127 # Set target-api for LOCAL_SDK_VERSIONs other than current.
Jiyong Park5ebca302018-01-31 00:14:55 +0900128 ifneq (,$(filter-out current system_current test_current core_current, $(LOCAL_SDK_VERSION)))
Sundong Ahn5a44d1f2017-10-16 19:20:34 +0900129 renderscript_target_api := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
Miao Wang302e9442015-07-28 17:43:51 -0700130 endif
131 endif # LOCAL_SDK_VERSION is set
Stephen Hinesa941d132011-08-29 18:53:53 -0700132endif # LOCAL_RENDERSCRIPT_TARGET_API is set
Stephen Hinesc963eae2011-08-10 13:53:05 -0700133
Miao Wanga11f6c22015-07-29 11:46:23 -0700134# For 64-bit, we always have to upgrade to at least 21 for compat build.
135ifneq ($(LOCAL_RENDERSCRIPT_COMPATIBILITY),)
136 ifeq ($(TARGET_IS_64_BIT),true)
137 ifneq ($(filter $(RSCOMPAT_32BIT_ONLY_API_LEVELS),$(renderscript_target_api)),)
138 renderscript_target_api := 21
139 endif
Miao Wang302e9442015-07-28 17:43:51 -0700140 endif
141endif
142
Stephen Hinesc963eae2011-08-10 13:53:05 -0700143ifeq ($(LOCAL_RENDERSCRIPT_CC),)
144LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC)
145endif
146
Stephen Hines914f7a22011-12-06 18:43:24 -0800147# Turn on all warnings and warnings as errors for RS compiles.
148# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
149renderscript_flags := -Wall -Werror
150renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)
151
Ying Wang51280272010-09-01 13:28:52 -0700152# prepend the RenderScript system include path
Jiyong Park5ebca302018-01-31 00:14:55 +0900153ifneq ($(filter-out current system_current test_current core_current,$(LOCAL_SDK_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current test_current,$(LOCAL_SDK_VERSION))),)
Ying Wang0ec188f2012-05-10 17:25:51 -0700154# if a numeric LOCAL_SDK_VERSION, or current LOCAL_SDK_VERSION with TARGET_BUILD_APPS
Ying Wangfcf00d52011-03-29 11:47:12 -0700155LOCAL_RENDERSCRIPT_INCLUDES := \
Stephen Hines5a4eb5f2012-03-06 21:48:36 -0800156 $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/clang-include \
157 $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/include \
Ying Wangfcf00d52011-03-29 11:47:12 -0700158 $(LOCAL_RENDERSCRIPT_INCLUDES)
159else
Ying Wang85aa5de2011-01-19 11:49:21 -0800160LOCAL_RENDERSCRIPT_INCLUDES := \
Stephen Hinesc963eae2011-08-10 13:53:05 -0700161 $(TOPDIR)external/clang/lib/Headers \
Jean-Luc Brouilleteba44932017-01-08 17:40:21 -0800162 $(TOPDIR)frameworks/rs/script_api/include \
Stephen Hinesc963eae2011-08-10 13:53:05 -0700163 $(LOCAL_RENDERSCRIPT_INCLUDES)
Ying Wang7d83ef82011-05-25 17:16:22 -0700164endif
165
Stephen Hinesd4136c02011-08-23 22:01:49 -0700166ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),)
167LOCAL_RENDERSCRIPT_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE)
168endif
169
Ying Wangb9319562015-04-03 16:15:28 -0700170bc_files := $(patsubst %.fs,%.bc, $(patsubst %.rs,%.bc, $(notdir $(renderscript_sources))))
171bc_dep_files := $(addprefix $(renderscript_intermediate.COMMON)/,$(patsubst %.bc,%.d,$(bc_files)))
172
Ying Wang51280272010-09-01 13:28:52 -0700173$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES)
Ying Wang7d83ef82011-05-25 17:16:22 -0700174$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC)
Stephen Hines914f7a22011-12-06 18:43:24 -0800175$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags)
Ying Wang0bd59a02010-07-15 17:17:52 -0700176$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath)
177# By putting the generated java files into $(LOCAL_INTERMEDIATE_SOURCE_DIR), they will be
178# automatically found by the java compiling function transform-java-to-classes.jar.
Ying Wang370fa672013-02-25 16:06:42 -0800179$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate.COMMON)
Stephen Hinesc963eae2011-08-10 13:53:05 -0700180$(RenderScript_file_stamp): PRIVATE_RS_TARGET_API := $(renderscript_target_api)
Ying Wangb9319562015-04-03 16:15:28 -0700181$(RenderScript_file_stamp): PRIVATE_DEP_FILES := $(bc_dep_files)
Ying Wang7d83ef82011-05-25 17:16:22 -0700182$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC)
Ying Wang0bd59a02010-07-15 17:17:52 -0700183 $(transform-renderscripts-to-java-and-bc)
184
Ying Wangb9319562015-04-03 16:15:28 -0700185# include the dependency files (.d/.P) generated by llvm-rs-cc.
Shinichiro Hamaji52a1d6c2016-02-01 17:59:01 +0900186$(call include-depfile,$(RenderScript_file_stamp).P,$(RenderScript_file_stamp))
Ying Wangcddece62015-04-03 09:53:41 -0700187
Stephen Hinese719f282012-11-28 16:52:41 -0800188ifneq ($(LOCAL_RENDERSCRIPT_COMPATIBILITY),)
Miao Wange4359cf2015-01-07 18:18:41 -0800189
190
191ifeq ($(filter $(RSCOMPAT_32BIT_ONLY_API_LEVELS),$(renderscript_target_api)),)
192ifeq ($(TARGET_IS_64_BIT),true)
193renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/bc64/
194else
195renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/bc32/
196endif
197else
198renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/
199endif
200
Stephen Hinese719f282012-11-28 16:52:41 -0800201rs_generated_bc := $(addprefix \
Miao Wange4359cf2015-01-07 18:18:41 -0800202 $(renderscript_intermediate.bc_folder), $(bc_files))
Stephen Hinese719f282012-11-28 16:52:41 -0800203
Ying Wang370fa672013-02-25 16:06:42 -0800204renderscript_intermediate := $(intermediates)/renderscript
Tim Murray8e0567a2013-05-13 15:46:37 -0700205
206# We don't need the .so files in bundled branches
207# Prevent these from showing up on the device
Miao Wangc919b0b2015-02-12 16:22:59 -0800208# One exception is librsjni.so, which is needed for
209# both native path and compat path.
210rs_jni_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/librsjni.so
211LOCAL_JNI_SHARED_LIBRARIES += librsjni
212
Stephen Hinesc54e81c2013-09-30 15:57:36 -0700213ifneq (,$(TARGET_BUILD_APPS)$(FORCE_BUILD_RS_COMPAT))
Tim Murray8e0567a2013-05-13 15:46:37 -0700214
Stephen Hinese719f282012-11-28 16:52:41 -0800215rs_compatibility_jni_libs := $(addprefix \
Stephen Hinesec02b4f2013-02-15 23:02:20 -0800216 $(renderscript_intermediate)/librs., \
Stephen Hinese719f282012-11-28 16:52:41 -0800217 $(patsubst %.bc,%.so, $(bc_files)))
218
219$(rs_generated_bc) : $(RenderScript_file_stamp)
220
Stephen Hinesf6925132012-12-17 14:23:14 -0800221rs_support_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/libRSSupport.so
Miao Wangc919b0b2015-02-12 16:22:59 -0800222LOCAL_JNI_SHARED_LIBRARIES += libRSSupport
Stephen Hinesf6925132012-12-17 14:23:14 -0800223
Miao Wangec27a892014-11-20 11:05:18 -0800224rs_support_io_lib :=
225# check if the target api level support USAGE_IO
226ifeq ($(filter $(RSCOMPAT_NO_USAGEIO_API_LEVELS),$(renderscript_target_api)),)
227rs_support_io_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/libRSSupportIO.so
228LOCAL_JNI_SHARED_LIBRARIES += libRSSupportIO
229endif
Tim Murray8e0567a2013-05-13 15:46:37 -0700230
Miao Wang28e78f42017-08-16 16:05:26 -0700231my_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
232ifneq (,$(filter arm64 mips64 x86_64,$(my_arch)))
233 my_min_sdk_version := 21
234else
235 my_min_sdk_version := $(MIN_SUPPORTED_SDK_VERSION)
236endif
Tim Murray8e0567a2013-05-13 15:46:37 -0700237
Tim Murray1a6f09a2013-03-05 11:07:15 -0800238$(rs_compatibility_jni_libs): $(RenderScript_file_stamp) $(RS_PREBUILT_CLCORE) \
Miao Wangec27a892014-11-20 11:05:18 -0800239 $(rs_support_lib) $(rs_support_io_lib) $(rs_jni_lib) $(rs_compiler_rt)
Stephen Hines8db4cce2013-03-27 16:51:38 -0700240$(rs_compatibility_jni_libs): $(BCC_COMPAT)
Ying Wang57d90602015-07-20 18:40:18 -0700241$(rs_compatibility_jni_libs): PRIVATE_CXX := $(CXX_WRAPPER) $(TARGET_CXX)
Miao Wang28e78f42017-08-16 16:05:26 -0700242$(rs_compatibility_jni_libs): PRIVATE_SDK_VERSION := $(my_min_sdk_version)
Stephen Hinesec02b4f2013-02-15 23:02:20 -0800243$(rs_compatibility_jni_libs): $(renderscript_intermediate)/librs.%.so: \
Miao Wang28e78f42017-08-16 16:05:26 -0700244 $(renderscript_intermediate.bc_folder)%.bc \
245 $(SOONG_OUT_DIR)/ndk.timestamp
Stephen Hinese719f282012-11-28 16:52:41 -0800246 $(transform-bc-to-so)
247
248endif
249
Tim Murray8e0567a2013-05-13 15:46:37 -0700250endif
251
Ying Wang0bd59a02010-07-15 17:17:52 -0700252LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
253# Make sure the generated resource will be added to the apk.
Ying Wangdd71c852015-12-04 13:59:18 -0800254rs_generated_res_dir := $(renderscript_intermediate.COMMON)/res
255LOCAL_RESOURCE_DIR := $(rs_generated_res_dir) $(LOCAL_RESOURCE_DIR)
Ying Wang0bd59a02010-07-15 17:17:52 -0700256endif
257
Ying Wang956dccc2015-08-28 11:47:03 -0700258
259###########################################################
260## AIDL: Compile .aidl files to .java
261###########################################################
262aidl_sources := $(filter %.aidl,$(LOCAL_SRC_FILES))
Christopher Wileyd9205ba2016-06-23 16:44:47 -0700263aidl_java_sources :=
Ying Wang956dccc2015-08-28 11:47:03 -0700264
265ifneq ($(strip $(aidl_sources)),)
Ying Wang956dccc2015-08-28 11:47:03 -0700266
267aidl_preprocess_import :=
268ifdef LOCAL_SDK_VERSION
Jiyong Park5ebca302018-01-31 00:14:55 +0900269ifneq ($(filter current system_current test_current core_current, $(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS)),)
Ying Wang956dccc2015-08-28 11:47:03 -0700270 # LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS
271 aidl_preprocess_import := $(TARGET_OUT_COMMON_INTERMEDIATES)/framework.aidl
272else
273 aidl_preprocess_import := $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_VERSION)/framework.aidl
274endif # not current or system_current
275else
276# build against the platform.
277LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)
278endif # LOCAL_SDK_VERSION
Ying Wang956dccc2015-08-28 11:47:03 -0700279
Christopher Wileyd9205ba2016-06-23 16:44:47 -0700280$(foreach s,$(aidl_sources),\
Dan Willemsen4d995272017-09-29 17:37:31 -0700281 $(eval $(call define-aidl-java-rule,$(s),$(intermediates.COMMON)/aidl,aidl_java_sources)))
Shinichiro Hamaji2a0d1fe2016-01-28 16:10:00 +0900282$(foreach java,$(aidl_java_sources), \
283 $(call include-depfile,$(java:%.java=%.P),$(java)))
Ying Wang956dccc2015-08-28 11:47:03 -0700284
Christopher Wileyd9205ba2016-06-23 16:44:47 -0700285$(aidl_java_sources) : $(LOCAL_ADDITIONAL_DEPENDENCIES) $(aidl_preprocess_import)
286
287$(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 -0700288$(aidl_java_sources): PRIVATE_MODULE := $(LOCAL_MODULE)
Christopher Wileyd9205ba2016-06-23 16:44:47 -0700289
Ying Wang956dccc2015-08-28 11:47:03 -0700290endif
291
Ying Wang956dccc2015-08-28 11:47:03 -0700292##########################################
293
Ying Wang1d977e32013-01-30 11:22:06 -0800294# All of the rules after full_classes_compiled_jar are very unlikely
295# to fail except for bugs in their respective tools. If you would
296# like to run these rules, add the "all" modifier goal to the make
297# command line.
Ying Wang447d6962015-09-01 19:12:05 -0700298ifndef LOCAL_CHECKED_MODULE
Jean-Philippe Lesot0fbc9ff2015-01-20 14:18:48 +0000299ifdef full_classes_jar
Colin Crossb17f2852017-04-27 13:34:02 -0700300LOCAL_CHECKED_MODULE := $(full_classes_compiled_jar)
Ying Wang990cf5e2013-08-28 13:04:46 -0700301endif
Yohann Rousselee572682015-08-18 19:18:18 +0200302endif
Ying Wang1d977e32013-01-30 11:22:06 -0800303
The Android Open Source Project88b60792009-03-03 19:28:42 -0800304#######################################
305include $(BUILD_SYSTEM)/base_rules.mk
306#######################################
307
Yasuhiro Matsudaff82e822015-09-04 16:23:49 +0900308###########################################################
309## logtags: emit java source
310###########################################################
311ifneq ($(strip $(logtags_sources)),)
312
Dan Willemsen4d995272017-09-29 17:37:31 -0700313logtags_java_sources := $(patsubst %.logtags,%.java,$(addprefix $(intermediates.COMMON)/logtags/, $(logtags_sources)))
Yasuhiro Matsudaff82e822015-09-04 16:23:49 +0900314logtags_sources := $(addprefix $(LOCAL_PATH)/, $(logtags_sources))
315
Shinichiro Hamajid3ce14c2016-03-29 03:29:21 +0900316$(logtags_java_sources): PRIVATE_MERGED_TAG := $(TARGET_OUT_COMMON_INTERMEDIATES)/all-event-log-tags.txt
Colin Crossfdea8932017-12-06 14:38:40 -0800317$(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 +0900318 $(transform-logtags-to-java)
319
320else
321logtags_java_sources :=
322endif
323
Ying Wang956dccc2015-08-28 11:47:03 -0700324##########################################
325java_sources := $(addprefix $(LOCAL_PATH)/, $(filter %.java,$(LOCAL_SRC_FILES))) $(aidl_java_sources) $(logtags_java_sources) \
326 $(filter %.java,$(LOCAL_GENERATED_SOURCES))
Nan Zhangad818dc2017-10-04 09:26:06 -0700327java_intermediate_sources := $(addprefix $(TARGET_OUT_COMMON_INTERMEDIATES)/, $(filter %.java,$(LOCAL_INTERMEDIATE_SOURCES)))
328all_java_sources := $(java_sources) $(java_intermediate_sources)
329
330enable_sharding :=
331ifneq ($(TURBINE_ENABLED),false)
332ifneq ($(LOCAL_JAVAC_SHARD_SIZE),)
333ifneq ($(LOCAL_JAR_PROCESSOR),)
334$(call pretty-error,Cannot set both LOCAL_JAVAC_SHARD_SIZE and LOCAL_JAR_PROCESSOR!)
335endif # LOCAL_JAR_PROCESSOR is not empty
336enable_sharding := true
337
338num_shards := $(call int_divide,$(words $(java_sources)),$(LOCAL_JAVAC_SHARD_SIZE))
339ifneq ($(words $(java_sources)),$(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(num_shards)))
340# increment number of shards by 1.
341num_shards := $(call int_plus,$(num_shards),1)
342endif
343
344shard_idx_list := $(call int_range_list,1,$(num_shards))
345sharded_java_source_list_files += $(foreach x,$(shard_idx_list),$(java_source_list_file).shard.$(x))
346sharded_jar_list += $(foreach x,$(shard_idx_list),$(full_classes_compiled_jar).shard.$(x))
347
348# always put dynamically-located .java files (generated by Proto/resource, etc) in a new final shard.
349# increment number of shards by 1.
350num_shards := $(call int_plus,$(num_shards),1)
351sharded_java_source_list_files += $(java_source_list_file).shard.$(num_shards)
352sharded_jar_list += $(full_classes_compiled_jar).shard.$(num_shards)
353LOCAL_INTERMEDIATE_TARGETS += $(sharded_java_source_list_files)
354LOCAL_INTERMEDIATE_TARGETS += $(sharded_jar_list)
355endif # LOCAL_JAVAC_SHARD_SIZE is not empty
356endif # TURBINE_ENABLED != false
Ying Wang956dccc2015-08-28 11:47:03 -0700357
358include $(BUILD_SYSTEM)/java_common.mk
359
Anton Hansson7ff32d22018-02-21 15:29:44 +0000360include $(BUILD_SYSTEM)/sdk_check.mk
361
Dan Willemsencf324af2016-12-21 17:37:00 -0800362$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HAS_RS_SOURCES := $(if $(renderscript_sources),true)
363$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RS_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/renderscript
364
Narayan Kamathbbcdc072017-08-22 15:47:08 +0100365# Set the profile source so that the odex / profile code included from java.mk
366# can find it.
367#
368# TODO: b/64896089, this is broken when called from package_internal.mk, since the file
369# we preopt from is a temporary file. This will be addressed in a follow up, possibly
370# by disabling stripping for profile guided preopt (which may be desirable for other
371# reasons anyway).
372#
373# Note that we set this only when called from package_internal.mk and not in other cases.
374ifneq (,$(called_from_package_internal)
375dex_preopt_profile_src_file := $(LOCAL_BUILT_MODULE)
376endif
377
Brian Carlstromced4bff2013-11-14 23:44:56 -0800378#######################################
379# defines built_odex along with rule to install odex
380include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
381#######################################
382
Ying Wang990cf5e2013-08-28 13:04:46 -0700383# Make sure there's something to build.
384ifdef full_classes_jar
385ifndef need_compile_java
Jeff Gaston960acf12018-02-26 21:00:25 -0500386$(call pretty-error,Target java module does not define any source or resource files)
Ying Wang990cf5e2013-08-28 13:04:46 -0700387endif
388endif
389
The Android Open Source Project88b60792009-03-03 19:28:42 -0800390# Since we're using intermediates.COMMON, make sure that it gets cleaned
391# properly.
392$(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON)
393
Ying Wang990cf5e2013-08-28 13:04:46 -0700394ifdef full_classes_jar
The Android Open Source Project88b60792009-03-03 19:28:42 -0800395
Joe Onorato64d85d02009-04-09 19:31:12 -0700396# Droiddoc isn't currently able to generate stubs for modules, so we're just
397# allowing it to use the classes.jar as the "stubs" that would be use to link
398# against, for the cases where someone needs the jar to link against.
Colin Cross0e537342017-03-29 12:17:36 -0700399$(eval $(call copy-one-file,$(full_classes_jar),$(full_classes_stubs_jar)))
Joe Onorato64d85d02009-04-09 19:31:12 -0700400ALL_MODULES.$(LOCAL_MODULE).STUBS := $(full_classes_stubs_jar)
401
Joe Onorato0eccce92011-10-30 21:37:35 -0700402# The layers file allows you to enforce a layering between java packages.
Colin Crossfdea8932017-12-06 14:38:40 -0800403# Run build/make/tools/java-layers.py for more details.
Joe Onorato0eccce92011-10-30 21:37:35 -0700404layers_file := $(addprefix $(LOCAL_PATH)/, $(LOCAL_JAVA_LAYERS_FILE))
405$(full_classes_compiled_jar): PRIVATE_JAVA_LAYERS_FILE := $(layers_file)
Ying Wang057eba02012-10-18 10:54:49 -0700406$(full_classes_compiled_jar): PRIVATE_WARNINGS_ENABLE := $(LOCAL_WARNINGS_ENABLE)
Joe Onorato0eccce92011-10-30 21:37:35 -0700407
The Android Open Source Project88b60792009-03-03 19:28:42 -0800408# Compile the java files to a .jar file.
409# This intentionally depends on java_sources, not all_java_sources.
410# Deps for generated source files must be handled separately,
411# via deps on the target that generates the sources.
Paul Duffin3ca92982016-09-20 15:12:30 +0100412
413# If error prone is enabled then add LOCAL_ERROR_PRONE_FLAGS to LOCAL_JAVACFLAGS
414ifeq ($(RUN_ERROR_PRONE),true)
415LOCAL_JAVACFLAGS += $(LOCAL_ERROR_PRONE_FLAGS)
416endif
417
Przemyslaw Szczepaniak2e81b3c2017-06-30 14:51:12 +0100418# For user / userdebug builds, strip the local variable table and the local variable
419# type table. This has no bearing on stack traces, but will leave less information
420# available via JDWP.
421ifneq (,$(PRODUCT_MINIMIZE_JAVA_DEBUG_INFO))
422ifneq (,$(filter userdebug user,$(TARGET_BUILD_VARIANT)))
423LOCAL_JAVACFLAGS+= -g:source,lines
Przemyslaw Szczepaniak2e81b3c2017-06-30 14:51:12 +0100424endif
425endif
426
Colin Crossdfc45ec2017-05-26 15:22:02 -0700427# List of dependencies for anything that needs all java sources in place
428java_sources_deps := \
429 $(java_sources) \
430 $(java_resource_sources) \
431 $(RenderScript_file_stamp) \
432 $(proto_java_sources_file_stamp) \
433 $(LOCAL_ADDITIONAL_DEPENDENCIES)
434
435$(java_source_list_file): $(java_sources_deps)
436 $(write-java-source-list)
437
Nan Zhangad818dc2017-10-04 09:26:06 -0700438ifdef enable_sharding
439$(foreach x,$(shard_idx_list),\
440 $(eval $(call save-sharded-java-source-list,$(x),\
441 $(wordlist $(call int_plus,1,$(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(call int_subtract,$(x),1))),\
442 $(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(x)),$(sort $(java_sources))))))
443
444# always put dynamically-located .java files (generated by Proto/resource, etc) in a new final shard.
445$(java_source_list_file).shard.$(num_shards): PRIVATE_JAVA_INTERMEDIATE_SOURCES := $(java_intermediate_sources)
446$(java_source_list_file).shard.$(num_shards): $(java_resource_sources) \
447 $(RenderScript_file_stamp) \
448 $(proto_java_sources_file_stamp) \
449 $(LOCAL_ADDITIONAL_DEPENDENCIES) \
450 $(NORMALIZE_PATH)
451 $(hide) rm -f $@
452 $(call dump-words-to-file,$(PRIVATE_JAVA_INTERMEDIATE_SOURCES),$@.tmp)
453 $(call fetch-additional-java-source,$@.tmp)
454 $(hide) tr ' ' '\n' < $@.tmp | $(NORMALIZE_PATH) | sort -u > $@
455
456# Javac sharding with header libs including its own header jar as one of dependency.
457$(foreach x,$(shard_idx_list),\
458 $(eval $(call create-classes-full-debug.jar,$(full_classes_compiled_jar).shard.$(x),\
459 $(java_source_list_file).shard.$(x),\
460 $(full_java_header_libs) $(full_classes_header_jar),$(x),\
461 $(wordlist $(call int_plus,1,$(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(call int_subtract,$(x),1))),\
462 $(call int_multiply,$(LOCAL_JAVAC_SHARD_SIZE),$(x)),$(sort $(java_sources))))))
463
464# Javac sharding for last shard with additional Java dependencies.
465$(eval $(call create-classes-full-debug.jar,$(full_classes_compiled_jar).shard.$(num_shards),\
466 $(java_source_list_file).shard.$(num_shards),$(full_java_header_libs) $(full_classes_header_jar),$(strip \
467 $(num_shards)),$$(java_resource_sources) $$(RenderScript_file_stamp) \
468 $$(proto_java_sources_file_stamp) $$(LOCAL_ADDITIONAL_DEPENDENCIES)))
469
470$(full_classes_compiled_jar): PRIVATE_SHARDED_JAR_LIST := $(sharded_jar_list)
471$(full_classes_compiled_jar): $(sharded_jar_list) | $(MERGE_ZIPS)
472 $(MERGE_ZIPS) -j $@ $(PRIVATE_SHARDED_JAR_LIST)
473else
474# we can't use single $ for java_sources_deps since it may contain hash '#' sign.
475$(eval $(call create-classes-full-debug.jar,$(full_classes_compiled_jar),\
476 $(java_source_list_file),$(full_java_header_libs),,$$(java_sources_deps)))
477
478endif # ifdef enable_sharding
The Android Open Source Project88b60792009-03-03 19:28:42 -0800479
Colin Cross7dc90432017-09-26 16:17:24 -0700480ifneq ($(TURBINE_ENABLED),false)
481
Nan Zhangb3ec5342017-08-31 21:43:04 +0000482$(full_classes_turbine_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) $(annotation_processor_flags)
483$(full_classes_turbine_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
484$(full_classes_turbine_jar): \
485 $(java_source_list_file) \
486 $(java_sources_deps) \
487 $(full_java_header_libs) \
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700488 $(full_java_bootclasspath_libs) \
Colin Crossf9602572017-10-12 13:34:40 -0700489 $(full_java_system_modules_deps) \
Nan Zhangb3ec5342017-08-31 21:43:04 +0000490 $(NORMALIZE_PATH) \
491 $(JAR_ARGS) \
492 $(ZIPTIME) \
Nan Zhang9bd54052017-09-13 13:13:53 -0700493 | $(TURBINE) \
494 $(MERGE_ZIPS)
Nan Zhangb3ec5342017-08-31 21:43:04 +0000495 $(transform-java-to-header.jar)
496
497.KATI_RESTAT: $(full_classes_turbine_jar)
498
499# Run jarjar before generate classes-header.jar if necessary.
500ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
501$(full_classes_header_jarjar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
502$(full_classes_header_jarjar): $(full_classes_turbine_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
503 @echo Header JarJar: $@
504 $(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
505else
506full_classes_header_jarjar := $(full_classes_turbine_jar)
507endif
508
509$(eval $(call copy-one-file,$(full_classes_header_jarjar),$(full_classes_header_jar)))
510
Colin Cross7dc90432017-09-26 16:17:24 -0700511endif # TURBINE_ENABLED != false
512
Ying Wangcddeb6c2016-03-24 11:00:30 -0700513javac-check : $(full_classes_compiled_jar)
Paul Duffin32bd0ad2016-09-15 14:34:42 +0100514javac-check-$(LOCAL_MODULE) : $(full_classes_compiled_jar)
Ying Wangcddeb6c2016-03-24 11:00:30 -0700515
Nan Zhang9bd54052017-09-13 13:13:53 -0700516$(full_classes_combined_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
517$(full_classes_combined_jar): $(full_classes_compiled_jar) \
Nan Zhangb8801172017-09-20 14:56:48 -0700518 $(jar_manifest_file) \
Nan Zhang9bd54052017-09-13 13:13:53 -0700519 $(full_static_java_libs) | $(MERGE_ZIPS)
Nan Zhangb8801172017-09-20 14:56:48 -0700520 $(if $(PRIVATE_JAR_MANIFEST), $(hide) sed -e "s/%BUILD_NUMBER%/$(BUILD_NUMBER_FROM_FILE)/" \
521 $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf)
Colin Cross5b73ab32018-02-14 10:32:48 -0800522 $(MERGE_ZIPS) -j --ignore-duplicates $(if $(PRIVATE_JAR_MANIFEST),-m $(dir $@)/manifest.mf) \
Nan Zhangb8801172017-09-20 14:56:48 -0700523 $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,-stripDir META-INF -zipToNotStrip $<) \
524 $@ $< $(call reverse-list,$(PRIVATE_STATIC_JAVA_LIBRARIES))
Nan Zhang9bd54052017-09-13 13:13:53 -0700525
Colin Crossf8a49c52017-05-22 16:21:49 -0700526ifdef LOCAL_JAR_PROCESSOR
527# LOCAL_JAR_PROCESSOR_ARGS must be evaluated here to set up the rule-local
528# PRIVATE_JAR_PROCESSOR_ARGS variable, but $< and $@ are not available yet.
529# Set ${in} and ${out} so they can be referenced by LOCAL_JAR_PROCESSOR_ARGS
530# using deferred evaluation (LOCAL_JAR_PROCESSOR_ARGS = instead of :=).
Nan Zhang9bd54052017-09-13 13:13:53 -0700531in := $(full_classes_combined_jar)
Colin Crossf8a49c52017-05-22 16:21:49 -0700532out := $(full_classes_processed_jar).tmp
Colin Cross89b802b2017-07-13 19:25:47 -0700533my_jar_processor := $(HOST_OUT_JAVA_LIBRARIES)/$(LOCAL_JAR_PROCESSOR).jar
534
Colin Crossf8a49c52017-05-22 16:21:49 -0700535$(full_classes_processed_jar): PRIVATE_JAR_PROCESSOR_ARGS := $(LOCAL_JAR_PROCESSOR_ARGS)
Colin Cross89b802b2017-07-13 19:25:47 -0700536$(full_classes_processed_jar): PRIVATE_JAR_PROCESSOR := $(my_jar_processor)
Colin Crossf8a49c52017-05-22 16:21:49 -0700537$(full_classes_processed_jar): PRIVATE_TMP_OUT := $(out)
538in :=
539out :=
540
Nan Zhang9bd54052017-09-13 13:13:53 -0700541$(full_classes_processed_jar): $(full_classes_combined_jar) $(my_jar_processor)
Colin Crossf8a49c52017-05-22 16:21:49 -0700542 @echo Processing $@ with $(PRIVATE_JAR_PROCESSOR)
543 $(hide) rm -f $@ $(PRIVATE_TMP_OUT)
Colin Cross0851df82017-06-30 13:55:38 -0700544 $(hide) $(JAVA) -jar $(PRIVATE_JAR_PROCESSOR) $(PRIVATE_JAR_PROCESSOR_ARGS)
Colin Crossf8a49c52017-05-22 16:21:49 -0700545 $(hide) mv $(PRIVATE_TMP_OUT) $@
546
Colin Cross89b802b2017-07-13 19:25:47 -0700547my_jar_processor :=
Colin Crossf8a49c52017-05-22 16:21:49 -0700548else
Nan Zhang9bd54052017-09-13 13:13:53 -0700549full_classes_processed_jar := $(full_classes_combined_jar)
Colin Crossf8a49c52017-05-22 16:21:49 -0700550endif
551
Nan Zhang870025f2017-09-13 14:56:11 -0700552# Run jarjar if necessary
553ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
554$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
555$(full_classes_jarjar_jar): $(full_classes_processed_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
556 @echo JarJar: $@
557 $(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
558else
559full_classes_jarjar_jar := $(full_classes_processed_jar)
560endif
561
562$(eval $(call copy-one-file,$(full_classes_jarjar_jar),$(full_classes_jar)))
563
Colin Cross96873482017-12-22 16:51:23 -0800564LOCAL_FULL_CLASSES_PRE_JACOCO_JAR := $(full_classes_jar)
565
566#######################################
567include $(BUILD_SYSTEM)/jacoco.mk
568#######################################
569
Tobias Thierer7ef760b2017-11-17 13:02:12 +0000570# Temporarily enable --multi-dex until proguard supports v53 class files
571# ( http://b/67673860 ) or we move away from proguard altogether.
Tobias Thiererf6bd4952017-11-15 20:55:03 +0000572ifdef TARGET_OPENJDK9
Tobias Thierer89740662017-10-25 02:38:01 +0100573LOCAL_DX_FLAGS := $(filter-out --multi-dex,$(LOCAL_DX_FLAGS)) --multi-dex
574endif
575
Alan Leungeaafb3c2017-12-01 14:32:58 -0800576ifneq ($(USE_D8_DESUGAR),true)
Colin Crosseac5ce42016-12-21 17:11:03 -0800577my_desugaring :=
Colin Cross31060fd2017-03-21 10:17:04 -0700578ifndef LOCAL_IS_STATIC_JAVA_LIBRARY
Colin Crosseac5ce42016-12-21 17:11:03 -0800579my_desugaring := true
580$(full_classes_desugar_jar): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
Colin Cross96873482017-12-22 16:51:23 -0800581$(full_classes_desugar_jar): $(LOCAL_FULL_CLASSES_JACOCO_JAR) $(full_java_header_libs) $(DESUGAR)
Colin Crosseac5ce42016-12-21 17:11:03 -0800582 $(desugar-classes-jar)
583endif
Alan Leungeaafb3c2017-12-01 14:32:58 -0800584else
585my_desugaring :=
586endif
Colin Crosseac5ce42016-12-21 17:11:03 -0800587
588ifndef my_desugaring
Colin Cross96873482017-12-22 16:51:23 -0800589full_classes_desugar_jar := $(LOCAL_FULL_CLASSES_JACOCO_JAR)
Colin Crosseac5ce42016-12-21 17:11:03 -0800590endif
591
Colin Cross96873482017-12-22 16:51:23 -0800592full_classes_pre_proguard_jar := $(full_classes_desugar_jar)
Ying Wang3b2bdf12010-02-01 09:51:23 -0800593
Colin Cross950f1ef2017-04-05 15:30:42 -0700594# Keep a copy of the jar just before proguard processing.
595$(eval $(call copy-one-file,$(full_classes_pre_proguard_jar),$(intermediates.COMMON)/classes-pre-proguard.jar))
Shinichiro Hamaji89b255a2015-11-09 16:47:42 +0900596
Colin Cross0e537342017-03-29 12:17:36 -0700597# Run proguard if necessary
Ying Wang7311a342013-08-21 18:32:49 -0700598ifdef LOCAL_PROGUARD_ENABLED
Colin Crosse616f342017-12-28 09:43:41 -0800599ifneq ($(filter-out full custom obfuscation optimization,$(LOCAL_PROGUARD_ENABLED)),)
Ying Wang7311a342013-08-21 18:32:49 -0700600 $(warning while processing: $(LOCAL_MODULE))
601 $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED))
602endif
Joe Onorato2daa2b32009-08-30 13:39:24 -0700603proguard_dictionary := $(intermediates.COMMON)/proguard_dictionary
Ying Wang4f5d0e62015-05-04 19:21:48 -0700604
Colin Crossb5f25a22017-10-20 19:16:41 -0700605# When an app contains references to APIs that are not in the SDK specified by
606# its LOCAL_SDK_VERSION for example added by support library or by runtime
607# classes added by desugar, we artifically raise the "SDK version" "linked" by
608# ProGuard, to
Ying Wang4f5d0e62015-05-04 19:21:48 -0700609# - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version.
610# - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version.
Colin Crossb5f25a22017-10-20 19:16:41 -0700611# See b/20667396
612my_proguard_sdk_raise :=
Ying Wang4f5d0e62015-05-04 19:21:48 -0700613ifdef LOCAL_SDK_VERSION
Ying Wang4f5d0e62015-05-04 19:21:48 -0700614ifdef TARGET_BUILD_APPS
Jiyong Park5ebca302018-01-31 00:14:55 +0900615ifeq (,$(filter current system_current test_current core_current, $(LOCAL_SDK_VERSION)))
Colin Crossb5f25a22017-10-20 19:16:41 -0700616 my_proguard_sdk_raise := $(call java-lib-header-files, sdk_vcurrent)
Ying Wang742f5832015-06-26 12:33:06 -0700617endif
Ying Wang4f5d0e62015-05-04 19:21:48 -0700618else
619 # For platform build, we can't just raise to the "current" SDK,
620 # that would break apps that use APIs removed from the current SDK.
Colin Crossb5f25a22017-10-20 19:16:41 -0700621 my_proguard_sdk_raise := $(call java-lib-header-files,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES) $(TARGET_DEFAULT_JAVA_LIBRARIES))
Ying Wang4f5d0e62015-05-04 19:21:48 -0700622endif
623endif
Ying Wang4f5d0e62015-05-04 19:21:48 -0700624
Colin Crossb5f25a22017-10-20 19:16:41 -0700625legacy_proguard_flags := $(addprefix -libraryjars ,$(my_proguard_sdk_raise) \
626 $(filter-out $(my_proguard_sdk_raise), \
Colin Crossb541aae2017-09-23 19:52:43 -0700627 $(full_java_bootclasspath_libs) \
628 $(full_shared_java_header_libs)))
Nan Zhangb3ec5342017-08-31 21:43:04 +0000629
Colin Crossb5f25a22017-10-20 19:16:41 -0700630legacy_proguard_lib_deps := $(my_proguard_sdk_raise) \
631 $(filter-out $(my_proguard_sdk_raise),$(full_shared_java_header_libs))
Yohann Rousselb7de0fb2015-11-03 18:33:21 +0100632
633legacy_proguard_flags += -printmapping $(proguard_dictionary)
Yohann Rousselb7de0fb2015-11-03 18:33:21 +0100634
635common_proguard_flags := -forceprocessing
Ying Wang7311a342013-08-21 18:32:49 -0700636
Colin Crosse616f342017-12-28 09:43:41 -0800637common_proguard_flag_files := $(BUILD_SYSTEM)/proguard.flags
Ying Wang7311a342013-08-21 18:32:49 -0700638ifneq ($(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS)),)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200639common_proguard_flags += -dontshrink # don't shrink tests by default
Ying Wang3b2bdf12010-02-01 09:51:23 -0800640endif # test package
Dan Willemsen1d646232017-11-17 13:11:26 -0800641ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
642 ifdef LOCAL_USE_AAPT2
643 common_proguard_flag_files += $(foreach l,$(LOCAL_STATIC_ANDROID_LIBRARIES),\
644 $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/export_proguard_flags)
645 endif
646endif
Shinichiro Hamaji4eaeef82016-04-07 18:56:42 +0900647ifneq ($(common_proguard_flag_files),)
648common_proguard_flags += $(addprefix -include , $(common_proguard_flag_files))
649# This is included from $(BUILD_SYSTEM)/proguard.flags
650common_proguard_flag_files += $(BUILD_SYSTEM)/proguard_basic_keeps.flags
651endif
652
Ying Wang7311a342013-08-21 18:32:49 -0700653ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
654# By default no obfuscation
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200655common_proguard_flags += -dontobfuscate
Ying Wang7311a342013-08-21 18:32:49 -0700656endif # No obfuscation
657ifeq ($(filter optimization,$(LOCAL_PROGUARD_ENABLED)),)
658# By default no optimization
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200659common_proguard_flags += -dontoptimize
Ying Wang7311a342013-08-21 18:32:49 -0700660endif # No optimization
Ying Wang3b2bdf12010-02-01 09:51:23 -0800661
Ying Wang7311a342013-08-21 18:32:49 -0700662ifdef LOCAL_INSTRUMENTATION_FOR
663ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
664# If no obfuscation, link in the instrmented package's classes.jar as a library.
665# link_instr_classes_jar is defined in base_rule.mk
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200666legacy_proguard_flags += -libraryjars $(link_instr_classes_jar)
Nan Zhangb3ec5342017-08-31 21:43:04 +0000667legacy_proguard_lib_deps += $(link_instr_classes_jar)
Ying Wang7311a342013-08-21 18:32:49 -0700668else # obfuscation
669# If obfuscation is enabled, the main app must be obfuscated too.
670# We need to run obfuscation using the main app's dictionary,
671# and treat the main app's class.jar as injars instead of libraryjars.
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200672legacy_proguard_flags := -injars $(link_instr_classes_jar) \
Ying Wang7311a342013-08-21 18:32:49 -0700673 -outjars $(intermediates.COMMON)/proguard.$(LOCAL_INSTRUMENTATION_FOR).jar \
674 -include $(link_instr_intermediates_dir.COMMON)/proguard_options \
675 -applymapping $(link_instr_intermediates_dir.COMMON)/proguard_dictionary \
676 -verbose \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200677 $(legacy_proguard_flags)
Ying Wang7311a342013-08-21 18:32:49 -0700678
679# Sometimes (test + main app) uses different keep rules from the main app -
680# apply the main app's dictionary anyway.
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200681legacy_proguard_flags += -ignorewarnings
Ying Wang7311a342013-08-21 18:32:49 -0700682
683# Make sure we run Proguard on the main app first
684$(full_classes_proguard_jar) : $(link_instr_intermediates_dir.COMMON)/proguard.classes.jar
685
686endif # no obfuscation
687endif # LOCAL_INSTRUMENTATION_FOR
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
David Brazdilb8fa6dd2018-01-29 14:43:14 +0000768ifneq ($(filter $(LOCAL_MODULE),$(PRODUCT_BOOT_JARS)),) # is_boot_jar
769 $(eval $(call hiddenapi-copy-dex-files,$(built_dex_intermediate),$(built_dex_hiddenapi)))
770 built_dex_copy_from := $(built_dex_hiddenapi)
771else # !is_boot_jar
772 built_dex_copy_from := $(built_dex_intermediate)
773endif # is_boot_jar
774
775$(built_dex): $(built_dex_copy_from)
Guang Zhu155afe32010-03-10 15:48:03 -0800776 @echo Copying: $@
Yohann Roussel8ffe9c32013-08-20 17:05:27 +0200777 $(hide) mkdir -p $(dir $@)
778 $(hide) rm -f $(dir $@)/classes*.dex
Colin Cross0e537342017-03-29 12:17:36 -0700779 $(hide) cp -fp $(dir $<)/classes*.dex $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800780
Colin Cross9eff8302017-04-27 15:05:44 -0700781java-dex: $(built_dex)
782
Colin Cross96476c12017-04-06 09:56:19 -0700783endif # !LOCAL_IS_STATIC_JAVA_LIBRARY
784
The Android Open Source Project88b60792009-03-03 19:28:42 -0800785findbugs_xml := $(intermediates.COMMON)/findbugs.xml
Ying Wang702e01e2015-10-21 10:30:51 -0700786$(findbugs_xml): PRIVATE_AUXCLASSPATH := $(addprefix -auxclasspath ,$(strip \
787 $(call normalize-path-list,$(filter %.jar,$(full_java_libs)))))
788$(findbugs_xml): PRIVATE_FINDBUGS_FLAGS := $(LOCAL_FINDBUGS_FLAGS)
Colin Cross950f1ef2017-04-05 15:30:42 -0700789$(findbugs_xml) : $(full_classes_pre_proguard_jar) $(filter %.xml, $(LOCAL_FINDBUGS_FLAGS))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800790 @echo Findbugs: $@
791 $(hide) $(FINDBUGS) -textui -effort:min -xml:withMessages \
Ying Wang702e01e2015-10-21 10:30:51 -0700792 $(PRIVATE_AUXCLASSPATH) $(PRIVATE_FINDBUGS_FLAGS) \
Yohann Rousseld2a76c12015-02-05 16:10:58 +0100793 $< \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800794 > $@
795
796ALL_FINDBUGS_FILES += $(findbugs_xml)
797
798findbugs_html := $(PRODUCT_OUT)/findbugs/$(LOCAL_MODULE).html
799$(findbugs_html) : PRIVATE_XML_FILE := $(findbugs_xml)
800$(LOCAL_MODULE)-findbugs : $(findbugs_html)
801$(findbugs_html) : $(findbugs_xml)
802 @mkdir -p $(dir $@)
Andrew Stadlercef9ed92009-05-13 00:44:59 -0700803 @echo ConvertXmlToText: $@
Yuncheol Heo623d7062014-05-20 17:04:16 +0900804 $(hide) $(FINDBUGS_DIR)/convertXmlToText -html:fancy.xsl $(PRIVATE_XML_FILE) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800805 > $@
806
807$(LOCAL_MODULE)-findbugs : $(findbugs_html)
808
Ying Wang990cf5e2013-08-28 13:04:46 -0700809endif # full_classes_jar is defined
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200810
Jiyong Park5ebca302018-01-31 00:14:55 +0900811ifneq (,$(filter-out current system_current test_current core_current, $(LOCAL_SDK_VERSION)))
Sundong Ahn5a44d1f2017-10-16 19:20:34 +0900812 my_default_app_target_sdk := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
813 my_sdk_version := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
Colin Cross536ef4e2017-02-21 16:14:55 -0800814else
Colin Cross9deb3312017-09-28 16:17:36 -0700815 my_default_app_target_sdk := $(DEFAULT_APP_TARGET_SDK)
816 my_sdk_version := $(PLATFORM_SDK_VERSION)
Colin Cross536ef4e2017-02-21 16:14:55 -0800817endif
818
Colin Cross9deb3312017-09-28 16:17:36 -0700819ifdef LOCAL_MIN_SDK_VERSION
820 my_min_sdk_version := $(LOCAL_MIN_SDK_VERSION)
821else
822 my_min_sdk_version := $(call codename-or-sdk-to-sdk,$(my_default_app_target_sdk))
823endif
824
825$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(my_default_app_target_sdk)
826$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SDK_VERSION := $(my_sdk_version)
827$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MIN_SDK_VERSION := $(my_min_sdk_version)