Android proguard for Gson

Problem

GSON混淆后执行错误 java.lang.ClassCastException:
com.google.gson.internal.LinkedTreeMap cannot be cast to

Solution

I read from gson source through https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg,
here is the content.

##—————Begin: proguard configuration for Gson ———- 
#
Gson uses generic type information stored in a class file when working with
fields. Proguard 
#
removes such information by default, so configure it to keep all of it. 
-keepattributes Signature

# For using GSON @Expose annotation 
-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
com.google.gson.examples.android.model.*
{ 
; }

##—————End: proguard configuration for Gson
———-

总结一下

  1. 是不要混淆GsonJar包中的类
  2. 实现
    java.io.Serializable的实体类中所有的属性名称也不能被混淆。
  3. 以及为了序列化和反序列化,writeObject(); readObject();
    writeReplace(); readResolve();亦不可被混淆

Related Resource

http://xiaodongdong.blog.51cto.com/7049299/1353704 
编写Android Proguard
File

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇