模糊不能与proguard

时间:2017-02-22 14:19:56

标签: java android proguard obfuscation android-proguard

我正在使用各种其他库。但是我已经从他们的存储库文档中添加了他们的proguard配置我无法使用proguard来混淆我的代码及其内部变量。即使我无法模糊包名。我仍然可以在我的android logcat上看到日志。我的应用程序运行没有任何崩溃。我是否感到困惑是否适用缩小。

这是我的app level gradle

   defaultConfig {
    resConfigs "en"
    applicationId "com.xxx.xxx"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 49
    multiDexEnabled true
    versionName "1.4.2-debug"
}
buildTypes {
    debug {
        minifyEnabled true
        debuggable true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    release {
        minifyEnabled true
        debuggable true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.config
    }
}
dexOptions {
    javaMaxHeapSize "4g"
}

这是我的proguard规则文件。

-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}

-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class **.R$* {
public static <fields>;
}
####################################################################      Fragmenst

-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment


####################################################################  Methods

-keepclasseswithmembernames class * {
native <methods>;
}
-keepclassmembers class * {
public void *ButtonClicked(android.view.View);
}



####################################################################  Serializables

-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[]serialPersistentFields;
!static !transient <fields>;
!private <fields>;
!private <methods>;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}

####################################################################  KEEP ANDROID SUPPORT V7 AND DESIGN

-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }

-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }

-keep public class * extends android.support.v4.view.ActionProvider {
public <init>(android.content.Context);
}

-keep interface android.support.v4.** { *; }
-keep interface android.support.v7.** { *; }
-keep class android.support.** { *; }

####################################################################  REMOVE WARNINGS


-dontwarn android.support.design.internal.**
-dontwarn com.google.android.gms.**
-dontwarn android.support.v4.**


####################################################################  REMOVE LOGGING

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

2 个答案:

答案 0 :(得分:3)

I am not able to obfuscate my code and its inner variable using proguard

您的应用程序似乎没有混淆,因为您的progaurd规则过于宽泛,并且它们阻止了大部分代码被缩小和混淆。例如以下行:

-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

I am still able to see logs on my android logcat

您必须从gradle的release buildType中删除debuggable true以防止在logcat中查看日志。

答案 1 :(得分:0)

我有这条线

-dontobfuscate 

在我的proguard文件中阻止混淆