endif # EMMA_INSTRUMENT=true
+#------------------------------------------------------------------
+# A zip of Proguard obfuscation dictionary files.
+# Only for apps_only build.
+#
+ifdef TARGET_BUILD_APPS
+PROGUARD_DICT_ZIP := $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-dict-$(FILE_NAME_TAG).zip
+# the dependency will be set up later in build/core/main.mk.
+$(PROGUARD_DICT_ZIP) :
+ @echo "Packaging Proguard obfuscation dictionary files."
+ $(hide) dict_files=`find $(TARGET_OUT_COMMON_INTERMEDIATES)/APPS -name proguard_dictionary`; \
+ if [ -n "$$dict_files" ]; then \
+ zip -q $@ $$dict_files; \
+ else \
+ touch $(dir $@)/dummy; \
+ (cd $(dir $@) && zip -q $(notdir $@) dummy); \
+ zip -qd $@ dummy; \
+ rm $(dir $@)/dummy; \
+ fi
+
+endif # TARGET_BUILD_APPS
+
# -----------------------------------------------------------------
# dalvik something
.PHONY: dalvikfiles
ifeq ($(LOCAL_BUILD_HOST_DEX),true)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := -bootclasspath $(call java-lib-files,core-hostdex,$(LOCAL_IS_HOST_MODULE))
-full_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
+full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
full_java_lib_deps := $(call java-lib-deps,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
else
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH :=
-full_java_libs := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/,$(addsuffix $(COMMON_JAVA_PACKAGE_SUFFIX),$(LOCAL_JAVA_LIBRARIES)))
-full_java_lib_deps := $(full_java_libs)
+full_shared_java_libs := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/,\
+ $(addsuffix $(COMMON_JAVA_PACKAGE_SUFFIX),$(LOCAL_JAVA_LIBRARIES)))
+full_java_lib_deps := $(full_shared_java_libs)
endif # LOCAL_BUILD_HOST_DEX
else
-full_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
+full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
full_java_lib_deps := $(call java-lib-deps,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
endif # !LOCAL_IS_HOST_MODULE
-full_java_libs += $(full_static_java_libs) $(LOCAL_CLASSPATH)
+full_java_libs := $(full_shared_java_libs) $(full_static_java_libs) $(LOCAL_CLASSPATH)
full_java_lib_deps += $(full_static_java_libs) $(LOCAL_CLASSPATH)
# This is set by packages that are linking to other packages that export
APPS,$(lib),,COMMON)/classes.jar)
# link against the jar with full original names (before proguard processing).
+ full_shared_java_libs += $(link_apk_libraries)
full_java_libs += $(link_apk_libraries)
full_java_lib_deps += $(link_apk_libraries)
endif
$(LOCAL_PATH): Multiple LOCAL_INSTRUMENTATION_FOR members defined)
endif
- link_instr_intermediates_dir := $(call intermediates-dir-for, \
- APPS,$(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).
- full_java_libs += $(link_instr_intermediates_dir.COMMON)/classes.jar
- full_java_lib_deps += $(link_instr_intermediates_dir.COMMON)/classes.jar
+ link_instr_classes_jar := $(link_instr_intermediates_dir.COMMON)/classes.jar
+ full_java_libs += $(link_instr_classes_jar)
+ full_java_lib_deps += $(link_instr_classes_jar)
endif
jar_manifest_file :=
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAR_MANIFEST :=
endif
-endif
+endif # PRIVATE java vars
###########################################################
ifdef LOCAL_SDK_VERSION
my_target_project_includes :=
my_target_c_includes := $(my_ndk_stl_include_path) $(my_ndk_version_root)/usr/include
-
-# filter out including of AndroidConfig.h in system/core.
-TARGET_GLOBAL_CFLAGS_NO_ANDCONF ?= $(subst $(TARGET_ANDROID_CONFIG_CFLAGS),,\
- $(TARGET_GLOBAL_CFLAGS))
-my_target_global_cflags := $(TARGET_GLOBAL_CFLAGS_NO_ANDCONF)
else
my_target_project_includes := $(TARGET_PROJECT_INCLUDES)
my_target_c_includes := $(TARGET_C_INCLUDES)
-ifeq ($(strip $(LOCAL_CLANG)),true)
-my_target_c_includes += $(CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES)
+endif # LOCAL_SDK_VERSION
+
+ifeq ($(LOCAL_CLANG),true)
my_target_global_cflags := $(TARGET_GLOBAL_CLANG_FLAGS)
+my_target_c_includes += $(CLANG_CONFIG_EXTRA_TARGET_C_INCLUDES)
else
my_target_global_cflags := $(TARGET_GLOBAL_CFLAGS)
endif # LOCAL_CLANG
-endif # LOCAL_SDK_VERSION
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_PROJECT_INCLUDES := $(my_target_project_includes)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_C_INCLUDES := $(my_target_c_includes)
LOCAL_SDK_RES_VERSION:=
LOCAL_NDK_STL_VARIANT:=
LOCAL_EMMA_INSTRUMENT:=
-LOCAL_PROGUARD_ENABLED:= # '',full,custom,nosystem,disabled
+LOCAL_PROGUARD_ENABLED:= # '',full,custom,nosystem,disabled,obfuscation,optimization
LOCAL_PROGUARD_FLAGS:=
LOCAL_PROGUARD_FLAG_FILES:=
LOCAL_EMMA_COVERAGE_FILTER:=
TARGET_thumb_CFLAGS += -marm -fno-omit-frame-pointer
endif
+android_config_h := $(call select-android-config-h,linux-arm)
+
TARGET_GLOBAL_CFLAGS += \
-msoft-float -fpic -fPIE \
-ffunction-sections \
-Werror=format-security \
-D_FORTIFY_SOURCE=1 \
-fno-short-enums \
- $(arch_variant_cflags)
-
-android_config_h := $(call select-android-config-h,linux-arm)
-TARGET_ANDROID_CONFIG_CFLAGS := -include $(android_config_h) -I $(dir $(android_config_h))
-TARGET_GLOBAL_CFLAGS += $(TARGET_ANDROID_CONFIG_CFLAGS)
+ $(arch_variant_cflags) \
+ -include $(android_config_h) \
+ -I $(dir $(android_config_h))
# This warning causes dalvik not to build with gcc 4.6+ and -Werror.
# We cannot turn it off blindly since the option is not available
TARGET_mips_CFLAGS += -fno-omit-frame-pointer
endif
+android_config_h := $(call select-android-config-h,linux-mips)
+
TARGET_GLOBAL_CFLAGS += \
$(TARGET_mips_CFLAGS) \
-Ulinux -U__unix -U__unix__ -Umips \
-Wa,--noexecstack \
-Werror=format-security \
-D_FORTIFY_SOURCE=1 \
- $(arch_variant_cflags)
-
-android_config_h := $(call select-android-config-h,linux-mips)
-TARGET_ANDROID_CONFIG_CFLAGS := -include $(android_config_h) -I $(dir $(android_config_h))
-TARGET_GLOBAL_CFLAGS += $(TARGET_ANDROID_CONFIG_CFLAGS)
+ $(arch_variant_cflags) \
+ -include $(android_config_h) \
+ -I $(dir $(android_config_h))
# This warning causes dalvik not to build with gcc 4.6+ and -Werror.
# We cannot turn it off blindly since the option is not available
endif
KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)
+android_config_h := $(call select-android-config-h,target_linux-x86)
+
TARGET_GLOBAL_CFLAGS += \
-O2 \
-Ulinux \
-fstrict-aliasing \
-funswitch-loops \
-funwind-tables \
- -fstack-protector
-
-android_config_h := $(call select-android-config-h,target_linux-x86)
-TARGET_ANDROID_CONFIG_CFLAGS := -include $(android_config_h) -I $(dir $(android_config_h))
-TARGET_GLOBAL_CFLAGS += $(TARGET_ANDROID_CONFIG_CFLAGS)
+ -fstack-protector \
+ -include $(android_config_h) \
+ -I $(dir $(android_config_h))
# XXX: Not sure this is still needed. Must check with our toolchains.
TARGET_GLOBAL_CPPFLAGS += \
endef
###########################################################
-## Obfuscate a jar file
-###########################################################
-
-# PRIVATE_KEEP_FILE is a file containing a list of classes
-# PRIVATE_INTERMEDIATES_DIR is a directory we can use for temporary files
-# The module using this must depend on
-# $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar
-define obfuscate-jar
-@echo "Obfuscate jar: $(notdir $@) ($@)"
-@mkdir -p $(dir $@)
-@rm -f $@
-@mkdir -p $(PRIVATE_INTERMEDIATES_DIR)
-$(hide) sed -e 's/^/-keep class /' < $(PRIVATE_KEEP_FILE) > \
- $(PRIVATE_INTERMEDIATES_DIR)/keep.pro
-$(hide) java -Xmx512M -jar $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar \
- -injars $< \
- -outjars $@ \
- -target 1.5 \
- -dontnote -dontwarn \
- -printmapping $(PRIVATE_INTERMEDIATES_DIR)/out.map \
- -forceprocessing \
- -renamesourcefileattribute SourceFile \
- -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod \
- -repackageclasses \
- -keepclassmembers "class * { public protected *; }" \
- @$(PRIVATE_INTERMEDIATES_DIR)/keep.pro
-endef
-
-###########################################################
## Commands for copying files
###########################################################
###########################################################
## Commands to call Proguard
###########################################################
-
-# Command to copy the file with acp, if proguard is disabled.
-define proguard-disabled-commands
-@echo Copying: $@
-$(hide) $(ACP) -fp $< $@
-endef
-
-# Command to call Proguard
-# $(1): extra flags for instrumentation.
-define proguard-enabled-commands
-@echo Proguard: $@
-$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS) $(1)
-endef
-
-# Figure out the proguard dictionary file of the module that is instrumentationed for.
-define get-instrumentation-proguard-flags
-$(if $(PRIVATE_INSTRUMENTATION_FOR),$(if $(ALL_MODULES.$(PRIVATE_INSTRUMENTATION_FOR).PROGUARD_ENABLED),-applymapping $(call intermediates-dir-for,APPS,$(PRIVATE_INSTRUMENTATION_FOR),,COMMON)/proguard_dictionary))
-endef
-
define transform-jar-to-proguard
-$(eval _instrumentation_proguard_flags:=$(call get-instrumentation-proguard-flags))
-$(eval _enable_proguard:=$(PRIVATE_PROGUARD_ENABLED)$(_instrumentation_proguard_flags))
-$(if $(_enable_proguard),$(call proguard-enabled-commands,$(_instrumentation_proguard_flags)),$(call proguard-disabled-commands))
-$(eval _instrumentation_proguard_flags:=)
-$(eval _enable_proguard:=)
+@echo Proguard: $@
+$(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS)
endef
-
###########################################################
## Stuff source generated from one-off tools
###########################################################
###########################################################
## Define device-specific radio files
###########################################################
+INSTALLED_RADIOIMAGE_TARGET :=
# Copy a radio image file to the output location, and add it to
# INSTALLED_RADIOIMAGE_TARGET.
built_dex_intermediate_leaf := classes-with-local.dex
endif
-LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED))
ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
LOCAL_PROGUARD_ENABLED :=
endif
$(hide) $(ACP) -fp $< $@
# Run proguard if necessary, otherwise just copy the file.
+ifdef LOCAL_PROGUARD_ENABLED
+ifneq ($(filter-out full custom nosystem obfuscation optimization,$(LOCAL_PROGUARD_ENABLED)),)
+ $(warning while processing: $(LOCAL_MODULE))
+ $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED))
+endif
proguard_dictionary := $(intermediates.COMMON)/proguard_dictionary
-# Proguard doesn't like a class in both library and the jar to be processed.
-proguard_full_java_libs := $(filter-out $(full_static_java_libs),$(full_java_libs))
-proguard_flags := $(addprefix -libraryjars ,$(proguard_full_java_libs)) \
+proguard_flags := $(addprefix -libraryjars ,$(full_shared_java_libs)) \
-forceprocessing \
-printmapping $(proguard_dictionary)
-ifneq ($(LOCAL_PROGUARD_ENABLED),nosystem)
+
+ifeq ($(filter nosystem,$(LOCAL_PROGUARD_ENABLED)),)
proguard_flags += -include $(BUILD_SYSTEM)/proguard.flags
ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
proguard_flags += -include $(BUILD_SYSTEM)/proguard.emma.flags
endif
# If this is a test package, add proguard keep flags for tests.
-ifneq ($(strip $(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS))$(filter android.test.runner,$(LOCAL_JAVA_LIBRARIES))),)
-proguard_flags := $(proguard_flags) -include $(BUILD_SYSTEM)/proguard_tests.flags
+ifneq ($(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS)),)
+proguard_flags += -include $(BUILD_SYSTEM)/proguard_tests.flags
endif # test package
-else # LOCAL_PROGUARD_ENABLED is nosystem
-proguard_flags += -include $(BUILD_SYSTEM)/proguard_basic_keeps.flags
-endif # LOCAL_PROGUARD_ENABLED is not nosystem
-
-ifneq ($(LOCAL_PROGUARD_ENABLED),)
-ifeq ($(filter full custom nosystem, $(LOCAL_PROGUARD_ENABLED)),)
- $(warning while processing: $(LOCAL_MODULE))
- $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED))
-endif # not a legal value
-endif # LOCAL_PROGUARD_ENABLED
+ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
+# By default no obfuscation
+proguard_flags += -dontobfuscate
+endif # No obfuscation
+ifeq ($(filter optimization,$(LOCAL_PROGUARD_ENABLED)),)
+# By default no optimization
+proguard_flags += -dontoptimize
+endif # No optimization
+
+ifdef LOCAL_INSTRUMENTATION_FOR
+ifeq ($(filter obfuscation,$(LOCAL_PROGUARD_ENABLED)),)
+# If no obfuscation, link in the instrmented package's classes.jar as a library.
+# link_instr_classes_jar is defined in base_rule.mk
+proguard_flags += -libraryjars $(link_instr_classes_jar)
+else # obfuscation
+# If obfuscation is enabled, the main app must be obfuscated too.
+# We need to run obfuscation using the main app's dictionary,
+# and treat the main app's class.jar as injars instead of libraryjars.
+proguard_flags := -injars $(link_instr_classes_jar) \
+ -outjars $(intermediates.COMMON)/proguard.$(LOCAL_INSTRUMENTATION_FOR).jar \
+ -include $(link_instr_intermediates_dir.COMMON)/proguard_options \
+ -applymapping $(link_instr_intermediates_dir.COMMON)/proguard_dictionary \
+ -verbose \
+ $(proguard_flags)
+
+# Sometimes (test + main app) uses different keep rules from the main app -
+# apply the main app's dictionary anyway.
+proguard_flags += -ignorewarnings
+
+# Make sure we run Proguard on the main app first
+$(full_classes_proguard_jar) : $(link_instr_intermediates_dir.COMMON)/proguard.classes.jar
+
+endif # no obfuscation
+endif # LOCAL_INSTRUMENTATION_FOR
+endif # LOCAL_PROGUARD_ENABLED is not nosystem
proguard_flag_files := $(addprefix $(LOCAL_PATH)/, $(LOCAL_PROGUARD_FLAG_FILES))
LOCAL_PROGUARD_FLAGS += $(addprefix -include , $(proguard_flag_files))
-$(full_classes_proguard_jar): PRIVATE_PROGUARD_ENABLED:=$(LOCAL_PROGUARD_ENABLED)
$(full_classes_proguard_jar): PRIVATE_PROGUARD_FLAGS := $(proguard_flags) $(LOCAL_PROGUARD_FLAGS)
-$(full_classes_proguard_jar): PRIVATE_INSTRUMENTATION_FOR:=$(strip $(LOCAL_INSTRUMENTATION_FOR))
$(full_classes_proguard_jar) : $(full_classes_jar) $(proguard_flag_files) | $(ACP) $(PROGUARD)
$(call transform-jar-to-proguard)
-ALL_MODULES.$(LOCAL_MODULE).PROGUARD_ENABLED:=$(LOCAL_PROGUARD_ENABLED)
+else # LOCAL_PROGUARD_ENABLED not defined
+$(full_classes_proguard_jar) : $(full_classes_jar)
+ @echo Copying: $@
+ $(hide) $(ACP) -fp $< $@
+
+endif # LOCAL_PROGUARD_ENABLED defined
+
# Override PRIVATE_INTERMEDIATES_DIR so that install-dex-debug
# will work even when intermediates != intermediates.COMMON.
$(eval r := $(ALL_MODULES.$(m).REQUIRED)) \
$(if $(r), \
$(eval r := $(call module-installed-files,$(r))) \
- $(eval $(call add-required-deps,$(ALL_MODULES.$(m).INSTALLED),$(r))) \
+ $(eval t_m := $(filter $(TARGET_OUT_ROOT)/%, $(ALL_MODULES.$(m).INSTALLED))) \
+ $(eval h_m := $(filter $(HOST_OUT_ROOT)/%, $(ALL_MODULES.$(m).INSTALLED))) \
+ $(eval t_r := $(filter $(TARGET_OUT_ROOT)/%, $(r))) \
+ $(eval h_r := $(filter $(HOST_OUT_ROOT)/%, $(r))) \
+ $(if $(t_m), $(eval $(call add-required-deps, $(t_m),$(t_r)))) \
+ $(if $(h_m), $(eval $(call add-required-deps, $(h_m),$(h_r)))) \
) \
)
+t_m :=
+h_m :=
+t_r :=
+h_r :=
+
# Resolve the dependencies on shared libraries.
$(foreach m,$(TARGET_DEPENDENCIES_ON_SHARED_LIBRARIES), \
$(eval p := $(subst :,$(space),$(m))) \
$(call dist-for-goals,apps_only, $(EMMA_META_ZIP))
endif
+ $(PROGUARD_DICT_ZIP) : $(apps_only_installed_files)
+ $(call dist-for-goals,apps_only, $(PROGUARD_DICT_ZIP))
+
.PHONY: apps_only
apps_only: $(unbundled_build_modules)
$(INSTALLED_FACTORY_BUNDLE_TARGET) \
)
+ # Put a copy of the radio/bootloader files in the dist dir.
+ $(foreach f,$(INSTALLED_RADIOIMAGE_TARGET), \
+ $(call dist-for-goals, droidcore, $(f)))
+
ifneq ($(TARGET_BUILD_PDK),true)
$(call dist-for-goals, droidcore, \
$(APPS_ZIP) \
+# We have moved -dontobfuscate and -dontoptimize to the makefiles.
# dex does not like code run through proguard optimize and preverify steps.
--dontoptimize
+# -dontoptimize
-dontpreverify
# Don't obfuscate. We only need dead code striping.
--dontobfuscate
+# -dontobfuscate
# Add this flag in your package's own configuration if it's needed.
#-flattenpackagehierarchy
# see http://sourceforge.net/tracker/?func=detail&aid=2787465&group_id=54750&atid=474707
-optimizations !code/simplification/arithmetic
-optimizations !code/simplification/cast
--allowaccessmodification
# To prevent name conflict in incremental obfuscation.
-useuniqueclassmembernames
# Keep everything for tests
--dontshrink -dontobfuscate
+-dontshrink
+
+# But we may want to obfuscate if the main app gets obfuscated.
+# This flag has been moved to the makefiles.
+#-dontobfuscate
#-keep class * extends junit.framework.TestCase {
# public void test*();
TelephonyProvider \
UserDictionaryProvider \
VpnDialogs \
- abcc \
atrace \
libandroidfw \
libaudiopreprocessing \
Shell \
TelephonyProvider \
UserDictionaryProvider \
- abcc \
apache-xml \
audio \
bouncycastle \