java.mk revision 4c474617d491fe98fa02571349138fb757959232
1# Target Java.
2# Requires:
3# LOCAL_MODULE_SUFFIX
4# LOCAL_MODULE_CLASS
5# all_res_assets
6
7ifeq ($(TARGET_BUILD_PDK),true)
8ifeq ($(TARGET_BUILD_PDK_JAVA_PLATFORM),)
9# LOCAL_SDK not defined or set to current
10ifeq ($(filter-out current,$(LOCAL_SDK_VERSION)),)
11ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
12LOCAL_SDK_VERSION := $(PDK_BUILD_SDK_VERSION)
13endif #!LOCAL_NO_STANDARD_LIBRARIES
14endif
15endif # !PDK_JAVA
16endif #PDK
17
18LOCAL_NO_STANDARD_LIBRARIES:=$(strip $(LOCAL_NO_STANDARD_LIBRARIES))
19LOCAL_SDK_VERSION:=$(strip $(LOCAL_SDK_VERSION))
20
21ifneq ($(LOCAL_SDK_VERSION),)
22  ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
23    $(error $(LOCAL_PATH): Must not define both LOCAL_NO_STANDARD_LIBRARIES and LOCAL_SDK_VERSION)
24  else
25    ifeq ($(strip $(filter $(LOCAL_SDK_VERSION),$(TARGET_AVAILABLE_SDK_VERSIONS))),)
26      $(error $(LOCAL_PATH): Invalid LOCAL_SDK_VERSION '$(LOCAL_SDK_VERSION)' \
27             Choices are: $(TARGET_AVAILABLE_SDK_VERSIONS))
28    else
29      ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),current)
30        # Use android_stubs_current if LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS.
31        LOCAL_JAVA_LIBRARIES := android_stubs_current $(LOCAL_JAVA_LIBRARIES)
32      else ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),system_current)
33        LOCAL_JAVA_LIBRARIES := android_system_stubs_current $(LOCAL_JAVA_LIBRARIES)
34      else
35        LOCAL_JAVA_LIBRARIES := sdk_v$(LOCAL_SDK_VERSION) $(LOCAL_JAVA_LIBRARIES)
36      endif
37    endif
38  endif
39else
40  ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
41    LOCAL_JAVA_LIBRARIES := $(TARGET_DEFAULT_JAVA_LIBRARIES) $(LOCAL_JAVA_LIBRARIES)
42  endif
43endif
44
45proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
46ifneq ($(proto_sources),)
47ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro)
48    LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-micro
49else
50  ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nano)
51    LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-nano
52  else
53    LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-lite
54  endif
55endif
56endif
57
58# LOCAL_STATIC_JAVA_AAR_LIBRARIES are special LOCAL_STATIC_JAVA_LIBRARIES
59LOCAL_STATIC_JAVA_LIBRARIES := $(strip $(LOCAL_STATIC_JAVA_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES))
60
61LOCAL_JAVA_LIBRARIES := $(sort $(LOCAL_JAVA_LIBRARIES))
62
63LOCAL_BUILT_MODULE_STEM := $(strip $(LOCAL_BUILT_MODULE_STEM))
64ifeq ($(LOCAL_BUILT_MODULE_STEM),)
65$(error $(LOCAL_PATH): Target java template must define LOCAL_BUILT_MODULE_STEM)
66endif
67ifneq ($(filter classes-compiled.jar classes.jar,$(LOCAL_BUILT_MODULE_STEM)),)
68$(error LOCAL_BUILT_MODULE_STEM may not be "$(LOCAL_BUILT_MODULE_STEM)")
69endif
70
71
72##############################################################################
73# Define the intermediate targets before including base_rules so they get
74# the correct environment.
75##############################################################################
76
77intermediates := $(call local-intermediates-dir)
78intermediates.COMMON := $(call local-intermediates-dir,COMMON)
79
80# Choose leaf name for the compiled jar file.
81ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
82full_classes_compiled_jar_leaf := classes-no-debug-var.jar
83built_dex_intermediate_leaf := no-local
84else
85full_classes_compiled_jar_leaf := classes-full-debug.jar
86built_dex_intermediate_leaf := with-local
87endif
88
89ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
90LOCAL_PROGUARD_ENABLED :=
91endif
92
93ifdef LOCAL_PROGUARD_ENABLED
94proguard_jar_leaf := proguard.classes.jar
95else
96proguard_jar_leaf := noproguard.classes.jar
97endif
98
99full_classes_compiled_jar := $(intermediates.COMMON)/$(full_classes_compiled_jar_leaf)
100jarjar_leaf := classes-jarjar.jar
101full_classes_jarjar_jar := $(intermediates.COMMON)/$(jarjar_leaf)
102emma_intermediates_dir := $(intermediates.COMMON)/emma_out
103# emma is hardcoded to use the leaf name of its input for the output file --
104# only the output directory can be changed
105full_classes_emma_jar := $(emma_intermediates_dir)/lib/$(jarjar_leaf)
106full_classes_proguard_jar := $(intermediates.COMMON)/$(proguard_jar_leaf)
107built_dex_intermediate := $(intermediates.COMMON)/$(built_dex_intermediate_leaf)/classes.dex
108full_classes_stubs_jar := $(intermediates.COMMON)/stubs.jar
109
110ifeq ($(LOCAL_MODULE_CLASS)$(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),APPS)
111# If this is an apk without any Java code (e.g. framework-res), we should skip compiling Java.
112full_classes_jar :=
113built_dex :=
114else
115full_classes_jar := $(intermediates.COMMON)/classes.jar
116built_dex := $(intermediates.COMMON)/classes.dex
117endif
118# final Jack library, shrinked and obfuscated if it must be
119full_classes_jack := $(intermediates.COMMON)/classes.jack
120# intermediate Jack library without shrink and obfuscation
121noshrob_classes_jack := $(intermediates.COMMON)/classes.noshrob.jack
122
123LOCAL_INTERMEDIATE_TARGETS += \
124    $(full_classes_compiled_jar) \
125    $(full_classes_jarjar_jar) \
126    $(full_classes_emma_jar) \
127    $(full_classes_jar) \
128    $(full_classes_proguard_jar) \
129    $(built_dex_intermediate) \
130    $(full_classes_jack) \
131    $(noshrob_classes_jack) \
132    $(built_dex) \
133    $(full_classes_stubs_jar)
134
135
136LOCAL_INTERMEDIATE_SOURCE_DIR := $(intermediates.COMMON)/src
137
138###############################################################
139## .rs files: RenderScript sources to .java files and .bc files
140## .fs files: Filterscript sources to .java files and .bc files
141###############################################################
142renderscript_sources := $(filter %.rs %.fs,$(LOCAL_SRC_FILES))
143# Because names of the java files from RenderScript are unknown until the
144# .rs file(s) are compiled, we have to depend on a timestamp file.
145RenderScript_file_stamp :=
146rs_compatibility_jni_libs :=
147ifneq ($(renderscript_sources),)
148renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
149RenderScript_file_stamp := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/RenderScript.stamp
150renderscript_intermediate.COMMON := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/renderscript
151
152# Defaulting to an empty string uses the latest available platform SDK.
153renderscript_target_api :=
154
155ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API))
156  renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API)
157else
158  ifneq (,$(LOCAL_SDK_VERSION))
159    # Set target-api for LOCAL_SDK_VERSIONs other than current.
160    ifneq (,$(filter-out current system_current, $(LOCAL_SDK_VERSION)))
161      renderscript_target_api := $(LOCAL_SDK_VERSION)
162    endif
163  endif  # LOCAL_SDK_VERSION is set
164endif  # LOCAL_RENDERSCRIPT_TARGET_API is set
165
166# For 64-bit, we always have to upgrade to at least 21 for compat build.
167ifneq ($(LOCAL_RENDERSCRIPT_COMPATIBILITY),)
168  ifeq ($(TARGET_IS_64_BIT),true)
169    ifneq ($(filter $(RSCOMPAT_32BIT_ONLY_API_LEVELS),$(renderscript_target_api)),)
170      renderscript_target_api := 21
171    endif
172  endif
173endif
174
175ifeq ($(LOCAL_RENDERSCRIPT_CC),)
176LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC)
177endif
178
179# Turn on all warnings and warnings as errors for RS compiles.
180# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
181renderscript_flags := -Wall -Werror
182renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)
183
184# prepend the RenderScript system include path
185ifneq ($(filter-out current system_current,$(LOCAL_SDK_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current,$(LOCAL_SDK_VERSION))),)
186# if a numeric LOCAL_SDK_VERSION, or current LOCAL_SDK_VERSION with TARGET_BUILD_APPS
187LOCAL_RENDERSCRIPT_INCLUDES := \
188    $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/clang-include \
189    $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/include \
190    $(LOCAL_RENDERSCRIPT_INCLUDES)
191else
192LOCAL_RENDERSCRIPT_INCLUDES := \
193    $(TOPDIR)external/clang/lib/Headers \
194    $(TOPDIR)frameworks/rs/scriptc \
195    $(LOCAL_RENDERSCRIPT_INCLUDES)
196endif
197
198ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),)
199LOCAL_RENDERSCRIPT_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE)
200endif
201
202bc_files := $(patsubst %.fs,%.bc, $(patsubst %.rs,%.bc, $(notdir $(renderscript_sources))))
203bc_dep_files := $(addprefix $(renderscript_intermediate.COMMON)/,$(patsubst %.bc,%.d,$(bc_files)))
204
205$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES)
206$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC)
207$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags)
208$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath)
209# By putting the generated java files into $(LOCAL_INTERMEDIATE_SOURCE_DIR), they will be
210# automatically found by the java compiling function transform-java-to-classes.jar.
211$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate.COMMON)
212$(RenderScript_file_stamp): PRIVATE_RS_TARGET_API := $(renderscript_target_api)
213$(RenderScript_file_stamp): PRIVATE_DEP_FILES := $(bc_dep_files)
214$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC)
215	$(transform-renderscripts-to-java-and-bc)
216
217# include the dependency files (.d/.P) generated by llvm-rs-cc.
218$(call include-depfile,$(RenderScript_file_stamp).P,$(RenderScript_file_stamp))
219
220ifneq ($(LOCAL_RENDERSCRIPT_COMPATIBILITY),)
221
222
223ifeq ($(filter $(RSCOMPAT_32BIT_ONLY_API_LEVELS),$(renderscript_target_api)),)
224ifeq ($(TARGET_IS_64_BIT),true)
225renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/bc64/
226else
227renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/bc32/
228endif
229else
230renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/
231endif
232
233rs_generated_bc := $(addprefix \
234    $(renderscript_intermediate.bc_folder), $(bc_files))
235
236renderscript_intermediate := $(intermediates)/renderscript
237
238# We don't need the .so files in bundled branches
239# Prevent these from showing up on the device
240# One exception is librsjni.so, which is needed for
241# both native path and compat path.
242rs_jni_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/librsjni.so
243LOCAL_JNI_SHARED_LIBRARIES += librsjni
244
245ifneq (,$(TARGET_BUILD_APPS)$(FORCE_BUILD_RS_COMPAT))
246
247rs_compatibility_jni_libs := $(addprefix \
248    $(renderscript_intermediate)/librs., \
249    $(patsubst %.bc,%.so, $(bc_files)))
250
251$(rs_generated_bc) : $(RenderScript_file_stamp)
252
253rs_support_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/libRSSupport.so
254LOCAL_JNI_SHARED_LIBRARIES += libRSSupport
255
256rs_support_io_lib :=
257# check if the target api level support USAGE_IO
258ifeq ($(filter $(RSCOMPAT_NO_USAGEIO_API_LEVELS),$(renderscript_target_api)),)
259rs_support_io_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/libRSSupportIO.so
260LOCAL_JNI_SHARED_LIBRARIES += libRSSupportIO
261endif
262
263
264$(rs_compatibility_jni_libs): $(RenderScript_file_stamp) $(RS_PREBUILT_CLCORE) \
265    $(rs_support_lib) $(rs_support_io_lib) $(rs_jni_lib) $(rs_compiler_rt)
266$(rs_compatibility_jni_libs): $(BCC_COMPAT)
267$(rs_compatibility_jni_libs): PRIVATE_CXX := $(CXX_WRAPPER) $(TARGET_CXX)
268$(rs_compatibility_jni_libs): $(renderscript_intermediate)/librs.%.so: \
269    $(renderscript_intermediate.bc_folder)%.bc
270	$(transform-bc-to-so)
271
272endif
273
274endif
275
276LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
277# Make sure the generated resource will be added to the apk.
278LOCAL_RESOURCE_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/renderscript/res $(LOCAL_RESOURCE_DIR)
279endif
280
281
282###########################################################
283## AIDL: Compile .aidl files to .java
284###########################################################
285aidl_sources := $(filter %.aidl,$(LOCAL_SRC_FILES))
286
287ifneq ($(strip $(aidl_sources)),)
288aidl_java_sources := $(patsubst %.aidl,%.java,$(addprefix $(intermediates.COMMON)/src/, $(aidl_sources)))
289aidl_sources := $(addprefix $(LOCAL_PATH)/, $(aidl_sources))
290
291aidl_preprocess_import :=
292ifdef LOCAL_SDK_VERSION
293ifneq ($(filter current system_current, $(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS)),)
294  # LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS
295  aidl_preprocess_import := $(TARGET_OUT_COMMON_INTERMEDIATES)/framework.aidl
296else
297  aidl_preprocess_import := $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_VERSION)/framework.aidl
298endif # not current or system_current
299else
300# build against the platform.
301LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)
302endif # LOCAL_SDK_VERSION
303$(aidl_java_sources): PRIVATE_AIDL_FLAGS := -b $(addprefix -p,$(aidl_preprocess_import)) -I$(LOCAL_PATH) -I$(LOCAL_PATH)/src $(addprefix -I,$(LOCAL_AIDL_INCLUDES))
304
305$(aidl_java_sources): $(intermediates.COMMON)/src/%.java: \
306        $(LOCAL_PATH)/%.aidl \
307        $(LOCAL_MODULE_MAKEFILE_DEP) \
308        $(LOCAL_ADDITIONAL_DEPENDENCIES) \
309        $(AIDL) \
310        $(aidl_preprocess_import)
311	$(transform-aidl-to-java)
312-include $(aidl_java_sources:%.java=%.P)
313
314else
315aidl_java_sources :=
316endif
317
318##########################################
319
320# All of the rules after full_classes_compiled_jar are very unlikely
321# to fail except for bugs in their respective tools.  If you would
322# like to run these rules, add the "all" modifier goal to the make
323# command line.
324ifndef LOCAL_CHECKED_MODULE
325ifdef full_classes_jar
326LOCAL_CHECKED_MODULE := $(full_classes_compiled_jar)
327endif
328endif
329
330#######################################
331include $(BUILD_SYSTEM)/base_rules.mk
332#######################################
333
334###########################################################
335## logtags: emit java source
336###########################################################
337ifneq ($(strip $(logtags_sources)),)
338
339logtags_java_sources := $(patsubst %.logtags,%.java,$(addprefix $(intermediates.COMMON)/src/, $(logtags_sources)))
340logtags_sources := $(addprefix $(LOCAL_PATH)/, $(logtags_sources))
341
342$(logtags_java_sources): $(intermediates.COMMON)/src/%.java: $(LOCAL_PATH)/%.logtags $(TARGET_OUT_COMMON_INTERMEDIATES)/all-event-log-tags.txt
343	$(transform-logtags-to-java)
344
345else
346logtags_java_sources :=
347endif
348
349##########################################
350java_sources := $(addprefix $(LOCAL_PATH)/, $(filter %.java,$(LOCAL_SRC_FILES))) $(aidl_java_sources) $(logtags_java_sources) \
351                $(filter %.java,$(LOCAL_GENERATED_SOURCES))
352all_java_sources := $(java_sources) $(addprefix $(TARGET_OUT_COMMON_INTERMEDIATES)/, $(filter %.java,$(LOCAL_INTERMEDIATE_SOURCES)))
353
354include $(BUILD_SYSTEM)/java_common.mk
355
356#######################################
357# defines built_odex along with rule to install odex
358include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
359#######################################
360
361# Make sure there's something to build.
362ifdef full_classes_jar
363ifndef need_compile_java
364$(error $(LOCAL_PATH): Target java module does not define any source or resource files)
365endif
366endif
367
368# Since we're using intermediates.COMMON, make sure that it gets cleaned
369# properly.
370$(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON)
371
372ifdef full_classes_jar
373
374# Droiddoc isn't currently able to generate stubs for modules, so we're just
375# allowing it to use the classes.jar as the "stubs" that would be use to link
376# against, for the cases where someone needs the jar to link against.
377# - Use the classes.jar instead of the handful of other intermediates that
378#   we have, because it's the most processed, but still hasn't had dex run on
379#   it, so it's closest to what's on the device.
380# - This extra copy, with the dependency on LOCAL_BUILT_MODULE allows the
381#   PRIVATE_ vars to be preserved.
382$(full_classes_stubs_jar): PRIVATE_SOURCE_FILE := $(full_classes_jar)
383$(full_classes_stubs_jar) : $(full_classes_jar) | $(ACP)
384	@echo Copying $(PRIVATE_SOURCE_FILE)
385	$(hide) $(ACP) -fp $(PRIVATE_SOURCE_FILE) $@
386ALL_MODULES.$(LOCAL_MODULE).STUBS := $(full_classes_stubs_jar)
387
388# The layers file allows you to enforce a layering between java packages.
389# Run build/tools/java-layers.py for more details.
390layers_file := $(addprefix $(LOCAL_PATH)/, $(LOCAL_JAVA_LAYERS_FILE))
391$(full_classes_compiled_jar): PRIVATE_JAVA_LAYERS_FILE := $(layers_file)
392$(full_classes_compiled_jar): PRIVATE_WARNINGS_ENABLE := $(LOCAL_WARNINGS_ENABLE)
393
394ifdef LOCAL_RMTYPEDEFS
395$(full_classes_compiled_jar): | $(RMTYPEDEFS)
396endif
397
398# Compile the java files to a .jar file.
399# This intentionally depends on java_sources, not all_java_sources.
400# Deps for generated source files must be handled separately,
401# via deps on the target that generates the sources.
402$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(GLOBAL_JAVAC_DEBUG_FLAGS) $(LOCAL_JAVACFLAGS)
403$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES := $(LOCAL_JAR_EXCLUDE_FILES)
404$(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES := $(LOCAL_JAR_PACKAGES)
405$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_PACKAGES := $(LOCAL_JAR_EXCLUDE_PACKAGES)
406$(full_classes_compiled_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
407$(full_classes_compiled_jar): \
408        $(java_sources) \
409        $(java_resource_sources) \
410        $(full_java_lib_deps) \
411        $(jar_manifest_file) \
412        $(layers_file) \
413        $(RenderScript_file_stamp) \
414        $(proto_java_sources_file_stamp) \
415        $(LOCAL_MODULE_MAKEFILE_DEP) \
416        $(LOCAL_ADDITIONAL_DEPENDENCIES)
417	$(transform-java-to-classes.jar)
418
419# Run jarjar if necessary, otherwise just copy the file.
420ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
421$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
422$(full_classes_jarjar_jar): $(full_classes_compiled_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
423	@echo JarJar: $@
424	$(hide) java -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
425else
426$(full_classes_jarjar_jar): $(full_classes_compiled_jar) | $(ACP)
427	@echo Copying: $@
428	$(hide) $(ACP) -fp $< $@
429endif
430
431ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
432$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILE := $(intermediates.COMMON)/coverage.em
433$(full_classes_emma_jar): PRIVATE_EMMA_INTERMEDIATES_DIR := $(emma_intermediates_dir)
434# module level coverage filter can be defined using LOCAL_EMMA_COVERAGE_FILTER
435# in Android.mk
436ifdef LOCAL_EMMA_COVERAGE_FILTER
437$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := $(LOCAL_EMMA_COVERAGE_FILTER)
438else
439# by default, avoid applying emma instrumentation onto emma classes itself,
440# otherwise there will be exceptions thrown
441$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := *,-emma,-emmarun,-com.vladium.*
442endif
443# this rule will generate both $(PRIVATE_EMMA_COVERAGE_FILE) and
444# $(full_classes_emma_jar)
445$(full_classes_emma_jar): $(full_classes_jarjar_jar) | $(EMMA_JAR)
446	$(transform-classes.jar-to-emma)
447
448else
449$(full_classes_emma_jar): $(full_classes_jarjar_jar) | $(ACP)
450	@echo Copying: $@
451	$(copy-file-to-target)
452endif
453
454# Keep a copy of the jar just before proguard processing.
455$(full_classes_jar): $(full_classes_emma_jar) | $(ACP)
456	@echo Copying: $@
457	$(hide) $(ACP) -fp $< $@
458
459$(call define-jar-to-toc-rule, $(full_classes_jar))
460
461# Run proguard if necessary, otherwise just copy the file.
462ifdef LOCAL_PROGUARD_ENABLED
463ifneq ($(filter-out full custom nosystem obfuscation optimization shrinktests,$(LOCAL_PROGUARD_ENABLED)),)
464    $(warning while processing: $(LOCAL_MODULE))
465    $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED))
466endif
467proguard_dictionary := $(intermediates.COMMON)/proguard_dictionary
468
469# Hack: see b/20667396
470# When an app's LOCAL_SDK_VERSION is lower than the support library's LOCAL_SDK_VERSION,
471# we artifically raises the "SDK version" "linked" by ProGuard, to
472# - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version.
473# - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version.
474my_support_library_sdk_raise :=
475ifneq (,$(filter android-support-%,$(LOCAL_STATIC_JAVA_LIBRARIES)))
476ifdef LOCAL_SDK_VERSION
477ifdef TARGET_BUILD_APPS
478ifeq (,$(filter current system_current, $(LOCAL_SDK_VERSION)))
479  my_support_library_sdk_raise := $(call java-lib-files, sdk_vcurrent)
480endif
481else
482  # For platform build, we can't just raise to the "current" SDK,
483  # that would break apps that use APIs removed from the current SDK.
484  my_support_library_sdk_raise := $(call java-lib-files,$(TARGET_DEFAULT_JAVA_LIBRARIES))
485endif
486endif
487endif
488
489# jack already has the libraries in its classpath and doesn't support jars
490legacy_proguard_flags := $(addprefix -libraryjars ,$(my_support_library_sdk_raise) $(full_shared_java_libs))
491common_proguard_flags :=  \
492                  -forceprocessing \
493                  -printmapping $(proguard_dictionary)
494
495ifeq ($(filter nosystem,$(LOCAL_PROGUARD_ENABLED)),)
496common_proguard_flags += -include $(BUILD_SYSTEM)/proguard.flags
497ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
498common_proguard_flags += -include $(BUILD_SYSTEM)/proguard.emma.flags
499endif
500# If this is a test package, add proguard keep flags for tests.
501ifneq ($(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS)),)
502common_proguard_flags += -include $(BUILD_SYSTEM)/proguard_tests.flags
503ifeq ($(filter shrinktests,$(LOCAL_PROGUARD_ENABLED)),)
504common_proguard_flags += -dontshrink # don't shrink tests by default
505endif # shrinktests
506endif # test package
507ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
508# By default no obfuscation
509common_proguard_flags += -dontobfuscate
510endif  # No obfuscation
511ifeq ($(filter optimization,$(LOCAL_PROGUARD_ENABLED)),)
512# By default no optimization
513common_proguard_flags += -dontoptimize
514endif  # No optimization
515
516ifdef LOCAL_INSTRUMENTATION_FOR
517ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
518# If no obfuscation, link in the instrmented package's classes.jar as a library.
519# link_instr_classes_jar is defined in base_rule.mk
520# jack already has this library in its classpath and doesn't support jars
521legacy_proguard_flags += -libraryjars $(link_instr_classes_jar)
522else # obfuscation
523# If obfuscation is enabled, the main app must be obfuscated too.
524# We need to run obfuscation using the main app's dictionary,
525# and treat the main app's class.jar as injars instead of libraryjars.
526legacy_proguard_flags := -injars  $(link_instr_classes_jar) \
527    -outjars $(intermediates.COMMON)/proguard.$(LOCAL_INSTRUMENTATION_FOR).jar \
528    -include $(link_instr_intermediates_dir.COMMON)/proguard_options \
529    -applymapping $(link_instr_intermediates_dir.COMMON)/proguard_dictionary \
530    -verbose \
531    $(legacy_proguard_flags)
532# not supported with jack
533ifdef LOCAL_JACK_ENABLED
534    $(error $(LOCAL_MODULE): Build with jack of instrumentation when obfuscating is not yet supported)
535endif
536
537# Sometimes (test + main app) uses different keep rules from the main app -
538# apply the main app's dictionary anyway.
539legacy_proguard_flags += -ignorewarnings
540
541# Make sure we run Proguard on the main app first
542$(full_classes_proguard_jar) : $(link_instr_intermediates_dir.COMMON)/proguard.classes.jar
543
544endif # no obfuscation
545endif # LOCAL_INSTRUMENTATION_FOR
546endif  # LOCAL_PROGUARD_ENABLED is not nosystem
547
548proguard_flag_files := $(addprefix $(LOCAL_PATH)/, $(LOCAL_PROGUARD_FLAG_FILES))
549LOCAL_PROGUARD_FLAGS += $(addprefix -include , $(proguard_flag_files))
550
551ifdef LOCAL_TEST_MODULE_TO_PROGUARD_WITH
552extra_input_jar := $(call intermediates-dir-for,APPS,$(LOCAL_TEST_MODULE_TO_PROGUARD_WITH),,COMMON)/classes.jar
553else
554extra_input_jar :=
555endif
556$(full_classes_proguard_jar): PRIVATE_EXTRA_INPUT_JAR := $(extra_input_jar)
557$(full_classes_proguard_jar): PRIVATE_PROGUARD_FLAGS := $(legacy_proguard_flags) $(common_proguard_flags) $(LOCAL_PROGUARD_FLAGS)
558$(full_classes_proguard_jar) : $(full_classes_jar) $(extra_input_jar) $(my_support_library_sdk_raise) $(proguard_flag_files) | $(ACP) $(PROGUARD)
559	$(call transform-jar-to-proguard)
560
561else  # LOCAL_PROGUARD_ENABLED not defined
562$(full_classes_proguard_jar) : $(full_classes_jar)
563	@echo Copying: $@
564	$(hide) $(ACP) -fp $< $@
565
566endif # LOCAL_PROGUARD_ENABLED defined
567
568ifndef LOCAL_JACK_ENABLED
569# Override PRIVATE_INTERMEDIATES_DIR so that install-dex-debug
570# will work even when intermediates != intermediates.COMMON.
571$(built_dex_intermediate): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON)
572$(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
573# If you instrument class files that have local variable debug information in
574# them emma does not correctly maintain the local variable table.
575# This will cause an error when you try to convert the class files for Android.
576# The workaround here is to build different dex file here based on emma switch
577# then later copy into classes.dex. When emma is on, dx is run with --no-locals
578# option to remove local variable information
579ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
580$(built_dex_intermediate): PRIVATE_DX_FLAGS += --no-locals
581endif
582$(built_dex_intermediate): $(full_classes_proguard_jar) $(DX)
583	$(transform-classes.jar-to-dex)
584endif # LOCAL_JACK_ENABLED is disabled
585
586$(built_dex): $(built_dex_intermediate) | $(ACP)
587	@echo Copying: $@
588	$(hide) mkdir -p $(dir $@)
589	$(hide) rm -f $(dir $@)/classes*.dex
590	$(hide) $(ACP) -fp $(dir $<)/classes*.dex $(dir $@)
591ifneq ($(GENERATE_DEX_DEBUG),)
592	$(install-dex-debug)
593endif
594
595findbugs_xml := $(intermediates.COMMON)/findbugs.xml
596$(findbugs_xml) : PRIVATE_AUXCLASSPATH := $(addprefix -auxclasspath ,$(strip \
597								$(call normalize-path-list,$(filter %.jar,\
598										$(full_java_libs)))))
599$(findbugs_xml) : $(full_classes_jar)
600	@echo Findbugs: $@
601	$(hide) $(FINDBUGS) -textui -effort:min -xml:withMessages \
602		$(PRIVATE_AUXCLASSPATH) \
603		$< \
604		> $@
605
606ALL_FINDBUGS_FILES += $(findbugs_xml)
607
608findbugs_html := $(PRODUCT_OUT)/findbugs/$(LOCAL_MODULE).html
609$(findbugs_html) : PRIVATE_XML_FILE := $(findbugs_xml)
610$(LOCAL_MODULE)-findbugs : $(findbugs_html)
611$(findbugs_html) : $(findbugs_xml)
612	@mkdir -p $(dir $@)
613	@echo ConvertXmlToText: $@
614	$(hide) $(FINDBUGS_DIR)/convertXmlToText -html:fancy.xsl $(PRIVATE_XML_FILE) \
615	> $@
616
617$(LOCAL_MODULE)-findbugs : $(findbugs_html)
618
619endif  # full_classes_jar is defined
620
621ifdef LOCAL_JACK_ENABLED
622$(LOCAL_INTERMEDIATE_TARGETS): \
623	PRIVATE_JACK_INTERMEDIATES_DIR := $(intermediates.COMMON)/jack-rsc
624ifeq ($(LOCAL_JACK_ENABLED),incremental)
625$(LOCAL_INTERMEDIATE_TARGETS): \
626	PRIVATE_JACK_INCREMENTAL_DIR := $(intermediates.COMMON)/jack-incremental
627else
628$(LOCAL_INTERMEDIATE_TARGETS): \
629	PRIVATE_JACK_INCREMENTAL_DIR :=
630endif
631
632ifdef full_classes_jar
633ifdef LOCAL_PROGUARD_ENABLED
634
635ifndef LOCAL_JACK_PROGUARD_FLAGS
636    LOCAL_JACK_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS)
637endif
638LOCAL_JACK_PROGUARD_FLAGS += $(addprefix -include , $(proguard_flag_files))
639ifdef LOCAL_TEST_MODULE_TO_PROGUARD_WITH
640    $(error $(LOCAL_MODULE): Build with jack when LOCAL_TEST_MODULE_TO_PROGUARD_WITH is defined is not yet implemented)
641endif
642
643$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_PROGUARD_FLAGS := $(common_proguard_flags) $(LOCAL_JACK_PROGUARD_FLAGS)
644else  # LOCAL_PROGUARD_ENABLED not defined
645$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_PROGUARD_FLAGS :=
646endif # LOCAL_PROGUARD_ENABLED defined
647
648$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_FLAGS := $(GLOBAL_JAVAC_DEBUG_FLAGS) $(LOCAL_JACK_FLAGS)
649$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_VERSION := $(LOCAL_JACK_VERSION)
650
651jack_all_deps := $(java_sources) $(java_resource_sources) $(full_jack_lib_deps) \
652        $(jar_manifest_file) $(layers_file) $(RenderScript_file_stamp) $(proguard_flag_files) \
653        $(proto_java_sources_file_stamp) $(LOCAL_ADDITIONAL_DEPENDENCIES) $(LOCAL_JARJAR_RULES) \
654        $(LOCAL_MODULE_MAKEFILE_DEP) $(JACK)
655
656ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
657$(full_classes_jack): $(jack_all_deps) | setup-jack-server
658	@echo Building with Jack: $@
659	$(java-to-jack)
660
661# Update timestamps of .toc files for static java libraries so
662# dependents will be always rebuilt.
663$(built_dex).toc: $(full_classes_jack)
664	touch $@
665
666else #LOCAL_IS_STATIC_JAVA_LIBRARY
667$(built_dex_intermediate): PRIVATE_CLASSES_JACK := $(full_classes_jack)
668
669$(built_dex_intermediate): $(jack_all_deps) | setup-jack-server
670	@echo Building with Jack: $@
671	$(jack-java-to-dex)
672
673# $(full_classes_jack) is just by-product of $(built_dex_intermediate).
674# The dummy command was added because, without it, make misses the fact the $(built_dex) also
675# change $(full_classes_jack).
676$(full_classes_jack): $(built_dex_intermediate)
677	$(hide) touch $@
678
679$(call define-dex-to-toc-rule, $(intermediates.COMMON))
680
681endif #LOCAL_IS_STATIC_JAVA_LIBRARY
682
683$(noshrob_classes_jack): PRIVATE_JACK_INTERMEDIATES_DIR := $(intermediates.COMMON)/jack-noshrob-rsc
684ifeq ($(LOCAL_JACK_ENABLED),incremental)
685$(noshrob_classes_jack): PRIVATE_JACK_INCREMENTAL_DIR := $(intermediates.COMMON)/jack-noshrob-incremental
686else
687$(noshrob_classes_jack): PRIVATE_JACK_INCREMENTAL_DIR :=
688endif
689$(noshrob_classes_jack): PRIVATE_JACK_PROGUARD_FLAGS :=
690$(noshrob_classes_jack): $(jack_all_deps) | setup-jack-server
691	@echo Building with Jack: $@
692	$(java-to-jack)
693endif  # full_classes_jar is defined
694endif # LOCAL_JACK_ENABLED
695