[英]Android app with GSON works in debug mode, but not when running signed apk
I've made an android app that works fine in the emulator and when debugging on my actual device. 我做了一个Android应用程序,在模拟器和我的实际设备上调试时工作正常。
However, when running the signed apk on the device my GSON deserializing doesn't work. 但是,当在设备上运行签名的apk时,我的GSON反序列化不起作用。
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. 我已经检查过名为“response”的字符串是一个有效的JSON字符串,但_Strings.class的实际填充不起作用,并且_Strings.class中包含的所有字符串都保持为空。
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.
它仅在运行签名的apk时发生,并且Logcat输出根本不显示任何异常或堆栈跟踪。
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.
一个可能的原因可能是使用proguard(在工具链中)进行模糊处理 - 这会破坏您的命名策略。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.