Proguard "Missing type parameter" on Samsung device

I posted an Android app confusing dexguard. Everything seems fine, except for the Galaxy Tab 3 10.1 and only with Android 4.4, which is the only device that reports errors in the developer console.

I am getting the following exception:

java.lang.RuntimeException: Missing type parameter.
at com.google.gson.reflect.TypeToken.<init>(:62)
at com....util.Helper$2.<init>(:398)

      


Code in Helper.java class and line 398

return (Config) getSerializable(context, CONFIG, new TypeToken<Config>(){}.getType());

      


My dexguard rules:

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-keep class sun.misc.Unsafe { *; }

# Application classes that will be serialized/deserialized over Gson
# path to the config class:  com/.../models/config/Config.java;
-keep class com....models.** { *; }

-keepattributes Signature

      


Not only can I not reproduce the error myself (I also have a Galaxy Tab 3 running Android 4.2, no update available yet), this only applies to the device mentioned above.

+3


source to share


3 answers


My solution was to avoid using TypeToken and updating dexguard to the latest version.

For example:

Instead of

new Gson().fromJson(json, new TypeToken<Object>(){}.getType());

      



use this

new Gson().fromJson(json, Object.class);

      

+2


source


If the error occurs on only one device, it is most likely a bug on that device. If you report such problems to us at Saikoa, preferably with a small project, we can allow DexGuard to work with it. You can check if the build has changed with the latest update.



(I'm a DexGuard developer)

+1


source


This problem can be solved by using another way to instantiate the TypeToken (for a parameterized type List<User>

):

Type collectionType = 
  TypeToken.get(
    $Gson$Types.newParameterizedTypeWithOwner(null,
      List.class, User.class)).getType();

new Gson().fromJson(json, collectionType);

      

The next version of gson (2.8 I assume) will allow you to enter this easily:

Type collectionType =
  TypeToken.getParameterized(List.class,
                             User.class).getType();
new Gson().fromJson(json, collectionType);

      

For non-parameterized classes, you can use the following:

new Gson().fromJson(json, TypeToken.get(Config.class).getType());

      

+1


source







All Articles