简体   繁体   English

使用GSON的Android应用程序在调试模式下工作,但在运行已签名的apk时则不行

[英]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.

相关问题 您上传了在调试模式下签名的 APK 或 Android App Bundle - You uploaded an APK or Android App Bundle that was signed in debug mode 从Android Studio运行时,应用正常运行,但在安装签名的APK后崩溃 - App works fine when running from Android Studio but crashes when signed apk installed 应用程序在 USB 调试模式下工作正常,但是当我生成签名 APK 并安装它时,它不起作用 - App is working fine in usb debug mode, but when i generate Signed APK and install it, its not working Ionic Android 应用程序在签名版本 apk 上无法访问互联网,但调试工作正常 - Ionic Android app has no internet access on signed release apk but debug works fine 我的应用程序在调试模式下运行良好,但使用签名的 APK 时会崩溃 - My App work fine in debug mode but with signed APK it crashes Firestore 应用程序可在调试中运行,但签名的 apk 出现错误 - Firestore app works in debug but signed apk gives error 您已在调试模式下发送了签名的 APK 或 Android App Bundle。 在发布模式下签名。 如何修复它(颤振) - You have sent a signed APK or Android App Bundle in debug mode. Sign it in release mode. How to fix it (flutter) Android-带签名的APK未运行 - Android - Signed apk not running Android App可在Debug模式下运行,但不能在Run模式下运行 - Android App works in Debug Mode, but not in Run mode Apk 在发布模式下崩溃但在调试模式下完美运行 - Apk crashes when Release mode but in debug mode works perfectly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM