2016-12-09 211 views
0

我已經使用proguard構建了一個發佈Android應用程序,但在反編譯APK之後,我發現必須進行混淆的類具有正常的源。還有我的gradle這個構建的一部分:Android proguard不會混淆類

buildTypes { 
    debug { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 
    } 
    release { 
     minifyEnabled true 
     proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 
    } 
} 

這是我的proguard-rules.pro文件:

-dontpreverify 
-repackageclasses '' 
-allowaccessmodification 
-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>; 
} 

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

-keepnames class * implements java.io.Serializable 

-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(); 
} 

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

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

-dontwarn okio** 
-dontwarn java.lang.invoke** 
-dontwarn org.apache.commons.io** 
-dontwarn org.codehaus** 
-keep public class java.nio** 
-dontwarn android.support.v4.** 
-keep class android.support.v4.** { *; } 
-dontwarn android.support.v7.** 
-keep class android.support.v7.** { *; } 
-keep class net.sqlcipher.** { *; } 

-keep class net.sqlcipher.database.** { *; } 

-keep class retrofit2.** { *; } 
-keepattributes Signature 
-keepattributes Exceptions 
-keepclasseswithmembers class * { 
    @retrofit2.http.* <methods>; 
} 
-keep class com.squareup.okhttp.** { *; } 
-keep interface com.squareup.okhttp.** { *; } 
-keep class com.google.gson.** { *; } 
-keep class com.google.inject.* { *; } 
-keep class org.apache.http.** { *; } 
-keep class org.apache.james.mime4j.** { *; } 
-keep class javax.inject.** { *; } 
-keepclassmembernames interface * { 
    @retrofit.http.* <methods>; 
} 

-keep class sun.misc.Unsafe { *; } 
-keep public class !com.vidal.cardio.datas.MySQLCipherOpenHelper { *; } 
-keep public class !com.vidal.cardio.datas.SCLcipherOpenHelper { *; } 

嗯,我預計MySQLCipherOpenHelperSCLcipherOpenHelper會被混淆,但實際上他們不「T。也許在proguard-rules.pro中有錯誤?

+0

的可能的複製(http://stackoverflow.com/questions/40811898/proguard-obfuscation-doesnt-work-on-activities) –

回答

1

保持規律進行分析,並相互獨立地進行處理,所以如果你寫這樣

-keep public class !com.vidal.cardio.datas.MySQLCipherOpenHelper { *; } 
-keep public class !com.vidal.cardio.datas.SCLcipherOpenHelper { *; } 

ProGuard的規則將做到以下幾點:

  • 過程中的第一條規則把一切都只是MySQLCipherOpenHelper
  • 處理第二條規則以保留除SCLcipherOpenHelper之外的所有內容

正如你所看到的,第一條規則也隱含地保留了第二類,而第二條規則也保留了第一條。

爲了跟不上他們兩個,你必須合併這樣的規則:?在活動Proguard的混淆不起作用]

-keep public class !com.vidal.cardio.datas.MySQLCipherOpenHelper, 
        !com.vidal.cardio.datas.SCLcipherOpenHelper { *; } 
+0

謝謝!有用! –