用Proguard进行混淆时出现的问题

我的应用程序在混淆之前工作正常,但是当启用proguard时,出现以下错误:

2013-05-02 13:43:58.772 E 30138/AndroidRuntime: FATAL EXCEPTION: main java.lang.NumberFormatException: Invalid long: "0.20" at java.lang.Long.invalidLong(Long.java:125) at java.lang.Long.parse(Long.java:362) at java.lang.Long.parseLong(Long.java:353) at java.lang.Long.parseLong(Long.java:319) at com.sourcetone.data.model.Station.long getId()(SourceFile:195) at com.sourcetone.STStationListFragment.void deleteStation(com.sourcetone.data.model.Station)(SourceFile:298) at com.sourcetone.STStationListFragment.void access$4(com.sourcetone.STStationListFragment,com.sourcetone.data.model.Station)(SourceFile:293) at com.sourcetone.STStationListFragment$ArrayListAdapter$1.void onClick(android.view.View)(SourceFile:274) at android.view.View.performClick(View.java:3528) at android.view.View$PerformClick.run(View.java:14217) at android.os.Handler.handleCallback(Handler.java:605) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4482) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561) at dalvik.system.NativeStart.main(Native Method) 2013-05-02 13:43:58.803 W 472/ActivityManager: Force finishing activity com.sourcetone/.STMainActivity 

我的proguardconfiguration如下:

 -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } 

所以Parcelable应该保持正确吗? 抛出的Invalid Long实际上是我的请求的另一部分,所以它读取错误的数字。 我还必须保留我的HttpResponse类吗? 还有什么呢?

Solutions Collecting From Web of "用Proguard进行混淆时出现的问题"

 -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } 

不保留类的所有内容,只保留类名和CREATOR方法。

尝试保持Parcelable类中的字段,添加如下所示的内容:

 -keepclassmembers class * implements android.os.Parcelable { public <fields>; } 
 -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } 

它将保持类名称和CREATOR。

你应该改变它

 -keepclassmembers class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator CREATOR; } 

默认的android规则包含了上面的说明,如果你保留默认生成的gradle定义,也会应用到你的项目中:

 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'