Remap proguard to access previous stored objects

Hi there,

I am using proguard inside Android Studio. The following scenario happened:

  1. Objects (.com.package.model) are stored inside a SQLite Database as Gson strings
  2. currently no proguard exceptions were added
  3. app is released on the play store
  4. after updating the release, app crashes (I suppose some changes inside the obfuscation were made and it can’t read the stored objects anymore)
  5. disabling proguard or adding the exceptions to both releases lets the error disappear. But adding only exceptions to the latest release, does not help (and I can’t change the code of the already released one)

Is there anybody who could give me a hint how to handle this? Maybe changing the mapping of the latest release manually somehow, read the stored values and then add the exceptions? I am a little bit lost here.

Thank you in advance.

Dear @noiling,

Welcome to the PG community!

In this case, you should provide a keep option for the serialized class and its members. This is the safest approach.

For example

-keepnames com.example.myserializableclass{*;}
-keepclassmembers com.example.myserializableclass{*;}

This way, the names of those serializable objects are not obfuscated. The issue here, resides in the way serialization works. Currently, names of the serialized object (and its members) are being obfuscated first, and then get serialized to a server, second. Initially, this works fine when you serialize data to the server. But, as you noticed, the problem will occur when you to de-serialize that data.

When you try deserializing that data from the server (using the original names) the app crashes, because the server does not have a mapping file, and all the names (which you’re now trying to deserialize by the original identifier) were previously obfuscated by ProGuard prior to serializing that data to the server. So, when you try to de-serialize a model or dto by its original name, it can’t be found… the name is actually changed. In actuality, you would need to retrieve/deserialize it but the obfuscated name for deserialization to work properly. But that’s not how your code works.

Luckily, there is a simple fix.

Providing a keep rule for those serialized parts, will ensure those names are not obfuscated by ProGuard. As a result, when you try to deserialize those pieces of data from the server later on, the names wont be changed, can once again be found by the original name, and the app won’t crash when anymore.

You can read more about this in our manual here:

Please let me know if you have any questions.

Kind regards,