java.mk revision 36fd47684350fa65316b5260867ea29f609765fd
1# Requires:
2# LOCAL_MODULE_SUFFIX
3# LOCAL_MODULE_CLASS
4# all_res_assets
5
6ifeq ($(TARGET_BUILD_PDK),true)
7ifeq ($(TARGET_BUILD_PDK_JAVA_PLATFORM),)
8# LOCAL_SDK not defined or set to current
9ifeq ($(filter-out current,$(LOCAL_SDK_VERSION)),)
10ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
11LOCAL_SDK_VERSION := $(PDK_BUILD_SDK_VERSION)
12endif #!LOCAL_NO_STANDARD_LIBRARIES
13endif
14endif # !PDK_JAVA
15endif #PDK
16
17LOCAL_NO_STANDARD_LIBRARIES:=$(strip $(LOCAL_NO_STANDARD_LIBRARIES))
18LOCAL_SDK_VERSION:=$(strip $(LOCAL_SDK_VERSION))
19
20ifneq ($(LOCAL_SDK_VERSION),)
21  ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
22    $(error $(LOCAL_PATH): Must not define both LOCAL_NO_STANDARD_LIBRARIES and LOCAL_SDK_VERSION)
23  else
24    ifeq ($(strip $(filter $(LOCAL_SDK_VERSION),$(TARGET_AVAILABLE_SDK_VERSIONS))),)
25      $(error $(LOCAL_PATH): Invalid LOCAL_SDK_VERSION '$(LOCAL_SDK_VERSION)' \
26             Choices are: $(TARGET_AVAILABLE_SDK_VERSIONS))
27    else
28      ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),current)
29        # Use android_stubs_current if LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS.
30        LOCAL_JAVA_LIBRARIES := android_stubs_current $(LOCAL_JAVA_LIBRARIES)
31      else ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),system_current)
32        LOCAL_JAVA_LIBRARIES := android_system_stubs_current $(LOCAL_JAVA_LIBRARIES)
33      else
34        LOCAL_JAVA_LIBRARIES := sdk_v$(LOCAL_SDK_VERSION) $(LOCAL_JAVA_LIBRARIES)
35      endif
36    endif
37  endif
38else
39  ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
40    LOCAL_JAVA_LIBRARIES := $(TARGET_DEFAULT_JAVA_LIBRARIES) $(LOCAL_JAVA_LIBRARIES)
41  endif
42endif
43
44proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
45ifneq ($(proto_sources),)
46ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro)
47    ifneq ($(filter libprotobuf-java-2.3.0-micro,$(LOCAL_STATIC_JAVA_LIBRARIES)),)
48        $(warning Stripping unneeded dependency on libprotobuf-java-2.3.0-micro in $(LOCAL_MODULE))
49        LOCAL_STATIC_JAVA_LIBRARIES := $(filter-out libprotobuf-java-2.3.0-micro,$(LOCAL_STATIC_JAVA_LIBRARIES))
50    endif
51    LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-micro
52else
53  ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nano)
54    ifneq ($(filter libprotobuf-java-2.3.0-nano,$(LOCAL_STATIC_JAVA_LIBRARIES)),)
55        $(warning Stripping unneeded dependency on libprotobuf-java-2.3.0-nano in $(LOCAL_MODULE))
56        LOCAL_STATIC_JAVA_LIBRARIES := $(filter-out libprotobuf-java-2.3.0-nano,$(LOCAL_STATIC_JAVA_LIBRARIES))
57    endif
58    LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-nano
59  else
60    ifneq ($(filter libprotobuf-java-2.3.0-lite,$(LOCAL_STATIC_JAVA_LIBRARIES)),)
61        $(warning Stripping unneeded dependency on libprotobuf-java-2.3.0-lite in $(LOCAL_MODULE))
62        LOCAL_STATIC_JAVA_LIBRARIES := $(filter-out libprotobuf-java-2.3.0-lite,$(LOCAL_STATIC_JAVA_LIBRARIES))
63    endif
64    LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-lite
65  endif
66endif
67endif
68
69LOCAL_JAVA_LIBRARIES := $(sort $(LOCAL_JAVA_LIBRARIES))
70
71LOCAL_BUILT_MODULE_STEM := $(strip $(LOCAL_BUILT_MODULE_STEM))
72ifeq ($(LOCAL_BUILT_MODULE_STEM),)
73$(error $(LOCAL_PATH): Target java template must define LOCAL_BUILT_MODULE_STEM)
74endif
75ifneq ($(filter classes-compiled.jar classes.jar,$(LOCAL_BUILT_MODULE_STEM)),)
76$(error LOCAL_BUILT_MODULE_STEM may not be "$(LOCAL_BUILT_MODULE_STEM)")
77endif
78
79
80##############################################################################
81# Define the intermediate targets before including base_rules so they get
82# the correct environment.
83##############################################################################
84
85intermediates := $(call local-intermediates-dir)
86intermediates.COMMON := $(call local-intermediates-dir,COMMON)
87
88# Choose leaf name for the compiled jar file.
89ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
90full_classes_compiled_jar_leaf := classes-no-debug-var.jar
91built_dex_intermediate_leaf := no-local
92else
93full_classes_compiled_jar_leaf := classes-full-debug.jar
94built_dex_intermediate_leaf := with-local
95endif
96
97ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
98LOCAL_PROGUARD_ENABLED :=
99endif
100
101ifdef LOCAL_PROGUARD_ENABLED
102proguard_jar_leaf := proguard.classes.jar
103else
104proguard_jar_leaf := noproguard.classes.jar
105endif
106
107full_classes_compiled_jar := $(intermediates.COMMON)/$(full_classes_compiled_jar_leaf)
108jarjar_leaf := classes-jarjar.jar
109full_classes_jarjar_jar := $(intermediates.COMMON)/$(jarjar_leaf)
110emma_intermediates_dir := $(intermediates.COMMON)/emma_out
111# emma is hardcoded to use the leaf name of its input for the output file --
112# only the output directory can be changed
113full_classes_emma_jar := $(emma_intermediates_dir)/lib/$(jarjar_leaf)
114full_classes_proguard_jar := $(intermediates.COMMON)/$(proguard_jar_leaf)
115built_dex_intermediate := $(intermediates.COMMON)/$(built_dex_intermediate_leaf)/classes.dex
116full_classes_stubs_jar := $(intermediates.COMMON)/stubs.jar
117
118ifeq ($(LOCAL_MODULE_CLASS)$(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),APPS)
119# If this is an apk without any Java code (e.g. framework-res), we should skip compiling Java.
120full_classes_jar :=
121built_dex :=
122else
123full_classes_jar := $(intermediates.COMMON)/classes.jar
124built_dex := $(intermediates.COMMON)/classes.dex
125endif
126
127LOCAL_INTERMEDIATE_TARGETS += \
128    $(full_classes_compiled_jar) \
129    $(full_classes_jarjar_jar) \
130    $(full_classes_emma_jar) \
131    $(full_classes_jar) \
132    $(full_classes_proguard_jar) \
133    $(built_dex_intermediate) \
134    $(built_dex) \
135    $(full_classes_stubs_jar)
136
137
138LOCAL_INTERMEDIATE_SOURCE_DIR := $(intermediates.COMMON)/src
139
140###############################################################
141## .rs files: RenderScript sources to .java files and .bc files
142## .fs files: Filterscript sources to .java files and .bc files
143###############################################################
144renderscript_sources := $(filter %.rs %.fs,$(LOCAL_SRC_FILES))
145# Because names of the java files from RenderScript are unknown until the
146# .rs file(s) are compiled, we have to depend on a timestamp file.
147RenderScript_file_stamp :=
148rs_compatibility_jni_libs :=
149ifneq ($(renderscript_sources),)
150renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
151RenderScript_file_stamp := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/RenderScript.stamp
152renderscript_intermediate.COMMON := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/renderscript
153
154renderscript_target_api :=
155
156ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API))
157renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API)
158else
159ifneq (,$(LOCAL_SDK_VERSION))
160# Set target-api for LOCAL_SDK_VERSIONs other than current.
161ifneq (,$(filter-out current system_current, $(LOCAL_SDK_VERSION)))
162renderscript_target_api := $(LOCAL_SDK_VERSION)
163endif
164endif  # LOCAL_SDK_VERSION is set
165endif  # LOCAL_RENDERSCRIPT_TARGET_API is set
166
167ifeq ($(LOCAL_RENDERSCRIPT_CC),)
168LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC)
169endif
170
171# Turn on all warnings and warnings as errors for RS compiles.
172# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error
173renderscript_flags := -Wall -Werror
174renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS)
175
176# prepend the RenderScript system include path
177ifneq ($(filter-out current system_current,$(LOCAL_SDK_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current,$(LOCAL_SDK_VERSION))),)
178# if a numeric LOCAL_SDK_VERSION, or current LOCAL_SDK_VERSION with TARGET_BUILD_APPS
179LOCAL_RENDERSCRIPT_INCLUDES := \
180    $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/clang-include \
181    $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/include \
182    $(LOCAL_RENDERSCRIPT_INCLUDES)
183else
184LOCAL_RENDERSCRIPT_INCLUDES := \
185    $(TOPDIR)external/clang/lib/Headers \
186    $(TOPDIR)frameworks/rs/scriptc \
187    $(LOCAL_RENDERSCRIPT_INCLUDES)
188endif
189
190ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),)
191LOCAL_RENDERSCRIPT_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE)
192endif
193
194$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES)
195$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC)
196$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags)
197$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath)
198# By putting the generated java files into $(LOCAL_INTERMEDIATE_SOURCE_DIR), they will be
199# automatically found by the java compiling function transform-java-to-classes.jar.
200$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate.COMMON)
201$(RenderScript_file_stamp): PRIVATE_RS_TARGET_API := $(renderscript_target_api)
202$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC)
203	$(transform-renderscripts-to-java-and-bc)
204
205ifneq ($(LOCAL_RENDERSCRIPT_COMPATIBILITY),)
206bc_files := $(patsubst %.fs,%.bc, $(patsubst %.rs,%.bc, $(notdir $(renderscript_sources))))
207rs_generated_bc := $(addprefix \
208    $(renderscript_intermediate.COMMON)/res/raw/, $(bc_files))
209
210renderscript_intermediate := $(intermediates)/renderscript
211
212# We don't need the .so files in bundled branches
213# Prevent these from showing up on the device
214ifneq (,$(TARGET_BUILD_APPS)$(FORCE_BUILD_RS_COMPAT))
215
216rs_compatibility_jni_libs := $(addprefix \
217    $(renderscript_intermediate)/librs., \
218    $(patsubst %.bc,%.so, $(bc_files)))
219
220$(rs_generated_bc) : $(RenderScript_file_stamp)
221
222rs_support_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/libRSSupport.so
223rs_jni_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/librsjni.so
224LOCAL_JNI_SHARED_LIBRARIES += libRSSupport librsjni
225
226
227
228$(rs_compatibility_jni_libs): $(RenderScript_file_stamp) $(RS_PREBUILT_CLCORE) \
229    $(rs_support_lib) $(rs_jni_lib) $(rs_compiler_rt)
230$(rs_compatibility_jni_libs): $(BCC_COMPAT)
231$(rs_compatibility_jni_libs): PRIVATE_CXX := $(TARGET_CXX)
232$(rs_compatibility_jni_libs): $(renderscript_intermediate)/librs.%.so: \
233    $(renderscript_intermediate.COMMON)/res/raw/%.bc
234	$(transform-bc-to-so)
235
236endif
237
238endif
239
240# include the dependency files (.d) generated by llvm-rs-cc.
241renderscript_generated_dep_files := $(addprefix $(renderscript_intermediate.COMMON)/, \
242    $(patsubst %.fs,%.d, $(patsubst %.rs,%.d, $(notdir $(renderscript_sources)))))
243-include $(renderscript_generated_dep_files)
244
245LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
246# Make sure the generated resource will be added to the apk.
247LOCAL_RESOURCE_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/renderscript/res $(LOCAL_RESOURCE_DIR)
248endif
249
250# All of the rules after full_classes_compiled_jar are very unlikely
251# to fail except for bugs in their respective tools.  If you would
252# like to run these rules, add the "all" modifier goal to the make
253# command line.
254ifdef full_classes_jar
255java_alternative_checked_module := $(full_classes_compiled_jar)
256else
257java_alternative_checked_module :=
258endif
259
260# TODO: It looks like the only thing we need from base_rules is
261# all_java_sources.  See if we can get that by adding a
262# common_java.mk, and moving the include of base_rules.mk to
263# after all the declarations.
264
265#######################################
266include $(BUILD_SYSTEM)/base_rules.mk
267#######################################
268
269java_alternative_checked_module :=
270
271#######################################
272# defines built_odex along with rule to install odex
273include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
274#######################################
275
276# Make sure there's something to build.
277ifdef full_classes_jar
278ifndef need_compile_java
279$(error $(LOCAL_PATH): Target java module does not define any source or resource files)
280endif
281endif
282
283# Install the RS compatibility libraries to /system/lib/ if necessary
284ifdef rs_compatibility_jni_libs
285installed_rs_compatibility_jni_libs := $(addprefix $(TARGET_OUT_SHARED_LIBRARIES)/,\
286    $(notdir $(rs_compatibility_jni_libs)))
287# Provide a way to skip sources included in multiple projects.
288ifdef LOCAL_RENDERSCRIPT_SKIP_INSTALL
289skip_install_rs_libs := $(patsubst %.rs,%.so, \
290    $(addprefix $(TARGET_OUT_SHARED_LIBRARIES)/librs., \
291    $(notdir $(LOCAL_RENDERSCRIPT_SKIP_INSTALL))))
292installed_rs_compatibility_jni_libs := \
293    $(filter-out $(skip_install_rs_libs),$(installed_rs_compatibility_jni_libs))
294endif
295ifneq (,$(strip $(installed_rs_compatibility_jni_libs)))
296$(installed_rs_compatibility_jni_libs) : $(TARGET_OUT_SHARED_LIBRARIES)/lib%.so : \
297    $(renderscript_intermediate)/lib%.so
298	$(hide) mkdir -p $(dir $@) && cp -f $< $@
299
300# Install them only if the current module is installed.
301$(LOCAL_INSTALLED_MODULE) : $(installed_rs_compatibility_jni_libs)
302endif
303endif
304
305# We use intermediates.COMMON because the classes.jar/.dex files will be
306# common even if LOCAL_BUILT_MODULE isn't.
307#
308# Override some target variables that base_rules set up for us.
309$(LOCAL_INTERMEDIATE_TARGETS): \
310	PRIVATE_CLASS_INTERMEDIATES_DIR := $(intermediates.COMMON)/classes
311$(LOCAL_INTERMEDIATE_TARGETS): \
312	PRIVATE_SOURCE_INTERMEDIATES_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR)
313
314# Since we're using intermediates.COMMON, make sure that it gets cleaned
315# properly.
316$(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON)
317
318ifdef full_classes_jar
319
320# Droiddoc isn't currently able to generate stubs for modules, so we're just
321# allowing it to use the classes.jar as the "stubs" that would be use to link
322# against, for the cases where someone needs the jar to link against.
323# - Use the classes.jar instead of the handful of other intermediates that
324#   we have, because it's the most processed, but still hasn't had dex run on
325#   it, so it's closest to what's on the device.
326# - This extra copy, with the dependency on LOCAL_BUILT_MODULE allows the
327#   PRIVATE_ vars to be preserved.
328$(full_classes_stubs_jar): PRIVATE_SOURCE_FILE := $(full_classes_jar)
329$(full_classes_stubs_jar) : $(LOCAL_BUILT_MODULE) | $(ACP)
330	@echo Copying $(PRIVATE_SOURCE_FILE)
331	$(hide) $(ACP) -fp $(PRIVATE_SOURCE_FILE) $@
332ALL_MODULES.$(LOCAL_MODULE).STUBS := $(full_classes_stubs_jar)
333
334# The layers file allows you to enforce a layering between java packages.
335# Run build/tools/java-layers.py for more details.
336layers_file := $(addprefix $(LOCAL_PATH)/, $(LOCAL_JAVA_LAYERS_FILE))
337$(full_classes_compiled_jar): PRIVATE_JAVA_LAYERS_FILE := $(layers_file)
338$(full_classes_compiled_jar): PRIVATE_WARNINGS_ENABLE := $(LOCAL_WARNINGS_ENABLE)
339
340ifdef LOCAL_RMTYPEDEFS
341$(full_classes_compiled_jar): | $(RMTYPEDEFS)
342endif
343
344# Compile the java files to a .jar file.
345# This intentionally depends on java_sources, not all_java_sources.
346# Deps for generated source files must be handled separately,
347# via deps on the target that generates the sources.
348$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS)
349$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES := $(LOCAL_JAR_EXCLUDE_FILES)
350$(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES := $(LOCAL_JAR_PACKAGES)
351$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_PACKAGES := $(LOCAL_JAR_EXCLUDE_PACKAGES)
352$(full_classes_compiled_jar): PRIVATE_RMTYPEDEFS := $(LOCAL_RMTYPEDEFS)
353$(full_classes_compiled_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
354$(full_classes_compiled_jar): $(java_sources) $(java_resource_sources) $(full_java_lib_deps) \
355        $(jar_manifest_file) $(layers_file) $(RenderScript_file_stamp) \
356        $(proto_java_sources_file_stamp) $(LOCAL_ADDITIONAL_DEPENDENCIES)
357	$(transform-java-to-classes.jar)
358
359$(full_classes_compiled_jar): PRIVATE_JAVAC_DEBUG_FLAGS := -g
360
361# Run jarjar if necessary, otherwise just copy the file.
362ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
363$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
364$(full_classes_jarjar_jar): $(full_classes_compiled_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
365	@echo JarJar: $@
366	$(hide) java -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
367else
368$(full_classes_jarjar_jar): $(full_classes_compiled_jar) | $(ACP)
369	@echo Copying: $@
370	$(hide) $(ACP) -fp $< $@
371endif
372
373ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
374$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILE := $(intermediates.COMMON)/coverage.em
375$(full_classes_emma_jar): PRIVATE_EMMA_INTERMEDIATES_DIR := $(emma_intermediates_dir)
376# module level coverage filter can be defined using LOCAL_EMMA_COVERAGE_FILTER
377# in Android.mk
378ifdef LOCAL_EMMA_COVERAGE_FILTER
379$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := $(LOCAL_EMMA_COVERAGE_FILTER)
380else
381# by default, avoid applying emma instrumentation onto emma classes itself,
382# otherwise there will be exceptions thrown
383$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := *,-emma,-emmarun,-com.vladium.*
384endif
385# this rule will generate both $(PRIVATE_EMMA_COVERAGE_FILE) and
386# $(full_classes_emma_jar)
387$(full_classes_emma_jar): $(full_classes_jarjar_jar) | $(EMMA_JAR)
388	$(transform-classes.jar-to-emma)
389
390else
391$(full_classes_emma_jar): $(full_classes_jarjar_jar) | $(ACP)
392	@echo Copying: $@
393	$(copy-file-to-target)
394endif
395
396# Keep a copy of the jar just before proguard processing.
397$(full_classes_jar): $(full_classes_emma_jar) | $(ACP)
398	@echo Copying: $@
399	$(hide) $(ACP) -fp $< $@
400
401# Run proguard if necessary, otherwise just copy the file.
402ifdef LOCAL_PROGUARD_ENABLED
403ifneq ($(filter-out full custom nosystem obfuscation optimization shrinktests,$(LOCAL_PROGUARD_ENABLED)),)
404    $(warning while processing: $(LOCAL_MODULE))
405    $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED))
406endif
407proguard_dictionary := $(intermediates.COMMON)/proguard_dictionary
408proguard_flags := $(addprefix -libraryjars ,$(full_shared_java_libs)) \
409                  -forceprocessing \
410                  -printmapping $(proguard_dictionary)
411
412ifeq ($(filter nosystem,$(LOCAL_PROGUARD_ENABLED)),)
413proguard_flags += -include $(BUILD_SYSTEM)/proguard.flags
414ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
415proguard_flags += -include $(BUILD_SYSTEM)/proguard.emma.flags
416endif
417# If this is a test package, add proguard keep flags for tests.
418ifneq ($(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS)),)
419proguard_flags += -include $(BUILD_SYSTEM)/proguard_tests.flags
420ifeq ($(filter shrinktests,$(LOCAL_PROGUARD_ENABLED)),)
421proguard_flags += -dontshrink # don't shrink tests by default
422endif # shrinktests
423endif # test package
424ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
425# By default no obfuscation
426proguard_flags += -dontobfuscate
427endif  # No obfuscation
428ifeq ($(filter optimization,$(LOCAL_PROGUARD_ENABLED)),)
429# By default no optimization
430proguard_flags += -dontoptimize
431endif  # No optimization
432
433ifdef LOCAL_INSTRUMENTATION_FOR
434ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
435# If no obfuscation, link in the instrmented package's classes.jar as a library.
436# link_instr_classes_jar is defined in base_rule.mk
437proguard_flags += -libraryjars $(link_instr_classes_jar)
438else # obfuscation
439# If obfuscation is enabled, the main app must be obfuscated too.
440# We need to run obfuscation using the main app's dictionary,
441# and treat the main app's class.jar as injars instead of libraryjars.
442proguard_flags := -injars  $(link_instr_classes_jar) \
443    -outjars $(intermediates.COMMON)/proguard.$(LOCAL_INSTRUMENTATION_FOR).jar \
444    -include $(link_instr_intermediates_dir.COMMON)/proguard_options \
445    -applymapping $(link_instr_intermediates_dir.COMMON)/proguard_dictionary \
446    -verbose \
447    $(proguard_flags)
448
449# Sometimes (test + main app) uses different keep rules from the main app -
450# apply the main app's dictionary anyway.
451proguard_flags += -ignorewarnings
452
453# Make sure we run Proguard on the main app first
454$(full_classes_proguard_jar) : $(link_instr_intermediates_dir.COMMON)/proguard.classes.jar
455
456endif # no obfuscation
457endif # LOCAL_INSTRUMENTATION_FOR
458endif  # LOCAL_PROGUARD_ENABLED is not nosystem
459
460proguard_flag_files := $(addprefix $(LOCAL_PATH)/, $(LOCAL_PROGUARD_FLAG_FILES))
461LOCAL_PROGUARD_FLAGS += $(addprefix -include , $(proguard_flag_files))
462
463ifdef LOCAL_TEST_MODULE_TO_PROGUARD_WITH
464extra_input_jar := $(call intermediates-dir-for,APPS,$(LOCAL_TEST_MODULE_TO_PROGUARD_WITH),,COMMON)/classes.jar
465else
466extra_input_jar :=
467endif
468$(full_classes_proguard_jar): PRIVATE_EXTRA_INPUT_JAR := $(extra_input_jar)
469$(full_classes_proguard_jar): PRIVATE_PROGUARD_FLAGS := $(proguard_flags) $(LOCAL_PROGUARD_FLAGS)
470$(full_classes_proguard_jar) : $(full_classes_jar) $(extra_input_jar) $(proguard_flag_files) | $(ACP) $(PROGUARD)
471	$(call transform-jar-to-proguard)
472
473else  # LOCAL_PROGUARD_ENABLED not defined
474$(full_classes_proguard_jar) : $(full_classes_jar)
475	@echo Copying: $@
476	$(hide) $(ACP) -fp $< $@
477
478endif # LOCAL_PROGUARD_ENABLED defined
479
480
481# Override PRIVATE_INTERMEDIATES_DIR so that install-dex-debug
482# will work even when intermediates != intermediates.COMMON.
483$(built_dex_intermediate): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON)
484$(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
485# If you instrument class files that have local variable debug information in
486# them emma does not correctly maintain the local variable table.
487# This will cause an error when you try to convert the class files for Android.
488# The workaround here is to build different dex file here based on emma switch
489# then later copy into classes.dex. When emma is on, dx is run with --no-locals
490# option to remove local variable information
491ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
492$(built_dex_intermediate): PRIVATE_DX_FLAGS += --no-locals
493endif
494$(built_dex_intermediate): $(full_classes_proguard_jar) $(DX)
495	$(transform-classes.jar-to-dex)
496$(built_dex): $(built_dex_intermediate) | $(ACP)
497	@echo Copying: $@
498	$(hide) mkdir -p $(dir $@)
499	$(hide) rm -f $(dir $@)/classes*.dex
500	$(hide) $(ACP) -fp $(dir $<)/classes*.dex $(dir $@)
501ifneq ($(GENERATE_DEX_DEBUG),)
502	$(install-dex-debug)
503endif
504
505findbugs_xml := $(intermediates.COMMON)/findbugs.xml
506$(findbugs_xml) : PRIVATE_JAR_FILE := $(full_classes_jar)
507$(findbugs_xml) : PRIVATE_AUXCLASSPATH := $(addprefix -auxclasspath ,$(strip \
508								$(call normalize-path-list,$(filter %.jar,\
509										$(full_java_libs)))))
510# We can't depend directly on full_classes_jar because the PRIVATE_
511# vars won't be set up correctly.
512$(findbugs_xml) : $(LOCAL_BUILT_MODULE)
513	@echo Findbugs: $@
514	$(hide) $(FINDBUGS) -textui -effort:min -xml:withMessages \
515		$(PRIVATE_AUXCLASSPATH) \
516		$(PRIVATE_JAR_FILE) \
517		> $@
518
519ALL_FINDBUGS_FILES += $(findbugs_xml)
520
521findbugs_html := $(PRODUCT_OUT)/findbugs/$(LOCAL_MODULE).html
522$(findbugs_html) : PRIVATE_XML_FILE := $(findbugs_xml)
523$(LOCAL_MODULE)-findbugs : $(findbugs_html)
524$(findbugs_html) : $(findbugs_xml)
525	@mkdir -p $(dir $@)
526	@echo ConvertXmlToText: $@
527	$(hide) $(FINDBUGS_DIR)/convertXmlToText -html:fancy.xsl $(PRIVATE_XML_FILE) \
528	> $@
529
530$(LOCAL_MODULE)-findbugs : $(findbugs_html)
531
532endif  # full_classes_jar is defined
533