Move proguard before classes.jar

Downstream users of a library always link against javalib.jar, which
is either the dex jar for java libraries or a copy of
proguard.classes.jar for static java libraries.  In preparation for
making java libraries a superset of static java libraries, make
classes.jar always be the final class-containing jar for use
downstream, and always create a classes-pre-proguard.jar for
users that need a jar without shrinking or obfuscation.

Also rename the intermediates to be consitent: classes-<tool>.jar

Test: m -j ANDROID_COMPILE_WITH_JACK=false java
Change-Id: I3df8b9a4edcd5db996f1fedc54c8a782d4f36a92
This commit is contained in:
Colin Cross 2017-03-29 12:58:15 -07:00
parent aac5674015
commit 6fabefa88e
7 changed files with 23 additions and 19 deletions

View file

@ -36,7 +36,7 @@ ifneq ($(full_classes_jar),)
$(built_dpi_apk): PRIVATE_DEX_FILE := $(built_dex)
ifndef LOCAL_JACK_ENABLED
# Use the jarjar processed arhive as the initial package file.
$(built_dpi_apk): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar)
$(built_dpi_apk): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar)
else
$(built_dpi_apk): PRIVATE_JACK_INTERMEDIATES_DIR := $(intermediates.COMMON)/jack-rsc
endif # LOCAL_JACK_ENABLED

View file

@ -114,14 +114,14 @@ LOCAL_PROGUARD_ENABLED :=
endif
full_classes_compiled_jar := $(intermediates.COMMON)/$(full_classes_compiled_jar_leaf)
full_classes_desugar_jar := $(intermediates.COMMON)/desugar.classes.jar
full_classes_desugar_jar := $(intermediates.COMMON)/classes-desugar.jar
jarjar_leaf := classes-jarjar.jar
full_classes_jarjar_jar := $(intermediates.COMMON)/$(jarjar_leaf)
emma_intermediates_dir := $(intermediates.COMMON)/emma_out
# emma is hardcoded to use the leaf name of its input for the output file --
# only the output directory can be changed
full_classes_emma_jar := $(emma_intermediates_dir)/lib/$(jarjar_leaf)
full_classes_proguard_jar := $(intermediates.COMMON)/proguard.classes.jar
full_classes_proguard_jar := $(intermediates.COMMON)/classes-proguard.jar
built_dex_intermediate := $(intermediates.COMMON)/$(built_dex_intermediate_leaf)/classes.dex
full_classes_stubs_jar := $(intermediates.COMMON)/stubs.jar
@ -493,11 +493,11 @@ else
full_classes_emma_jar := $(full_classes_jarjar_jar)
endif
# Keep a copy of the jar just before proguard processing.
# TODO: this should depend on full_classes_emma_jar once coverage works again
$(eval $(call copy-one-file,$(full_classes_jarjar_jar),$(full_classes_jar)))
full_classes_pre_proguard_jar := $(full_classes_jarjar_jar)
$(call define-jar-to-toc-rule, $(full_classes_jar))
# Keep a copy of the jar just before proguard processing.
$(eval $(call copy-one-file,$(full_classes_pre_proguard_jar),$(intermediates.COMMON)/classes-pre-proguard.jar))
# Run proguard if necessary
ifdef LOCAL_PROGUARD_ENABLED
@ -628,13 +628,17 @@ endif
$(full_classes_proguard_jar): PRIVATE_PROGUARD_INJAR_FILTERS := $(proguard_injar_filters)
$(full_classes_proguard_jar): PRIVATE_EXTRA_INPUT_JAR := $(extra_input_jar)
$(full_classes_proguard_jar): PRIVATE_PROGUARD_FLAGS := $(legacy_proguard_flags) $(common_proguard_flags) $(LOCAL_PROGUARD_FLAGS)
$(full_classes_proguard_jar) : $(full_classes_jar) $(extra_input_jar) $(my_support_library_sdk_raise) $(common_proguard_flag_files) $(proguard_flag_files) | $(PROGUARD)
$(full_classes_proguard_jar) : $(full_classes_pre_proguard_jar) $(extra_input_jar) $(my_support_library_sdk_raise) $(common_proguard_flag_files) $(proguard_flag_files) | $(PROGUARD)
$(call transform-jar-to-proguard)
else # LOCAL_PROGUARD_ENABLED not defined
full_classes_proguard_jar := $(full_classes_jar)
full_classes_proguard_jar := $(full_classes_pre_proguard_jar)
endif # LOCAL_PROGUARD_ENABLED defined
$(eval $(call copy-one-file,$(full_classes_proguard_jar),$(full_classes_jar)))
$(call define-jar-to-toc-rule, $(full_classes_jar))
ifndef LOCAL_JACK_ENABLED
$(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
# If you instrument class files that have local variable debug information in
@ -660,7 +664,7 @@ findbugs_xml := $(intermediates.COMMON)/findbugs.xml
$(findbugs_xml): PRIVATE_AUXCLASSPATH := $(addprefix -auxclasspath ,$(strip \
$(call normalize-path-list,$(filter %.jar,$(full_java_libs)))))
$(findbugs_xml): PRIVATE_FINDBUGS_FLAGS := $(LOCAL_FINDBUGS_FLAGS)
$(findbugs_xml) : $(full_classes_jar) $(filter %.xml, $(LOCAL_FINDBUGS_FLAGS))
$(findbugs_xml) : $(full_classes_pre_proguard_jar) $(filter %.xml, $(LOCAL_FINDBUGS_FLAGS))
@echo Findbugs: $@
$(hide) $(FINDBUGS) -textui -effort:min -xml:withMessages \
$(PRIVATE_AUXCLASSPATH) $(PRIVATE_FINDBUGS_FLAGS) \

View file

@ -247,7 +247,7 @@ ifneq ($(apk_libraries),)
link_apk_libraries := \
$(foreach lib,$(apk_libraries), \
$(call intermediates-dir-for, \
APPS,$(lib),,COMMON)/classes.jar)
APPS,$(lib),,COMMON)/classes-pre-proguard.jar)
# link against the jar with full original names (before proguard processing).
full_shared_java_libs += $(link_apk_libraries)
@ -268,7 +268,7 @@ ifdef LOCAL_INSTRUMENTATION_FOR
link_instr_intermediates_dir.COMMON := $(call intermediates-dir-for, \
APPS,$(LOCAL_INSTRUMENTATION_FOR),,COMMON)
# link against the jar with full original names (before proguard processing).
link_instr_classes_jar := $(link_instr_intermediates_dir.COMMON)/classes.jar
link_instr_classes_jar := $(link_instr_intermediates_dir.COMMON)/classes-pre-proguard.jar
full_java_libs += $(link_instr_classes_jar)
full_java_lib_deps += $(link_instr_classes_jar)
endif # LOCAL_INSTRUMENTATION_FOR

View file

@ -67,11 +67,7 @@ include $(BUILD_SYSTEM)/java.mk
ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
# No dex; all we want are the .class files with resources.
$(common_javalib.jar) : $(java_resource_sources)
ifdef LOCAL_PROGUARD_ENABLED
$(common_javalib.jar) : $(full_classes_proguard_jar)
else
$(common_javalib.jar) : $(full_classes_jar)
endif
@echo "target Static Jar: $(PRIVATE_MODULE) ($@)"
$(copy-file-to-target)
@ -85,7 +81,7 @@ endif
else # !LOCAL_IS_STATIC_JAVA_LIBRARY
$(common_javalib.jar): PRIVATE_DEX_FILE := $(built_dex)
$(common_javalib.jar): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar)
$(common_javalib.jar): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar)
$(common_javalib.jar): PRIVATE_DONT_DELETE_JAR_DIRS := $(LOCAL_DONT_DELETE_JAR_DIRS)
$(common_javalib.jar) : $(built_dex) $(java_resource_sources) | $(ZIPTIME)
@echo "target Jar: $(PRIVATE_MODULE) ($@)"

View file

@ -497,7 +497,7 @@ endif # LOCAL_NO_STANDARD_LIBRARIES
ifneq ($(full_classes_jar),)
$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
# Use the jarjar processed arhive as the initial package file.
$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar)
$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar)
$(LOCAL_BUILT_MODULE): $(built_dex)
else
$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE :=

View file

@ -429,6 +429,7 @@ ifeq ($(LOCAL_IS_HOST_MODULE),)
# for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir,
# while the deps should be in the common dir, so we make a copy in the common dir.
common_classes_jar := $(intermediates.COMMON)/classes.jar
common_classes_pre_proguard_jar := $(intermediates.COMMON)/classes-pre-proguard.jar
common_javalib_jar := $(intermediates.COMMON)/javalib.jar
$(common_classes_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE)
@ -471,6 +472,9 @@ endif
$(common_classes_jar) : $(my_src_jar)
$(transform-prebuilt-to-target)
$(common_classes_pre_proguard_jar) : $(my_src_jar)
$(transform-prebuilt-to-target)
$(common_javalib_jar) : $(common_classes_jar)
$(transform-prebuilt-to-target)

View file

@ -171,9 +171,9 @@ $(full_classes_compiled_jar): $(R_file_stamp)
# if we have custom proguarding done use the proguarded classes jar instead of the normal classes jar
ifeq ($(filter custom,$(LOCAL_PROGUARD_ENABLED)),custom)
aar_classes_jar = $(full_classes_proguard_jar)
else
aar_classes_jar = $(full_classes_jar)
else
aar_classes_jar = $(full_classes_pre_proguard_jar)
endif
# Rule to build AAR, archive including classes.jar, resource, etc.