Merge "Added support for using R8 instead of Proguard + dx"

This commit is contained in:
Søren Gjesse 2017-10-24 06:39:09 +00:00 committed by Gerrit Code Review
commit 9047dce212
4 changed files with 46 additions and 1 deletions

View file

@ -200,6 +200,7 @@ LOCAL_PROTOC_FLAGS:=
# lite(default),micro,nano,stream,full,nanopb-c,nanopb-c-enable_malloc
LOCAL_PROTOC_OPTIMIZE_TYPE:=
LOCAL_PROTO_JAVA_OUTPUT_PARAMS:=
LOCAL_R8_FLAG_FILES:=
LOCAL_RECORDED_MODULE_TYPE:=
LOCAL_RENDERSCRIPT_CC:=
LOCAL_RENDERSCRIPT_COMPATIBILITY:=

View file

@ -523,6 +523,7 @@ ifeq (,$(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK)))
SIGNAPK_JAR := $(HOST_OUT_JAVA_LIBRARIES)/signapk$(COMMON_JAVA_PACKAGE_SUFFIX)
SIGNAPK_JNI_LIBRARY_PATH := $(HOST_OUT_SHARED_LIBRARIES)
ZIPALIGN := $(HOST_OUT_EXECUTABLES)/zipalign
R8 := $(HOST_OUT_EXECUTABLES)/r8
else # TARGET_BUILD_APPS || TARGET_BUILD_PDK
AIDL := $(prebuilt_sdk_tools_bin)/aidl
@ -533,7 +534,7 @@ else # TARGET_BUILD_APPS || TARGET_BUILD_PDK
SIGNAPK_JAR := $(prebuilt_sdk_tools)/lib/signapk$(COMMON_JAVA_PACKAGE_SUFFIX)
SIGNAPK_JNI_LIBRARY_PATH := $(prebuilt_sdk_tools)/$(HOST_OS)/lib64
ZIPALIGN := $(prebuilt_sdk_tools_bin)/zipalign
R8 := $(prebuilt_build_tools_wrappers)/r8
endif # TARGET_BUILD_APPS || TARGET_BUILD_PDK
ifeq (,$(TARGET_BUILD_APPS))

View file

@ -2787,6 +2787,19 @@ $(hide) $(PROGUARD) -injars '$<$(PRIVATE_PROGUARD_INJAR_FILTERS)' \
$(addprefix -injars , $(PRIVATE_EXTRA_INPUT_JAR))
endef
###########################################################
## Commands to call R8
###########################################################
define transform-jar-to-dex-r8
@echo R8: $@
$(hide) $(R8) -injars '$<$(PRIVATE_PROGUARD_INJAR_FILTERS)' \
--min-api $(PRIVATE_MIN_SDK_VERSION) \
--force-proguard-compatibility --output $(subst classes.dex,,$@) \
$(PRIVATE_PROGUARD_FLAGS) \
$(addprefix -injars , $(PRIVATE_EXTRA_INPUT_JAR)) \
$(PRIVATE_DX_FLAGS)
endef
###########################################################
## Stuff source generated from one-off tools
###########################################################

View file

@ -694,6 +694,9 @@ endif # LOCAL_INSTRUMENTATION_FOR
endif # LOCAL_PROGUARD_ENABLED is not nosystem
proguard_flag_files := $(addprefix $(LOCAL_PATH)/, $(LOCAL_PROGUARD_FLAG_FILES))
ifeq ($(USE_R8),true)
proguard_flag_files += $(addprefix $(LOCAL_PATH)/, $(LOCAL_R8_FLAG_FILES))
endif # USE_R8
LOCAL_PROGUARD_FLAGS += $(addprefix -include , $(proguard_flag_files))
ifdef LOCAL_TEST_MODULE_TO_PROGUARD_WITH
@ -718,11 +721,20 @@ endif
ifneq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
$(full_classes_proguard_jar): .KATI_IMPLICIT_OUTPUTS := $(proguard_dictionary)
endif
# If R8 is not enabled run Proguard.
ifneq ($(USE_R8),true)
# Changes to these dependencies need to be replicated below when using R8
# instead of Proguard + dx.
$(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_pre_proguard_jar) $(extra_input_jar) $(my_support_library_sdk_raise) $(common_proguard_flag_files) $(proguard_flag_files) $(legacy_proguard_lib_deps) | $(PROGUARD)
$(call transform-jar-to-proguard)
else # !USE_R8
# Running R8 instead of Proguard, proguarded jar is actually the pre-Proguarded jar.
full_classes_proguard_jar := $(full_classes_pre_proguard_jar)
endif # !USE_R8
else # LOCAL_PROGUARD_ENABLED not defined
full_classes_proguard_jar := $(full_classes_pre_proguard_jar)
@ -739,8 +751,26 @@ $(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
$(built_dex_intermediate): PRIVATE_DX_FLAGS += --no-locals
endif
my_r8 :=
ifdef LOCAL_PROGUARD_ENABLED
ifeq ($(USE_R8),true)
# These are the dependencies for the proguarded jar when running
# Proguard + dx. They are used for the generated dex when using R8, as
# R8 does Proguard + dx
my_r8 := true
$(built_dex_intermediate): PRIVATE_PROGUARD_INJAR_FILTERS := $(proguard_injar_filters)
$(built_dex_intermediate): PRIVATE_EXTRA_INPUT_JAR := $(extra_input_jar)
$(built_dex_intermediate): PRIVATE_PROGUARD_FLAGS := $(legacy_proguard_flags) $(common_proguard_flags) $(LOCAL_PROGUARD_FLAGS)
$(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)
$(transform-jar-to-dex-r8)
endif # USE_R8
endif # LOCAL_PROGUARD_ENABLED
ifndef my_r8
$(built_dex_intermediate): $(full_classes_proguard_jar) $(DX)
$(transform-classes.jar-to-dex)
endif
$(built_dex): $(built_dex_intermediate)
@echo Copying: $@