如何使用proguard阻止选择性课程?

时间:2015-04-06 10:01:43

标签: java android android-fragments proguard

我想使用proguard在我的Android Studio项目中混淆一些类。这些是com.myproject.fragments文件夹中的一些片段。所有这些类都在扩展Android的Fragment类。看来,截至目前,我的计划规则是将这些类别排除在混淆之外。请告诉我如何编辑我的proguard规则文件以使这种混淆发生。

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

-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.content.Context

-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 * extends android.content.Context {
   public void *(android.view.View);
   public void *(android.view.MenuItem);
}

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

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

-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}


# Preserve the special static methods that are required in all enumeration classes.
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
    public *;
}

-keep public enum com.sync.model$** {
    **[] $VALUES;
    public *;
}

# Application classes that will be serialized/deserialized over Gson
-keep class com.myproject.models.** { *; }
-keep class com.myproject.httputils.** { *; }


-keep class com.facebook.** {
   *;
}

-keep class com.androidplot.** { *; }

-keepclassmembers class * extends com.actionbarsherlock.ActionBarSherlock {
    <init>(android.app.Activity, int);
}

# Gson specific classes
#-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }

2 个答案:

答案 0 :(得分:1)

你可以排除特定的课程和在Proguard文件中打包...

排除特定班级

-keep class com.demo.fragment.myfragment {*; }

排除整个包类

-keep class com.demo.fragment。 {*; } **

答案 1 :(得分:0)

您似乎正在使用此处提供的proguard文件模板 https://code.google.com/p/google-gson/source/browse/trunk/examples/android-proguard-example/proguard.cfg

自2011年以来尚未更新

同时检查一下 ProGuard for Android and GSON