Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parcelable Issues When Obfuscating With Proguard

My app works fine before obfuscation but when I enable proguard I get the following error:

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

My proguard config has the following:

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

So Parcelable should be keep right? The Invalid Long that it's throwing is actually another part of my request so it's reading the wrong number. Do I have to keep my HttpResponse class as well? What else could it be?

like image 324
hanleyhansen Avatar asked May 03 '13 15:05

hanleyhansen


People also ask

Does ProGuard obfuscate code?

You can obfuscate Android code to provide security against reverse engineering. You can use the Android ProGuard tool to obfuscate, shrink, and optimize your code. Obfuscated code can be more difficult for other people to reverse engineer.

How does ProGuard obfuscation work?

It obfuscates the code, which means that it renames classes, fields, and methods with semantically obscure names that, in addition to making the codebase smaller and more efficient, also makes it difficult to reverse engineer the app.

How do you keep a class in ProGuard?

-keepclassmembernames. This is the most permissive keep directive; it lets ProGuard do almost all of its work. Unused classes are removed, the remaining classes are renamed, unused members of those classes are removed, but then the remaining members keep their original names.


1 Answers

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

Doesn't keep all the content of your class intact, it just keeps the classname and the CREATOR method.

Try to keep the fields too in your Parcelable class, add something like :

-keepclassmembers class * implements android.os.Parcelable {
 public <fields>;
}
like image 172
doga Avatar answered Oct 03 '22 09:10

doga