blob: e2639068e6f1c77dc90d315a440b77567b9268d5 [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
Colin Cross5c66c282018-03-14 09:56:04 -070018ifndef LOCAL_USE_R8
19LOCAL_USE_R8 := $(USE_R8)
20endif
21
The Android Open Source Project88b60792009-03-03 19:28:42 -080022LOCAL_NO_STANDARD_LIBRARIES:=$(strip $(LOCAL_NO_STANDARD_LIBRARIES))
23LOCAL_SDK_VERSION:=$(strip $(LOCAL_SDK_VERSION))
24
Ying Wanga5fc87a2010-11-02 18:43:16 -070025proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
26ifneq ($(proto_sources),)
27ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro)
Jeff Davidsonb8ddd552014-09-15 17:51:11 -070028 LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-micro
Ying Wanga5fc87a2010-11-02 18:43:16 -070029else
Ulas Kirazcibde274e2013-03-28 14:02:14 -070030 ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nano)
Jeff Davidsonb8ddd552014-09-15 17:51:11 -070031 LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-nano
Ulas Kirazcibde274e2013-03-28 14:02:14 -070032 else
Joe Onoratoc05a8ee2016-10-05 18:01:10 -070033 ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),stream)
34 # No library for stream protobufs
35 else
36 LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-lite
37 endif
Ulas Kirazcibde274e2013-03-28 14:02:14 -070038 endif
Ying Wanga5fc87a2010-11-02 18:43:16 -070039endif
40endif
41
Ying Wange295c3d2016-02-24 14:11:55 -080042# LOCAL_STATIC_JAVA_AAR_LIBRARIES and LOCAL_STATIC_ANDROID_LIBRARIES are also LOCAL_STATIC_JAVA_LIBRARIES.
43LOCAL_STATIC_JAVA_LIBRARIES := $(strip $(LOCAL_STATIC_JAVA_LIBRARIES) \
44 $(LOCAL_STATIC_JAVA_AAR_LIBRARIES) \
45 $(LOCAL_STATIC_ANDROID_LIBRARIES))
46# LOCAL_SHARED_ANDROID_LIBRARIES are also LOCAL_JAVA_LIBRARIES.
47LOCAL_JAVA_LIBRARIES := $(sort $(LOCAL_JAVA_LIBRARIES) $(LOCAL_SHARED_ANDROID_LIBRARIES))
The Android Open Source Project88b60792009-03-03 19:28:42 -080048
49LOCAL_BUILT_MODULE_STEM := $(strip $(LOCAL_BUILT_MODULE_STEM))
50ifeq ($(LOCAL_BUILT_MODULE_STEM),)
51$(error $(LOCAL_PATH): Target java template must define LOCAL_BUILT_MODULE_STEM)
52endif
53ifneq ($(filter classes-compiled.jar classes.jar,$(LOCAL_BUILT_MODULE_STEM)),)
54$(error LOCAL_BUILT_MODULE_STEM may not be "$(LOCAL_BUILT_MODULE_STEM)")
55endif
56
Joe Onoratoe334d252009-07-17 15:33:40 -040057
58##############################################################################
59# Define the intermediate targets before including base_rules so they get
60# the correct environment.
61##############################################################################
62
63intermediates := $(call local-intermediates-dir)
64intermediates.COMMON := $(call local-intermediates-dir,COMMON)
65
Ying Wang957fea52010-09-23 11:48:38 -070066ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
67LOCAL_PROGUARD_ENABLED :=
68endif
69
Nan Zhangb3ec5342017-08-31 21:43:04 +000070full_classes_turbine_jar := $(intermediates.COMMON)/classes-turbine.jar
71full_classes_header_jarjar := $(intermediates.COMMON)/classes-header-jarjar.jar
72full_classes_header_jar := $(intermediates.COMMON)/classes-header.jar
Colin Crossa6e87822017-12-20 17:33:01 -080073full_classes_compiled_jar := $(intermediates.COMMON)/classes-full-debug.jar
Colin Crossf8a49c52017-05-22 16:21:49 -070074full_classes_processed_jar := $(intermediates.COMMON)/classes-processed.jar
Colin Cross950f1ef2017-04-05 15:30:42 -070075full_classes_desugar_jar := $(intermediates.COMMON)/classes-desugar.jar
Colin Crossa6e87822017-12-20 17:33:01 -080076full_classes_jarjar_jar := $(intermediates.COMMON)/classes-jarjar.jar
Colin Cross950f1ef2017-04-05 15:30:42 -070077full_classes_proguard_jar := $(intermediates.COMMON)/classes-proguard.jar
Nan Zhang9bd54052017-09-13 13:13:53 -070078full_classes_combined_jar := $(intermediates.COMMON)/classes-combined.jar
Colin Crossa6e87822017-12-20 17:33:01 -080079built_dex_intermediate := $(intermediates.COMMON)/dex/classes.dex
David Brazdilb8fa6dd2018-01-29 14:43:14 +000080built_dex_hiddenapi := $(intermediates.COMMON)/dex-hiddenapi/classes.dex
Ying Wang957fea52010-09-23 11:48:38 -070081full_classes_stubs_jar := $(intermediates.COMMON)/stubs.jar
Colin Crossdfc45ec2017-05-26 15:22:02 -070082java_source_list_file := $(intermediates.COMMON)/java-source-list
83
Ying Wang957fea52010-09-23 11:48:38 -070084
Ying Wang37b82aa2013-08-28 17:28:36 -070085ifeq ($(LOCAL_MODULE_CLASS)$(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),APPS)
86# 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 -070087full_classes_jar :=
88built_dex :=
89else
Ying Wang957fea52010-09-23 11:48:38 -070090full_classes_jar := $(intermediates.COMMON)/classes.jar
Ying Wang7b7929a2013-09-12 17:35:21 -070091built_dex := $(intermediates.COMMON)/classes.dex
Ying Wang990cf5e2013-08-28 13:04:46 -070092endif
Joe Onoratoe334d252009-07-17 15:33:40 -040093
94LOCAL_INTERMEDIATE_TARGETS += \
Nan Zhangb3ec5342017-08-31 21:43:04 +000095 $(full_classes_turbine_jar) \
Joe Onoratoe334d252009-07-17 15:33:40 -040096 $(full_classes_compiled_jar) \
Colin Crosseac5ce42016-12-21 17:11:03 -080097 $(full_classes_desugar_jar) \
Ying Wang957fea52010-09-23 11:48:38 -070098 $(full_classes_jarjar_jar) \
Ying Wang957fea52010-09-23 11:48:38 -070099 $(full_classes_jar) \
Nan Zhang9bd54052017-09-13 13:13:53 -0700100 $(full_classes_combined_jar) \
Ying Wanga9c381e2010-10-02 18:35:51 -0700101 $(full_classes_proguard_jar) \
Ying Wang957fea52010-09-23 11:48:38 -0700102 $(built_dex_intermediate) \
Guang Zhu155afe32010-03-10 15:48:03 -0800103 $(built_dex) \
Colin Crossdfc45ec2017-05-26 15:22:02 -0700104 $(full_classes_stubs_jar) \
105 $(java_source_list_file)
Ying Wang957fea52010-09-23 11:48:38 -0700106
Joe Onorato77dc0a52010-05-17 18:16:11 -0700107LOCAL_INTERMEDIATE_SOURCE_DIR := $(intermediates.COMMON)/src
Joe Onoratoe334d252009-07-17 15:33:40 -0400108
Ying Wang0bd59a02010-07-15 17:17:52 -0700109###############################################################
110## .rs files: RenderScript sources to .java files and .bc files
111###############################################################
Colin Cross93d65502018-03-12 18:17:25 -0700112renderscript_sources := $(filter %.rs,$(LOCAL_SRC_FILES))
Ying Wang0bd59a02010-07-15 17:17:52 -0700113# Because names of the java files from RenderScript are unknown until the
114# .rs file(s) are compiled, we have to depend on a timestamp file.
115RenderScript_file_stamp :=
Ying Wangdd71c852015-12-04 13:59:18 -0800116rs_generated_res_dir :=
Stephen Hines3b0fa102013-02-06 16:19:30 -0800117rs_compatibility_jni_libs :=
Ying Wang0bd59a02010-07-15 17:17:52 -0700118ifneq ($(renderscript_sources),)
119renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
120RenderScript_file_stamp := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/RenderScript.stamp
Dan Willemsencf324af2016-12-21 17:37:00 -0800121renderscript_intermediate.COMMON := $(intermediates.COMMON)/renderscript
Ying Wang0bd59a02010-07-15 17:17:52 -0700122
Miao Wang302e9442015-07-28 17:43:51 -0700123# Defaulting to an empty string uses the latest available platform SDK.
Stephen Hinesc963eae2011-08-10 13:53:05 -0700124renderscript_target_api :=
Stephen Hinesa941d132011-08-29 18:53:53 -0700125
126ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API))
Miao Wang302e9442015-07-28 17:43:51 -0700127 renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API)
Stephen Hinesa941d132011-08-29 18:53:53 -0700128else
Miao Wang302e9442015-07-28 17:43:51 -0700129 ifneq (,$(LOCAL_SDK_VERSION))
130 # Set target-api for LOCAL_SDK_VERSIONs other than current.
Jiyong Park5ebca302018-01-31 00:14:55 +0900131 ifneq (,$(filter-out current system_current test_current core_current, $(LOCAL_SDK_VERSION)))
Sundong Ahn5a44d1f2017-10-16 19:20:34 +0900132 renderscript_target_api := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
Miao Wang302e9442015-07-28 17:43:51 -0700133 endif
134 endif # LOCAL_SDK_VERSION is set
Stephen Hinesa941d132011-08-29 18:53:53 -0700135endif # LOCAL_RENDERSCRIPT_TARGET_API is set
Stephen Hinesc963eae2011-08-10 13:53:05 -0700136
Miao Wanga11f6c22015-07-29 11:46:23 -0700137# For 64-bit, we always have to upgrade to at least 21 for compat build.
138ifneq ($(LOCAL_RENDERSCRIPT_COMPATIBILITY),)
139 ifeq ($(TARGET_IS_64_BIT),true)
140 ifneq ($(filter $(RSCOMPAT_32BIT_ONLY_API_LEVELS),$(renderscript_target_api)),)
141 renderscript_target_api := 21
142 endif
Miao Wang302e9442015-07-28 17:43:51 -0700143 endif
144endif
145
Stephen Hinesc963eae2011-08-10 13:53:05 -0700146ifeq ($(LOCAL_RENDERSCRIPT_CC),)
147LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC)
148endif
149
Stephen Hines914f7a22011-12-06 18:43:24 -0800150# Turn on all warnings and warnings as errors for RS compiles.
151# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
152renderscript_flags := -Wall -Werror
153renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)
154
Ying Wang51280272010-09-01 13:28:52 -0700155# prepend the RenderScript system include path
Jiyong Park5ebca302018-01-31 00:14:55 +0900156ifneq ($(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 -0700157# if a numeric LOCAL_SDK_VERSION, or current LOCAL_SDK_VERSION with TARGET_BUILD_APPS
Ying Wangfcf00d52011-03-29 11:47:12 -0700158LOCAL_RENDERSCRIPT_INCLUDES := \
Stephen Hines5a4eb5f2012-03-06 21:48:36 -0800159 $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/clang-include \
160 $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/include \
Ying Wangfcf00d52011-03-29 11:47:12 -0700161 $(LOCAL_RENDERSCRIPT_INCLUDES)
162else
Ying Wang85aa5de2011-01-19 11:49:21 -0800163LOCAL_RENDERSCRIPT_INCLUDES := \
Stephen Hinesc963eae2011-08-10 13:53:05 -0700164 $(TOPDIR)external/clang/lib/Headers \
Jean-Luc Brouilleteba44932017-01-08 17:40:21 -0800165 $(TOPDIR)frameworks/rs/script_api/include \
Stephen Hinesc963eae2011-08-10 13:53:05 -0700166 $(LOCAL_RENDERSCRIPT_INCLUDES)
Ying Wang7d83ef82011-05-25 17:16:22 -0700167endif
168
Stephen Hinesd4136c02011-08-23 22:01:49 -0700169ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),)
170LOCAL_RENDERSCRIPT_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE)
171endif
172
Colin Cross93d65502018-03-12 18:17:25 -0700173bc_files := $(patsubst %.rs,%.bc, $(notdir $(renderscript_sources)))
Ying Wangb9319562015-04-03 16:15:28 -0700174bc_dep_files := $(addprefix $(renderscript_intermediate.COMMON)/,$(patsubst %.bc,%.d,$(bc_files)))
175
Ying Wang51280272010-09-01 13:28:52 -0700176$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES)
Ying Wang7d83ef82011-05-25 17:16:22 -0700177$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC)
Stephen Hines914f7a22011-12-06 18:43:24 -0800178$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags)
Ying Wang0bd59a02010-07-15 17:17:52 -0700179$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath)
180# By putting the generated java files into $(LOCAL_INTERMEDIATE_SOURCE_DIR), they will be
181# automatically found by the java compiling function transform-java-to-classes.jar.
Ying Wang370fa672013-02-25 16:06:42 -0800182$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate.COMMON)
Stephen Hinesc963eae2011-08-10 13:53:05 -0700183$(RenderScript_file_stamp): PRIVATE_RS_TARGET_API := $(renderscript_target_api)
Ying Wangb9319562015-04-03 16:15:28 -0700184$(RenderScript_file_stamp): PRIVATE_DEP_FILES := $(bc_dep_files)
Ying Wang7d83ef82011-05-25 17:16:22 -0700185$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC)
Ying Wang0bd59a02010-07-15 17:17:52 -0700186 $(transform-renderscripts-to-java-and-bc)
187
Ying Wangb9319562015-04-03 16:15:28 -0700188# include the dependency files (.d/.P) generated by llvm-rs-cc.
Shinichiro Hamaji52a1d6c2016-02-01 17:59:01 +0900189$(call include-depfile,$(RenderScript_file_stamp).P,$(RenderScript_file_stamp))
Ying Wangcddece62015-04-03 09:53:41 -0700190
Stephen Hinese719f282012-11-28 16:52:41 -0800191ifneq ($(LOCAL_RENDERSCRIPT_COMPATIBILITY),)
Miao Wange4359cf2015-01-07 18:18:41 -0800192
193
194ifeq ($(filter $(RSCOMPAT_32BIT_ONLY_API_LEVELS),$(renderscript_target_api)),)
195ifeq ($(TARGET_IS_64_BIT),true)
196renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/bc64/
197else
198renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/bc32/
199endif
200else
201renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/
202endif
203
Stephen Hinese719f282012-11-28 16:52:41 -0800204rs_generated_bc := $(addprefix \
Miao Wange4359cf2015-01-07 18:18:41 -0800205 $(renderscript_intermediate.bc_folder), $(bc_files))
Stephen Hinese719f282012-11-28 16:52:41 -0800206
Ying Wang370fa672013-02-25 16:06:42 -0800207renderscript_intermediate := $(intermediates)/renderscript
Tim Murray8e0567a2013-05-13 15:46:37 -0700208
209# We don't need the .so files in bundled branches
210# Prevent these from showing up on the device
Miao Wangc919b0b2015-02-12 16:22:59 -0800211# One exception is librsjni.so, which is needed for
212# both native path and compat path.
213rs_jni_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/librsjni.so
214LOCAL_JNI_SHARED_LIBRARIES += librsjni
215
Stephen Hinesc54e81c2013-09-30 15:57:36 -0700216ifneq (,$(TARGET_BUILD_APPS)$(FORCE_BUILD_RS_COMPAT))
Tim Murray8e0567a2013-05-13 15:46:37 -0700217
Stephen Hinese719f282012-11-28 16:52:41 -0800218rs_compatibility_jni_libs := $(addprefix \
Stephen Hinesec02b4f2013-02-15 23:02:20 -0800219 $(renderscript_intermediate)/librs., \
Stephen Hinese719f282012-11-28 16:52:41 -0800220 $(patsubst %.bc,%.so, $(bc_files)))
221
222$(rs_generated_bc) : $(RenderScript_file_stamp)
223
Stephen Hinesf6925132012-12-17 14:23:14 -0800224rs_support_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/libRSSupport.so
Miao Wangc919b0b2015-02-12 16:22:59 -0800225LOCAL_JNI_SHARED_LIBRARIES += libRSSupport
Stephen Hinesf6925132012-12-17 14:23:14 -0800226
Miao Wangec27a892014-11-20 11:05:18 -0800227rs_support_io_lib :=
228# check if the target api level support USAGE_IO
229ifeq ($(filter $(RSCOMPAT_NO_USAGEIO_API_LEVELS),$(renderscript_target_api)),)
230rs_support_io_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/libRSSupportIO.so
231LOCAL_JNI_SHARED_LIBRARIES += libRSSupportIO
232endif
Tim Murray8e0567a2013-05-13 15:46:37 -0700233
Miao Wang28e78f42017-08-16 16:05:26 -0700234my_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
235ifneq (,$(filter arm64 mips64 x86_64,$(my_arch)))
236 my_min_sdk_version := 21
237else
238 my_min_sdk_version := $(MIN_SUPPORTED_SDK_VERSION)
239endif
Tim Murray8e0567a2013-05-13 15:46:37 -0700240
Tim Murray1a6f09a2013-03-05 11:07:15 -0800241$(rs_compatibility_jni_libs): $(RenderScript_file_stamp) $(RS_PREBUILT_CLCORE) \
Miao Wangec27a892014-11-20 11:05:18 -0800242 $(rs_support_lib) $(rs_support_io_lib) $(rs_jni_lib) $(rs_compiler_rt)
Stephen Hines8db4cce2013-03-27 16:51:38 -0700243$(rs_compatibility_jni_libs): $(BCC_COMPAT)
Ying Wang57d90602015-07-20 18:40:18 -0700244$(rs_compatibility_jni_libs): PRIVATE_CXX := $(CXX_WRAPPER) $(TARGET_CXX)
Miao Wang28e78f42017-08-16 16:05:26 -0700245$(rs_compatibility_jni_libs): PRIVATE_SDK_VERSION := $(my_min_sdk_version)
Stephen Hinesec02b4f2013-02-15 23:02:20 -0800246$(rs_compatibility_jni_libs): $(renderscript_intermediate)/librs.%.so: \
Miao Wang28e78f42017-08-16 16:05:26 -0700247 $(renderscript_intermediate.bc_folder)%.bc \
248 $(SOONG_OUT_DIR)/ndk.timestamp
Stephen Hinese719f282012-11-28 16:52:41 -0800249 $(transform-bc-to-so)
250
251endif
252
Tim Murray8e0567a2013-05-13 15:46:37 -0700253endif
254
Ying Wang0bd59a02010-07-15 17:17:52 -0700255LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
256# Make sure the generated resource will be added to the apk.
Ying Wangdd71c852015-12-04 13:59:18 -0800257rs_generated_res_dir := $(renderscript_intermediate.COMMON)/res
258LOCAL_RESOURCE_DIR := $(rs_generated_res_dir) $(LOCAL_RESOURCE_DIR)
Ying Wang0bd59a02010-07-15 17:17:52 -0700259endif
260
Ying Wang956dccc2015-08-28 11:47:03 -0700261
262###########################################################
263## AIDL: Compile .aidl files to .java
264###########################################################
265aidl_sources := $(filter %.aidl,$(LOCAL_SRC_FILES))
Christopher Wileyd9205ba2016-06-23 16:44:47 -0700266aidl_java_sources :=
Ying Wang956dccc2015-08-28 11:47:03 -0700267
268ifneq ($(strip $(aidl_sources)),)
Ying Wang956dccc2015-08-28 11:47:03 -0700269
270aidl_preprocess_import :=
271ifdef LOCAL_SDK_VERSION
Jiyong Park5ebca302018-01-31 00:14:55 +0900272ifneq ($(filter current system_current test_current core_current, $(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS)),)
Ying Wang956dccc2015-08-28 11:47:03 -0700273 # LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS
274 aidl_preprocess_import := $(TARGET_OUT_COMMON_INTERMEDIATES)/framework.aidl
275else
276 aidl_preprocess_import := $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_VERSION)/framework.aidl
277endif # not current or system_current
278else
279# build against the platform.
280LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)
281endif # LOCAL_SDK_VERSION
Ying Wang956dccc2015-08-28 11:47:03 -0700282
Christopher Wileyd9205ba2016-06-23 16:44:47 -0700283$(foreach s,$(aidl_sources),\
Dan Willemsen4d995272017-09-29 17:37:31 -0700284 $(eval $(call define-aidl-java-rule,$(s),$(intermediates.COMMON)/aidl,aidl_java_sources)))
Shinichiro Hamaji2a0d1fe2016-01-28 16:10:00 +0900285$(foreach java,$(aidl_java_sources), \
286 $(call include-depfile,$(java:%.java=%.P),$(java)))
Ying Wang956dccc2015-08-28 11:47:03 -0700287
Christopher Wileyd9205ba2016-06-23 16:44:47 -0700288$(aidl_java_sources) : $(LOCAL_ADDITIONAL_DEPENDENCIES) $(aidl_preprocess_import)
289
290$(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 -0700291$(aidl_java_sources): PRIVATE_MODULE := $(LOCAL_MODULE)
Christopher Wileyd9205ba2016-06-23 16:44:47 -0700292
Ying Wang956dccc2015-08-28 11:47:03 -0700293endif
294
Ying Wang956dccc2015-08-28 11:47:03 -0700295##########################################
296
Ying Wang1d977e32013-01-30 11:22:06 -0800297# All of the rules after full_classes_compiled_jar are very unlikely
298# to fail except for bugs in their respective tools. If you would
299# like to run these rules, add the "all" modifier goal to the make
300# command line.
Ying Wang447d6962015-09-01 19:12:05 -0700301ifndef LOCAL_CHECKED_MODULE
Jean-Philippe Lesot0fbc9ff2015-01-20 14:18:48 +0000302ifdef full_classes_jar
Colin Crossb17f2852017-04-27 13:34:02 -0700303LOCAL_CHECKED_MODULE := $(full_classes_compiled_jar)
Ying Wang990cf5e2013-08-28 13:04:46 -0700304endif
Yohann Rousselee572682015-08-18 19:18:18 +0200305endif
Ying Wang1d977e32013-01-30 11:22:06 -0800306
The Android Open Source Project88b60792009-03-03 19:28:42 -0800307#######################################
308include $(BUILD_SYSTEM)/base_rules.mk
309#######################################
310
Yasuhiro Matsudaff82e822015-09-04 16:23:49 +0900311###########################################################
312## logtags: emit java source
313###########################################################
314ifneq ($(strip $(logtags_sources)),)
315
Dan Willemsen4d995272017-09-29 17:37:31 -0700316logtags_java_sources := $(patsubst %.logtags,%.java,$(addprefix $(intermediates.COMMON)/logtags/, $(logtags_sources)))
Yasuhiro Matsudaff82e822015-09-04 16:23:49 +0900317logtags_sources := $(addprefix $(LOCAL_PATH)/, $(logtags_sources))
318
Shinichiro Hamajid3ce14c2016-03-29 03:29:21 +0900319$(logtags_java_sources): PRIVATE_MERGED_TAG := $(TARGET_OUT_COMMON_INTERMEDIATES)/all-event-log-tags.txt
Colin Crossfdea8932017-12-06 14:38:40 -0800320$(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 +0900321 $(transform-logtags-to-java)
322
323else
324logtags_java_sources :=
325endif
326
Ying Wang956dccc2015-08-28 11:47:03 -0700327##########################################
328java_sources := $(addprefix $(LOCAL_PATH)/, $(filter %.java,$(LOCAL_SRC_FILES))) $(aidl_java_sources) $(logtags_java_sources) \
329 $(filter %.java,$(LOCAL_GENERATED_SOURCES))
Nan Zhangad818dc2017-10-04 09:26:06 -0700330java_intermediate_sources := $(addprefix $(TARGET_OUT_COMMON_INTERMEDIATES)/, $(filter %.java,$(LOCAL_INTERMEDIATE_SOURCES)))
331all_java_sources := $(java_sources) $(java_intermediate_sources)
332
Ying Wang956dccc2015-08-28 11:47:03 -0700333include $(BUILD_SYSTEM)/java_common.mk
334
Anton Hansson7ff32d22018-02-21 15:29:44 +0000335include $(BUILD_SYSTEM)/sdk_check.mk
336
Dan Willemsencf324af2016-12-21 17:37:00 -0800337$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HAS_RS_SOURCES := $(if $(renderscript_sources),true)
338$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RS_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/renderscript
339
Narayan Kamathbbcdc072017-08-22 15:47:08 +0100340# Set the profile source so that the odex / profile code included from java.mk
341# can find it.
342#
343# TODO: b/64896089, this is broken when called from package_internal.mk, since the file
344# we preopt from is a temporary file. This will be addressed in a follow up, possibly
345# by disabling stripping for profile guided preopt (which may be desirable for other
346# reasons anyway).
347#
348# Note that we set this only when called from package_internal.mk and not in other cases.
349ifneq (,$(called_from_package_internal)
350dex_preopt_profile_src_file := $(LOCAL_BUILT_MODULE)
351endif
352
Brian Carlstromced4bff2013-11-14 23:44:56 -0800353#######################################
354# defines built_odex along with rule to install odex
355include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
356#######################################
357
Ying Wang990cf5e2013-08-28 13:04:46 -0700358# Make sure there's something to build.
359ifdef full_classes_jar
360ifndef need_compile_java
Jeff Gaston960acf12018-02-26 21:00:25 -0500361$(call pretty-error,Target java module does not define any source or resource files)
Ying Wang990cf5e2013-08-28 13:04:46 -0700362endif
363endif
364
The Android Open Source Project88b60792009-03-03 19:28:42 -0800365# Since we're using intermediates.COMMON, make sure that it gets cleaned
366# properly.
367$(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON)
368
Ying Wang990cf5e2013-08-28 13:04:46 -0700369ifdef full_classes_jar
The Android Open Source Project88b60792009-03-03 19:28:42 -0800370
Joe Onorato64d85d02009-04-09 19:31:12 -0700371# Droiddoc isn't currently able to generate stubs for modules, so we're just
372# allowing it to use the classes.jar as the "stubs" that would be use to link
373# against, for the cases where someone needs the jar to link against.
Colin Cross0e537342017-03-29 12:17:36 -0700374$(eval $(call copy-one-file,$(full_classes_jar),$(full_classes_stubs_jar)))
Joe Onorato64d85d02009-04-09 19:31:12 -0700375ALL_MODULES.$(LOCAL_MODULE).STUBS := $(full_classes_stubs_jar)
376
Joe Onorato0eccce92011-10-30 21:37:35 -0700377# The layers file allows you to enforce a layering between java packages.
Colin Crossfdea8932017-12-06 14:38:40 -0800378# Run build/make/tools/java-layers.py for more details.
Joe Onorato0eccce92011-10-30 21:37:35 -0700379layers_file := $(addprefix $(LOCAL_PATH)/, $(LOCAL_JAVA_LAYERS_FILE))
380$(full_classes_compiled_jar): PRIVATE_JAVA_LAYERS_FILE := $(layers_file)
Ying Wang057eba02012-10-18 10:54:49 -0700381$(full_classes_compiled_jar): PRIVATE_WARNINGS_ENABLE := $(LOCAL_WARNINGS_ENABLE)
Joe Onorato0eccce92011-10-30 21:37:35 -0700382
The Android Open Source Project88b60792009-03-03 19:28:42 -0800383# Compile the java files to a .jar file.
384# This intentionally depends on java_sources, not all_java_sources.
385# Deps for generated source files must be handled separately,
386# via deps on the target that generates the sources.
Paul Duffin3ca92982016-09-20 15:12:30 +0100387
388# If error prone is enabled then add LOCAL_ERROR_PRONE_FLAGS to LOCAL_JAVACFLAGS
389ifeq ($(RUN_ERROR_PRONE),true)
390LOCAL_JAVACFLAGS += $(LOCAL_ERROR_PRONE_FLAGS)
391endif
392
Przemyslaw Szczepaniak2e81b3c2017-06-30 14:51:12 +0100393# For user / userdebug builds, strip the local variable table and the local variable
394# type table. This has no bearing on stack traces, but will leave less information
395# available via JDWP.
396ifneq (,$(PRODUCT_MINIMIZE_JAVA_DEBUG_INFO))
397ifneq (,$(filter userdebug user,$(TARGET_BUILD_VARIANT)))
398LOCAL_JAVACFLAGS+= -g:source,lines
Przemyslaw Szczepaniak2e81b3c2017-06-30 14:51:12 +0100399endif
400endif
401
Colin Crossdfc45ec2017-05-26 15:22:02 -0700402# List of dependencies for anything that needs all java sources in place
403java_sources_deps := \
404 $(java_sources) \
405 $(java_resource_sources) \
406 $(RenderScript_file_stamp) \
407 $(proto_java_sources_file_stamp) \
Colin Cross11e2d552018-03-07 15:44:54 -0800408 $(LOCAL_SRCJARS) \
Colin Crossdfc45ec2017-05-26 15:22:02 -0700409 $(LOCAL_ADDITIONAL_DEPENDENCIES)
410
411$(java_source_list_file): $(java_sources_deps)
412 $(write-java-source-list)
413
Colin Cross7dc90432017-09-26 16:17:24 -0700414ifneq ($(TURBINE_ENABLED),false)
415
Nan Zhangb3ec5342017-08-31 21:43:04 +0000416$(full_classes_turbine_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) $(annotation_processor_flags)
Colin Cross11e2d552018-03-07 15:44:54 -0800417$(full_classes_turbine_jar): PRIVATE_SRCJARS := $(LOCAL_SRCJARS)
Nan Zhangb3ec5342017-08-31 21:43:04 +0000418$(full_classes_turbine_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
419$(full_classes_turbine_jar): \
420 $(java_source_list_file) \
421 $(java_sources_deps) \
422 $(full_java_header_libs) \
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700423 $(full_java_bootclasspath_libs) \
Colin Crossf9602572017-10-12 13:34:40 -0700424 $(full_java_system_modules_deps) \
Nan Zhangb3ec5342017-08-31 21:43:04 +0000425 $(NORMALIZE_PATH) \
426 $(JAR_ARGS) \
427 $(ZIPTIME) \
Nan Zhang9bd54052017-09-13 13:13:53 -0700428 | $(TURBINE) \
429 $(MERGE_ZIPS)
Nan Zhangb3ec5342017-08-31 21:43:04 +0000430 $(transform-java-to-header.jar)
431
432.KATI_RESTAT: $(full_classes_turbine_jar)
433
434# Run jarjar before generate classes-header.jar if necessary.
435ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
436$(full_classes_header_jarjar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
437$(full_classes_header_jarjar): $(full_classes_turbine_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
438 @echo Header JarJar: $@
439 $(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
440else
441full_classes_header_jarjar := $(full_classes_turbine_jar)
442endif
443
444$(eval $(call copy-one-file,$(full_classes_header_jarjar),$(full_classes_header_jar)))
445
Colin Cross7dc90432017-09-26 16:17:24 -0700446endif # TURBINE_ENABLED != false
447
Colin Cross5ef6e792018-03-07 14:16:43 -0800448$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) $(annotation_processor_flags)
449$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES := $(LOCAL_JAR_EXCLUDE_FILES)
450$(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES := $(LOCAL_JAR_PACKAGES)
451$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_PACKAGES := $(LOCAL_JAR_EXCLUDE_PACKAGES)
452$(full_classes_compiled_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
453$(full_classes_compiled_jar): PRIVATE_JAVA_SOURCE_LIST := $(java_source_list_file)
454$(full_classes_compiled_jar): PRIVATE_ALL_JAVA_HEADER_LIBRARIES := $(full_java_header_libs)
Colin Cross11e2d552018-03-07 15:44:54 -0800455$(full_classes_compiled_jar): PRIVATE_SRCJARS := $(LOCAL_SRCJARS)
456$(full_classes_compiled_jar): PRIVATE_SRCJAR_LIST_FILE := $(intermediates.COMMON)/srcjar-list
457$(full_classes_compiled_jar): PRIVATE_SRCJAR_INTERMEDIATES_DIR := $(intermediates.COMMON)/srcjars
Colin Cross5ef6e792018-03-07 14:16:43 -0800458$(full_classes_compiled_jar): \
459 $(java_source_list_file) \
460 $(full_java_header_libs) \
461 $(java_sources_deps) \
462 $(full_java_bootclasspath_libs) \
463 $(full_java_system_modules_deps) \
464 $(layers_file) \
465 $(annotation_processor_deps) \
466 $(NORMALIZE_PATH) \
467 $(JAR_ARGS) \
Colin Cross3f99cd52018-03-15 16:26:08 -0700468 $(ZIPSYNC) \
Colin Cross5ef6e792018-03-07 14:16:43 -0800469 | $(SOONG_JAVAC_WRAPPER)
470 @echo "Target Java: $@
471 $(call compile-java,$(TARGET_JAVAC),$(PRIVATE_ALL_JAVA_HEADER_LIBRARIES))
472
Ying Wangcddeb6c2016-03-24 11:00:30 -0700473javac-check : $(full_classes_compiled_jar)
Paul Duffin32bd0ad2016-09-15 14:34:42 +0100474javac-check-$(LOCAL_MODULE) : $(full_classes_compiled_jar)
Ying Wangcddeb6c2016-03-24 11:00:30 -0700475
Nan Zhang9bd54052017-09-13 13:13:53 -0700476$(full_classes_combined_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
477$(full_classes_combined_jar): $(full_classes_compiled_jar) \
Nan Zhangb8801172017-09-20 14:56:48 -0700478 $(jar_manifest_file) \
Nan Zhang9bd54052017-09-13 13:13:53 -0700479 $(full_static_java_libs) | $(MERGE_ZIPS)
Nan Zhangb8801172017-09-20 14:56:48 -0700480 $(if $(PRIVATE_JAR_MANIFEST), $(hide) sed -e "s/%BUILD_NUMBER%/$(BUILD_NUMBER_FROM_FILE)/" \
481 $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf)
Colin Cross5b73ab32018-02-14 10:32:48 -0800482 $(MERGE_ZIPS) -j --ignore-duplicates $(if $(PRIVATE_JAR_MANIFEST),-m $(dir $@)/manifest.mf) \
Nan Zhangb8801172017-09-20 14:56:48 -0700483 $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,-stripDir META-INF -zipToNotStrip $<) \
484 $@ $< $(call reverse-list,$(PRIVATE_STATIC_JAVA_LIBRARIES))
Nan Zhang9bd54052017-09-13 13:13:53 -0700485
Colin Crossf8a49c52017-05-22 16:21:49 -0700486ifdef LOCAL_JAR_PROCESSOR
487# LOCAL_JAR_PROCESSOR_ARGS must be evaluated here to set up the rule-local
488# PRIVATE_JAR_PROCESSOR_ARGS variable, but $< and $@ are not available yet.
489# Set ${in} and ${out} so they can be referenced by LOCAL_JAR_PROCESSOR_ARGS
490# using deferred evaluation (LOCAL_JAR_PROCESSOR_ARGS = instead of :=).
Nan Zhang9bd54052017-09-13 13:13:53 -0700491in := $(full_classes_combined_jar)
Colin Crossf8a49c52017-05-22 16:21:49 -0700492out := $(full_classes_processed_jar).tmp
Colin Cross89b802b2017-07-13 19:25:47 -0700493my_jar_processor := $(HOST_OUT_JAVA_LIBRARIES)/$(LOCAL_JAR_PROCESSOR).jar
494
Colin Crossf8a49c52017-05-22 16:21:49 -0700495$(full_classes_processed_jar): PRIVATE_JAR_PROCESSOR_ARGS := $(LOCAL_JAR_PROCESSOR_ARGS)
Colin Cross89b802b2017-07-13 19:25:47 -0700496$(full_classes_processed_jar): PRIVATE_JAR_PROCESSOR := $(my_jar_processor)
Colin Crossf8a49c52017-05-22 16:21:49 -0700497$(full_classes_processed_jar): PRIVATE_TMP_OUT := $(out)
498in :=
499out :=
500
Nan Zhang9bd54052017-09-13 13:13:53 -0700501$(full_classes_processed_jar): $(full_classes_combined_jar) $(my_jar_processor)
Colin Crossf8a49c52017-05-22 16:21:49 -0700502 @echo Processing $@ with $(PRIVATE_JAR_PROCESSOR)
503 $(hide) rm -f $@ $(PRIVATE_TMP_OUT)
Colin Cross0851df82017-06-30 13:55:38 -0700504 $(hide) $(JAVA) -jar $(PRIVATE_JAR_PROCESSOR) $(PRIVATE_JAR_PROCESSOR_ARGS)
Colin Crossf8a49c52017-05-22 16:21:49 -0700505 $(hide) mv $(PRIVATE_TMP_OUT) $@
506
Colin Cross89b802b2017-07-13 19:25:47 -0700507my_jar_processor :=
Colin Crossf8a49c52017-05-22 16:21:49 -0700508else
Nan Zhang9bd54052017-09-13 13:13:53 -0700509full_classes_processed_jar := $(full_classes_combined_jar)
Colin Crossf8a49c52017-05-22 16:21:49 -0700510endif
511
Nan Zhang870025f2017-09-13 14:56:11 -0700512# Run jarjar if necessary
513ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
514$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
515$(full_classes_jarjar_jar): $(full_classes_processed_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
516 @echo JarJar: $@
517 $(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
518else
519full_classes_jarjar_jar := $(full_classes_processed_jar)
520endif
521
522$(eval $(call copy-one-file,$(full_classes_jarjar_jar),$(full_classes_jar)))
523
Colin Cross96873482017-12-22 16:51:23 -0800524LOCAL_FULL_CLASSES_PRE_JACOCO_JAR := $(full_classes_jar)
525
526#######################################
527include $(BUILD_SYSTEM)/jacoco.mk
528#######################################
529
Tobias Thierer7ef760b2017-11-17 13:02:12 +0000530# Temporarily enable --multi-dex until proguard supports v53 class files
531# ( http://b/67673860 ) or we move away from proguard altogether.
Tobias Thiererf6bd4952017-11-15 20:55:03 +0000532ifdef TARGET_OPENJDK9
Tobias Thierer89740662017-10-25 02:38:01 +0100533LOCAL_DX_FLAGS := $(filter-out --multi-dex,$(LOCAL_DX_FLAGS)) --multi-dex
534endif
535
Alan Leungeaafb3c2017-12-01 14:32:58 -0800536ifneq ($(USE_D8_DESUGAR),true)
Colin Crosseac5ce42016-12-21 17:11:03 -0800537my_desugaring :=
Colin Cross31060fd2017-03-21 10:17:04 -0700538ifndef LOCAL_IS_STATIC_JAVA_LIBRARY
Colin Crosseac5ce42016-12-21 17:11:03 -0800539my_desugaring := true
540$(full_classes_desugar_jar): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
Colin Cross96873482017-12-22 16:51:23 -0800541$(full_classes_desugar_jar): $(LOCAL_FULL_CLASSES_JACOCO_JAR) $(full_java_header_libs) $(DESUGAR)
Colin Crosseac5ce42016-12-21 17:11:03 -0800542 $(desugar-classes-jar)
543endif
Alan Leungeaafb3c2017-12-01 14:32:58 -0800544else
545my_desugaring :=
546endif
Colin Crosseac5ce42016-12-21 17:11:03 -0800547
548ifndef my_desugaring
Colin Cross96873482017-12-22 16:51:23 -0800549full_classes_desugar_jar := $(LOCAL_FULL_CLASSES_JACOCO_JAR)
Colin Crosseac5ce42016-12-21 17:11:03 -0800550endif
551
Colin Cross96873482017-12-22 16:51:23 -0800552full_classes_pre_proguard_jar := $(full_classes_desugar_jar)
Ying Wang3b2bdf12010-02-01 09:51:23 -0800553
Colin Cross950f1ef2017-04-05 15:30:42 -0700554# Keep a copy of the jar just before proguard processing.
555$(eval $(call copy-one-file,$(full_classes_pre_proguard_jar),$(intermediates.COMMON)/classes-pre-proguard.jar))
Shinichiro Hamaji89b255a2015-11-09 16:47:42 +0900556
Colin Cross0e537342017-03-29 12:17:36 -0700557# Run proguard if necessary
Ying Wang7311a342013-08-21 18:32:49 -0700558ifdef LOCAL_PROGUARD_ENABLED
Colin Crosse616f342017-12-28 09:43:41 -0800559ifneq ($(filter-out full custom obfuscation optimization,$(LOCAL_PROGUARD_ENABLED)),)
Ying Wang7311a342013-08-21 18:32:49 -0700560 $(warning while processing: $(LOCAL_MODULE))
561 $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED))
562endif
Joe Onorato2daa2b32009-08-30 13:39:24 -0700563proguard_dictionary := $(intermediates.COMMON)/proguard_dictionary
Ying Wang4f5d0e62015-05-04 19:21:48 -0700564
Colin Crossb5f25a22017-10-20 19:16:41 -0700565# When an app contains references to APIs that are not in the SDK specified by
566# its LOCAL_SDK_VERSION for example added by support library or by runtime
567# classes added by desugar, we artifically raise the "SDK version" "linked" by
568# ProGuard, to
Ying Wang4f5d0e62015-05-04 19:21:48 -0700569# - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version.
570# - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version.
Colin Crossb5f25a22017-10-20 19:16:41 -0700571# See b/20667396
572my_proguard_sdk_raise :=
Ying Wang4f5d0e62015-05-04 19:21:48 -0700573ifdef LOCAL_SDK_VERSION
Ying Wang4f5d0e62015-05-04 19:21:48 -0700574ifdef TARGET_BUILD_APPS
Jiyong Park5ebca302018-01-31 00:14:55 +0900575ifeq (,$(filter current system_current test_current core_current, $(LOCAL_SDK_VERSION)))
Colin Crossb5f25a22017-10-20 19:16:41 -0700576 my_proguard_sdk_raise := $(call java-lib-header-files, sdk_vcurrent)
Ying Wang742f5832015-06-26 12:33:06 -0700577endif
Ying Wang4f5d0e62015-05-04 19:21:48 -0700578else
579 # For platform build, we can't just raise to the "current" SDK,
580 # that would break apps that use APIs removed from the current SDK.
Colin Crossb5f25a22017-10-20 19:16:41 -0700581 my_proguard_sdk_raise := $(call java-lib-header-files,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES) $(TARGET_DEFAULT_JAVA_LIBRARIES))
Ying Wang4f5d0e62015-05-04 19:21:48 -0700582endif
583endif
Ying Wang4f5d0e62015-05-04 19:21:48 -0700584
Colin Crossb5f25a22017-10-20 19:16:41 -0700585legacy_proguard_flags := $(addprefix -libraryjars ,$(my_proguard_sdk_raise) \
586 $(filter-out $(my_proguard_sdk_raise), \
Colin Crossb541aae2017-09-23 19:52:43 -0700587 $(full_java_bootclasspath_libs) \
588 $(full_shared_java_header_libs)))
Nan Zhangb3ec5342017-08-31 21:43:04 +0000589
Colin Crossb5f25a22017-10-20 19:16:41 -0700590legacy_proguard_lib_deps := $(my_proguard_sdk_raise) \
591 $(filter-out $(my_proguard_sdk_raise),$(full_shared_java_header_libs))
Yohann Rousselb7de0fb2015-11-03 18:33:21 +0100592
593legacy_proguard_flags += -printmapping $(proguard_dictionary)
Yohann Rousselb7de0fb2015-11-03 18:33:21 +0100594
595common_proguard_flags := -forceprocessing
Ying Wang7311a342013-08-21 18:32:49 -0700596
Colin Crosse616f342017-12-28 09:43:41 -0800597common_proguard_flag_files := $(BUILD_SYSTEM)/proguard.flags
Ying Wang7311a342013-08-21 18:32:49 -0700598ifneq ($(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS)),)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200599common_proguard_flags += -dontshrink # don't shrink tests by default
Ying Wang3b2bdf12010-02-01 09:51:23 -0800600endif # test package
Dan Willemsen1d646232017-11-17 13:11:26 -0800601ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
602 ifdef LOCAL_USE_AAPT2
603 common_proguard_flag_files += $(foreach l,$(LOCAL_STATIC_ANDROID_LIBRARIES),\
604 $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/export_proguard_flags)
605 endif
606endif
Shinichiro Hamaji4eaeef82016-04-07 18:56:42 +0900607ifneq ($(common_proguard_flag_files),)
608common_proguard_flags += $(addprefix -include , $(common_proguard_flag_files))
609# This is included from $(BUILD_SYSTEM)/proguard.flags
610common_proguard_flag_files += $(BUILD_SYSTEM)/proguard_basic_keeps.flags
611endif
612
Ying Wang7311a342013-08-21 18:32:49 -0700613ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
614# By default no obfuscation
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200615common_proguard_flags += -dontobfuscate
Ying Wang7311a342013-08-21 18:32:49 -0700616endif # No obfuscation
617ifeq ($(filter optimization,$(LOCAL_PROGUARD_ENABLED)),)
618# By default no optimization
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200619common_proguard_flags += -dontoptimize
Ying Wang7311a342013-08-21 18:32:49 -0700620endif # No optimization
Ying Wang3b2bdf12010-02-01 09:51:23 -0800621
Ying Wang7311a342013-08-21 18:32:49 -0700622ifdef LOCAL_INSTRUMENTATION_FOR
623ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
624# If no obfuscation, link in the instrmented package's classes.jar as a library.
625# link_instr_classes_jar is defined in base_rule.mk
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200626legacy_proguard_flags += -libraryjars $(link_instr_classes_jar)
Nan Zhangb3ec5342017-08-31 21:43:04 +0000627legacy_proguard_lib_deps += $(link_instr_classes_jar)
Ying Wang7311a342013-08-21 18:32:49 -0700628else # obfuscation
629# If obfuscation is enabled, the main app must be obfuscated too.
630# We need to run obfuscation using the main app's dictionary,
631# and treat the main app's class.jar as injars instead of libraryjars.
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200632legacy_proguard_flags := -injars $(link_instr_classes_jar) \
Ying Wang7311a342013-08-21 18:32:49 -0700633 -outjars $(intermediates.COMMON)/proguard.$(LOCAL_INSTRUMENTATION_FOR).jar \
634 -include $(link_instr_intermediates_dir.COMMON)/proguard_options \
635 -applymapping $(link_instr_intermediates_dir.COMMON)/proguard_dictionary \
636 -verbose \
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200637 $(legacy_proguard_flags)
Ying Wang7311a342013-08-21 18:32:49 -0700638
639# Sometimes (test + main app) uses different keep rules from the main app -
640# apply the main app's dictionary anyway.
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200641legacy_proguard_flags += -ignorewarnings
Ying Wang7311a342013-08-21 18:32:49 -0700642
643# Make sure we run Proguard on the main app first
644$(full_classes_proguard_jar) : $(link_instr_intermediates_dir.COMMON)/proguard.classes.jar
645
646endif # no obfuscation
647endif # LOCAL_INSTRUMENTATION_FOR
Joe Onorato2daa2b32009-08-30 13:39:24 -0700648
Ying Wang0b9382c2010-09-29 14:50:41 -0700649proguard_flag_files := $(addprefix $(LOCAL_PATH)/, $(LOCAL_PROGUARD_FLAG_FILES))
Colin Cross5c66c282018-03-14 09:56:04 -0700650ifeq ($(LOCAL_USE_R8),true)
Søren Gjesse0c1fe642017-10-12 16:09:13 +0200651proguard_flag_files += $(addprefix $(LOCAL_PATH)/, $(LOCAL_R8_FLAG_FILES))
Colin Cross5c66c282018-03-14 09:56:04 -0700652endif # LOCAL_USE_R8
Ying Wang0b9382c2010-09-29 14:50:41 -0700653LOCAL_PROGUARD_FLAGS += $(addprefix -include , $(proguard_flag_files))
654
Mihail Dumitrescu4df82b32014-02-07 15:18:59 +0000655ifdef LOCAL_TEST_MODULE_TO_PROGUARD_WITH
656extra_input_jar := $(call intermediates-dir-for,APPS,$(LOCAL_TEST_MODULE_TO_PROGUARD_WITH),,COMMON)/classes.jar
657else
658extra_input_jar :=
659endif
Paul Duffinf22aca12017-02-21 13:11:13 +0000660
Colin Crosse673deb2017-09-27 14:28:41 -0700661# If building against the current SDK version then filter out the junit,
662# android.test and c.a.i.u.Predicate classes that are to be removed from
663# the Android API as part of b/30188076 but which are still present in
664# the Android API. This is to allow changes to be made to the build to
665# statically include those classes into the application without
Paul Duffinf22aca12017-02-21 13:11:13 +0000666# simultaneously removing those classes from the API.
667proguard_injar_filters :=
Paul Duffinf22aca12017-02-21 13:11:13 +0000668ifdef LOCAL_SDK_VERSION
669ifeq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
Paul Duffin54747a72017-06-15 08:42:23 +0100670proguard_injar_filters := (!junit/framework/**,!junit/runner/**,!junit/textui/**,!android/test/**,!com/android/internal/util/*)
Paul Duffinf22aca12017-02-21 13:11:13 +0000671endif
672endif
Paul Duffinf22aca12017-02-21 13:11:13 +0000673
Dan Willemsenbdd6a752017-09-25 23:36:19 -0700674ifneq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
Colin Cross5c66c282018-03-14 09:56:04 -0700675ifneq ($(LOCAL_USE_R8),true)
Dan Willemsenbdd6a752017-09-25 23:36:19 -0700676 $(full_classes_proguard_jar): .KATI_IMPLICIT_OUTPUTS := $(proguard_dictionary)
Søren Gjesse4ab5b022017-10-25 17:10:59 +0200677else
678 $(built_dex_intermediate): .KATI_IMPLICIT_OUTPUTS := $(proguard_dictionary)
679endif
Dan Willemsenbdd6a752017-09-25 23:36:19 -0700680endif
Søren Gjesse0c1fe642017-10-12 16:09:13 +0200681
682# If R8 is not enabled run Proguard.
Colin Cross5c66c282018-03-14 09:56:04 -0700683ifneq ($(LOCAL_USE_R8),true)
Søren Gjesse0c1fe642017-10-12 16:09:13 +0200684# Changes to these dependencies need to be replicated below when using R8
685# instead of Proguard + dx.
Paul Duffinf22aca12017-02-21 13:11:13 +0000686$(full_classes_proguard_jar): PRIVATE_PROGUARD_INJAR_FILTERS := $(proguard_injar_filters)
Mihail Dumitrescu4df82b32014-02-07 15:18:59 +0000687$(full_classes_proguard_jar): PRIVATE_EXTRA_INPUT_JAR := $(extra_input_jar)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200688$(full_classes_proguard_jar): PRIVATE_PROGUARD_FLAGS := $(legacy_proguard_flags) $(common_proguard_flags) $(LOCAL_PROGUARD_FLAGS)
Colin Crossb5f25a22017-10-20 19:16:41 -0700689$(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 -0800690 $(call transform-jar-to-proguard)
Colin Cross5c66c282018-03-14 09:56:04 -0700691else # !LOCAL_USE_R8
Søren Gjesse0c1fe642017-10-12 16:09:13 +0200692# Running R8 instead of Proguard, proguarded jar is actually the pre-Proguarded jar.
693full_classes_proguard_jar := $(full_classes_pre_proguard_jar)
Colin Cross5c66c282018-03-14 09:56:04 -0700694endif # !LOCAL_USE_R8
Ying Wang3b2bdf12010-02-01 09:51:23 -0800695
Ying Wang7311a342013-08-21 18:32:49 -0700696else # LOCAL_PROGUARD_ENABLED not defined
ShuJie Wang76e93ba2017-11-06 14:35:52 +0800697proguard_flag_files :=
Colin Cross950f1ef2017-04-05 15:30:42 -0700698full_classes_proguard_jar := $(full_classes_pre_proguard_jar)
Ying Wang7311a342013-08-21 18:32:49 -0700699endif # LOCAL_PROGUARD_ENABLED defined
700
Colin Cross96476c12017-04-06 09:56:19 -0700701ifneq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
Colin Cross79e2f732016-12-21 14:29:13 -0800702$(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
Søren Gjesse0c1fe642017-10-12 16:09:13 +0200703
704my_r8 :=
705ifdef LOCAL_PROGUARD_ENABLED
Colin Cross5c66c282018-03-14 09:56:04 -0700706ifeq ($(LOCAL_USE_R8),true)
Søren Gjesse0c1fe642017-10-12 16:09:13 +0200707# These are the dependencies for the proguarded jar when running
708# Proguard + dx. They are used for the generated dex when using R8, as
709# R8 does Proguard + dx
710my_r8 := true
711$(built_dex_intermediate): PRIVATE_PROGUARD_INJAR_FILTERS := $(proguard_injar_filters)
712$(built_dex_intermediate): PRIVATE_EXTRA_INPUT_JAR := $(extra_input_jar)
713$(built_dex_intermediate): PRIVATE_PROGUARD_FLAGS := $(legacy_proguard_flags) $(common_proguard_flags) $(LOCAL_PROGUARD_FLAGS)
Alan Leung7d6144d2017-11-16 15:51:07 -0800714$(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 +0200715 $(transform-jar-to-dex-r8)
Colin Cross5c66c282018-03-14 09:56:04 -0700716endif # LOCAL_USE_R8
Søren Gjesse0c1fe642017-10-12 16:09:13 +0200717endif # LOCAL_PROGUARD_ENABLED
718
719ifndef my_r8
Alan Leung5eb88c02017-12-20 20:03:58 -0800720$(built_dex_intermediate): $(full_classes_proguard_jar) $(DX) $(ZIP2ZIP)
Alan Leungeaafb3c2017-12-01 14:32:58 -0800721ifneq ($(USE_D8_DESUGAR),true)
Colin Cross79e2f732016-12-21 14:29:13 -0800722 $(transform-classes.jar-to-dex)
Alan Leungeaafb3c2017-12-01 14:32:58 -0800723else
724 $(transform-classes-d8.jar-to-dex)
725endif
Søren Gjesse0c1fe642017-10-12 16:09:13 +0200726endif
Colin Cross79e2f732016-12-21 14:29:13 -0800727
David Brazdilb8fa6dd2018-01-29 14:43:14 +0000728ifneq ($(filter $(LOCAL_MODULE),$(PRODUCT_BOOT_JARS)),) # is_boot_jar
729 $(eval $(call hiddenapi-copy-dex-files,$(built_dex_intermediate),$(built_dex_hiddenapi)))
730 built_dex_copy_from := $(built_dex_hiddenapi)
731else # !is_boot_jar
732 built_dex_copy_from := $(built_dex_intermediate)
733endif # is_boot_jar
734
735$(built_dex): $(built_dex_copy_from)
Guang Zhu155afe32010-03-10 15:48:03 -0800736 @echo Copying: $@
Yohann Roussel8ffe9c32013-08-20 17:05:27 +0200737 $(hide) mkdir -p $(dir $@)
738 $(hide) rm -f $(dir $@)/classes*.dex
Colin Cross0e537342017-03-29 12:17:36 -0700739 $(hide) cp -fp $(dir $<)/classes*.dex $(dir $@)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800740
Colin Cross9eff8302017-04-27 15:05:44 -0700741java-dex: $(built_dex)
742
Colin Cross96476c12017-04-06 09:56:19 -0700743endif # !LOCAL_IS_STATIC_JAVA_LIBRARY
744
The Android Open Source Project88b60792009-03-03 19:28:42 -0800745findbugs_xml := $(intermediates.COMMON)/findbugs.xml
Ying Wang702e01e2015-10-21 10:30:51 -0700746$(findbugs_xml): PRIVATE_AUXCLASSPATH := $(addprefix -auxclasspath ,$(strip \
747 $(call normalize-path-list,$(filter %.jar,$(full_java_libs)))))
748$(findbugs_xml): PRIVATE_FINDBUGS_FLAGS := $(LOCAL_FINDBUGS_FLAGS)
Colin Cross950f1ef2017-04-05 15:30:42 -0700749$(findbugs_xml) : $(full_classes_pre_proguard_jar) $(filter %.xml, $(LOCAL_FINDBUGS_FLAGS))
The Android Open Source Project88b60792009-03-03 19:28:42 -0800750 @echo Findbugs: $@
751 $(hide) $(FINDBUGS) -textui -effort:min -xml:withMessages \
Ying Wang702e01e2015-10-21 10:30:51 -0700752 $(PRIVATE_AUXCLASSPATH) $(PRIVATE_FINDBUGS_FLAGS) \
Yohann Rousseld2a76c12015-02-05 16:10:58 +0100753 $< \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800754 > $@
755
756ALL_FINDBUGS_FILES += $(findbugs_xml)
757
758findbugs_html := $(PRODUCT_OUT)/findbugs/$(LOCAL_MODULE).html
759$(findbugs_html) : PRIVATE_XML_FILE := $(findbugs_xml)
760$(LOCAL_MODULE)-findbugs : $(findbugs_html)
761$(findbugs_html) : $(findbugs_xml)
762 @mkdir -p $(dir $@)
Andrew Stadlercef9ed92009-05-13 00:44:59 -0700763 @echo ConvertXmlToText: $@
Yuncheol Heo623d7062014-05-20 17:04:16 +0900764 $(hide) $(FINDBUGS_DIR)/convertXmlToText -html:fancy.xsl $(PRIVATE_XML_FILE) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800765 > $@
766
767$(LOCAL_MODULE)-findbugs : $(findbugs_html)
768
Ying Wang990cf5e2013-08-28 13:04:46 -0700769endif # full_classes_jar is defined
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200770
Jiyong Park5ebca302018-01-31 00:14:55 +0900771ifneq (,$(filter-out current system_current test_current core_current, $(LOCAL_SDK_VERSION)))
Sundong Ahn5a44d1f2017-10-16 19:20:34 +0900772 my_default_app_target_sdk := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
773 my_sdk_version := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
Colin Cross536ef4e2017-02-21 16:14:55 -0800774else
Colin Cross9deb3312017-09-28 16:17:36 -0700775 my_default_app_target_sdk := $(DEFAULT_APP_TARGET_SDK)
776 my_sdk_version := $(PLATFORM_SDK_VERSION)
Colin Cross536ef4e2017-02-21 16:14:55 -0800777endif
778
Colin Cross9deb3312017-09-28 16:17:36 -0700779ifdef LOCAL_MIN_SDK_VERSION
780 my_min_sdk_version := $(LOCAL_MIN_SDK_VERSION)
781else
782 my_min_sdk_version := $(call codename-or-sdk-to-sdk,$(my_default_app_target_sdk))
783endif
784
785$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(my_default_app_target_sdk)
786$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SDK_VERSION := $(my_sdk_version)
787$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MIN_SDK_VERSION := $(my_min_sdk_version)