我们遇到的问题是,除了一些局部变量和一些方法之外,proguard并没有混淆大部分代码。休息所有方法名称(包括私有)保持原样 - 未经过模糊处理。我试图查看以前的帖子有类似的问题,大多数建议都与debuggable或-keep有关,这在这种情况下不适用,如下所述。必须是一个愚蠢的错误,但我们无法发现。
以下是mapping.txt的一小部分,显示了proguard保留名称
230:710:void onCreate(android.os.Bundle) -> onCreate
713:729:void setProfilePicture() -> setProfilePicture
733:737:void onStart() -> onStart
743:748:void createLocationRequest() -> createLocationRequest
755:759:void buildGoogleApiClient() -> buildGoogleApiClient
767:781:boolean checkPlayServices() -> checkPlayServices
787:794:void displayPlacePicker() -> displayPlacePicker
下面的是gradle文件的相关部分,如你所见,debuggable为false且minifyEnabled为true
buildTypes {
release {
debuggable false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-library.pro'
}
}
下面是proguarf文件,你可以看到只有两个类保存了CargoUI和CargoUIListener。但是,它保留了其他类(有些是Activity / Fragment类)的方法,因为它没有混淆。
-optimizationpasses 2
-dontpreverify
-verbose
-dontshrink
#-keepparameternames
-renamesourcefileattribute SourceFile
#-keepattributes SourceFile,LineNumberTable,Exceptions,InnerClasses,Signature
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-optimizations !field/removal/writeonly,!field/marking/private,!class/merging/*,!code/allocation/variable,!code/simplification/arithmetic,!field/*
-dump dump.txt
-printmapping mapping.txt
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
@butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
@butterknife.* <methods>;
}
-keepclasseswithmembernames,includedescriptorclasses class * {
native <methods>;
}
-keep class com.cargo.CargoUI {
public static *;
public *** init(...);
}
-keep class com.cargo.CargoUIListener {*;}
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** w(...);
public static *** v(...);
public static *** i(...);
public static *** e(...);
}
-assumenosideeffects class com.cargo.api.TMLog {
public static *** d(...);
public static *** w(...);
public static *** v(...);
public static *** i(...);
public static *** e(...);
}
-assumenosideeffects class com.cargo.api.Log {
public static *** d(...);
public static *** w(...);
public static *** v(...);
public static *** i(...);
public static *** e(...);
}
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.google.i18n.phonenumbers.** { *; }
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
##---------------End: proguard configuration for Gson ----------