如何在Android.MK文件中使用-assumenosideeffects标志启用proguard

时间:2018-05-24 06:00:28

标签: android android-source android-build android-make

我正在尝试使用AOSP编译我的应用程序并正确构建。我有一个使用proguard标志的问题。

-assumenosideeffects.

我试图在最终版本中删除Log语句,因此 在我的proguard文件中使用以下内容,

-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
}

我的Android.mk文件条目如下所示

LOCAL_PROGUARD_ENABLED := obfuscation optimization
LOCAL_PROGUARD_FLAG_FILES := proguard.flags

我尝试了各种组合。我确保优化是 启用。 如果我用来构建Android工作室,它可以正常工作。

在使用AOSP进行编译时,有没有办法使这项工作?

我的Android.mk文件

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

1 个答案:

答案 0 :(得分:0)

目前我们无法直接使用assumenosideeffects

<强>说明: 由于jack构建服务器,Android asop构建树不支持assumenosideeffects .Jack使用proguard配置文件来启用收缩和混淆。但是Jack会忽略一些选项。 忽略的选项包括以下内容:

-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 

参考:https://source.android.com/setup/build/jack

但我们可以为此做一个解决方法,

在Makefile中,我们可以使用禁用jack构建服务器 ANDROID_COMPILE_WITH_JACK =false

完整的Android.mk文件如下所示,

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