只有在构建为 apk 时改造才起作用

Retrofit did not work only when build to apk

我的应用程序在 android studio 调试时运行良好。 但是当我构建到 apk 然后在设备上安装时它不起作用。

当我调试时,服务器 api 运行良好,但从 json 转换为 java 对象时发生错误(我使用 gson)。 问题是代码在调试模式下运行良好(build & 运行 from android studio),但在通过 apk 安装时失败。 这里有人以前遇到过同样的错误吗?

// API调用

getUserPrivateInfo().map(res -> {
            MZDebug.d("UserPrivateInfo", res.toString());
            CommonCheck.checkResponse(res);
            return res.getData();
});

//然后报错:只有apk安装的app

java.lang.NullPointerException: throw with null exception

在我看来这与 Proguard 配置有关

要避免此问题,请将新规则添加到 Proguard 文件中

-keep class path of your data class.** { *; }