Proguard "Missing type parameter" on Samsung device

2.1k views Asked by At

I`ve published an android app, obfuscated by dexguard. Everything seems to be fine, except for the Galaxy Tab 3 10.1 and only with Android 4.4, which is the only device, that reports errors to the developer console.

I get 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 class Helper.java 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 that I can not reproduce the error myself (i also have an Galaxy Tab 3 with Android 4.2, update not available yet), it only concerns the above mentioned device.

3

There are 3 answers

1
0xPixelfrost On BEST ANSWER

My solution was to avoid the use of the 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
Eric Lafortune On

If the error only occurs on one device, it's most likely a bug on that device. If you report such problems to us at Saikoa, preferably with a small sample project, we may be able to let DexGuard work around it. You could check if building with the latest update makes a difference.

(I am the developer of DexGuard)

0
T. Neidhart On

This issue can be solved by using a different way to create the TypeToken instance (for the 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 (I assume 2.8), will allow you to type this more easily:

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

For non-parameterized classes, the following can be used:

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