I am trying to compile my application with AOSP and which build properly. I have an issue with make use of the proguard flag.
-assumenosideeffects.
I am trying to strip out the Log statements in my final build and hence using the following in my proguard file,
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
}
and my Android.mk file entries look like these
LOCAL_PROGUARD_ENABLED := obfuscation optimization
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
I tried with various combinations. I made sure that the optimizations are enabled. It works fine if I use to build Android studio.
Is there any way to make this work while compiling with AOSP?
My Android.mk file
LOCAL_PATH:= $(call my-dir)
ifneq ($(TARGET_BUILD_PDK), true)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res \
frameworks/support/v7/appcompat/res \
frameworks/support/design/res
LOCAL_PACKAGE_NAME := Progurdsample
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_TAGS := optional
TARGET_ABI := x86_64
LOCAL_PRIVILEGED_MODULE := true
LOCAL_USE_AAPT2 := true
LOCAL_DEX_PREOPT := false
LOCAL_PROGUARD_ENABLED := custom
LOCAL_JACK_ENABLED := incremental
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat:android.support.v7.gridlayout
include $(BUILD_PACKAGE)
endif
Currently we cant directly use the assumenosideeffects
Explanation:
Android asop build tree not support assumenosideeffects
due to the jack build server.Jack uses proguard configuration files to enable shrinking and obfuscation. But some of the options will ignore by the Jack.
Ignored options include the following:
-dontoptimize // Jack does not optimize
-dontpreverify // Jack does not preverify
-skipnonpubliclibraryclasses
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-keepdirectories
-target
-forceprocessing
-printusage
-whyareyoukeeping
-optimizations
-optimizationpasses
-assumenosideeffects
-allowaccessmodification
-mergeinterfacesaggressively
-overloadaggressively
-microedition
-verbose
-dontnote
-dontwarn
-ignorewarnings
-printconfiguration
-dump
reference : https://source.android.com/setup/build/jack
But we can do a workaround for the same,
In the Makefile we can disable the jack build server using
ANDROID_COMPILE_WITH_JACK =false
The complete Android.mk file looks like,
LOCAL_PATH:= $(call my-dir)
ifneq ($(TARGET_BUILD_PDK), true)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res \
frameworks/support/v7/appcompat/res \
frameworks/support/design/res
LOCAL_PACKAGE_NAME := Progurdsample
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_TAGS := optional
TARGET_ABI := x86_64
LOCAL_PRIVILEGED_MODULE := true
LOCAL_USE_AAPT2 := true
LOCAL_DEX_PREOPT := false
LOCAL_PROGUARD_ENABLED := custom
ANDROID_COMPILE_WITH_JACK := false
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat:android.support.v7.gridlayout
include $(BUILD_PACKAGE)
endif