首页 文章

gson混淆程序错误

提问于
浏览
1

所以我在这里和其他地方阅读了几千条线程,它仍然不适合我 . 它的错误就像找不到引用类sun.misc.Unsafe,或者如果我在那些上使用dontwarn,它编译但是gson部分在某些时候返回ClassCastExecption .

现在 - 我知道序列化类shuold在proguard设置中被标记为-keep,我知道-keepattributes Annotation和Signature,但是我仍然无法正确地混淆我的代码 .

附上我的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(...);
}

编辑1我也查了这个gson example proguard settings

1 回答

  • 0

    显然-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,Annotation,EnclosingMethod sorta帮助 . 我不知道为什么,虽然我没有从输出中删除Logs,它只是变成了StringBuffer lol .

    编辑1虽然我已经在ant build.xml脚本中添加了一个目标,如果有人需要它,就会这样

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

    并取消注释:

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

    所以你可以把它添加到类似的发布目标,以便它为你修复这些东西,并且日志被很好地评论

    /*Log.<blablabla> );
    */
    

相关问题