I’ve made an android app that works fine in the emulator and when debugging on my actual device.
However, when running the signed apk on the device my GSON deserializing doesn’t work.
The problem occurs in this code:
public static void parseLanguage(String response) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setFieldNamingStrategy(new MyFieldNamingStrategy());
Gson gson = gsonBuilder.create();
_Helper.s = gson.fromJson(response, _Strings.class);
}
I also use this class:
class MyFieldNamingStrategy implements FieldNamingStrategy {
//Translates the Java field name into its JSON element name representation.
@Override
public String translateName(Field field) {
return field.getName();
}
}
I’ve checked that the string named “response” is a valid JSON string, but the actual populating of _Strings.class does not work, and all the strings contained in _Strings.class remain empty.
Does anyone have any idea why this happens? It only occurs when running the signed apk, and the Logcat output does not show any exceptions or stack traces at all.
Just spike your code with debug output wherever possible. This will give you more insight.
I doubt that the problem is in signing. Most probably it’s your project / build configuration. One possible cause could be obfuscation with proguard (which is in toolchain) – this will screw your naming strategy.