so Ive read pretty much thousands of threads here and at other places and its still not working for me. Its either errors like cannot find referenced class sun.misc.Unsafe, or if i use dontwarn on those, it compiles but the gson part returns ClassCastExecption at some point.

Now - I know that serialized classes shuold be marked as -keep in proguard settings, I know about -keepattributes Annotation and Signature, however i still fail to obfuscate my code properly.

Attaching my proguard-project.txt

-optimizationpasses 2
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic 

-allowaccessmodification
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-repackageclasses ''

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

-keepattributes Signature

-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 my.package.model.** { *; }

-keep class com.google.gson.** { *; }

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

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

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

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

Edit 1 I also checked this gson example proguard settings

有帮助吗?

解决方案

Apparently -keepattributes Exceptions,InnerClasses,Signature,Deprecated, SourceFile,LineNumberTable,Annotation,EnclosingMethod sorta helped. I aint got any clue why though, and im not getting Logs cut out of the output aswell, it just changed into StringBuffer lol.

Edit 1 Though ive added a target into ant build.xml script that goes like this if anyone needs it

<target name="-commentoutlogs">
    <replaceregexp match="(Log\..*?;\s*\n)" replace="/*\1*/" flags="gs" byline="false">
        <fileset dir="src">
            <include name="**/*.java"/>
        </fileset>
    </replaceregexp>
</target>

and to uncomment:

    <target name="-uncommentlogsafter">
    <replaceregexp match="\/\*(Log\..*?;\s*\n)\*\/" replace="\1" flags="gs" byline="false">
        <fileset dir="src">
            <include name="**/*.java"/>
        </fileset>
    </replaceregexp>
</target>

so you can add it to like release target so it fixes the stuff for you and the Logs are finely commented into

/*Log.<blablabla> );
*/
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top