android - IncompatibleClassChangeError com.google.gson.annotations.SerializedName.value

标签 android gson

当用户从 Play 商店更新应用程序时,Samsung 设备中出现 IncompatibleClassChangeError。请检查以下日志。

java.lang.IncompatibleClassChangeError: Couldn't find com.google.gson.annotations.SerializedName.value
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:659)
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:641)
at libcore.reflect.AnnotationAccess.getDeclaredAnnotation(AnnotationAccess.java:170)
at java.lang.reflect.Field.getAnnotation(Field.java:242)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldName(ReflectiveTypeAdapterFactory.java:71)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldName(ReflectiveTypeAdapterFactory.java:67)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:142)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:83)
at com.google.gson.Gson.getAdapter(Gson.java:359)
at com.google.gson.Gson.fromJson(Gson.java:809)
at com.google.gson.Gson.fromJson(Gson.java:775)
at com.google.gson.Gson.fromJson(Gson.java:724)
at com.google.gson.Gson.fromJson(Gson.java:696)
at com.cubii.utils.SessionManager.getUserID(SessionManager.java:70)
at com.cubii.BluetoothLeService.broadcastUpdate(BluetoothLeService.java:188)
at com.cubii.BluetoothLeService.access$400(BluetoothLeService.java:47)
at com.cubii.BluetoothLeService$1.onCharacteristicChanged(BluetoothLeService.java:139)
at android.bluetooth.BluetoothGatt$1.onNotify(BluetoothGatt.java:443)
at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:399)`enter code here`
at android.os.Binder.execTransact(Binder.java:446)

代码如下:

public int getUserID(){
    try {
        String json = preferences.getString("User", "");

        LoginResponse loginResponse = new Gson().fromJson(json, LoginResponse.class);//getting error from this line

        Integer id = 0;
        if (loginResponse != null) {
            if (loginResponse.getId() != null) {
                id = loginResponse.getId();
            } else {
                id = loginResponse.getUserId();
            }
        }

        return (id == null) ? 0 : id;
    }catch (Exception e){
        Logger.dump(e);
    }
    return 0;
}

LoginResponse 是我的 POJO 类。

preferences.getString("User", "")

将返回服务器响应的 JSON 字符串。

最佳答案

看起来像是三星的问题。很多人不仅对 gson 库有同样的问题,对其他库也有同样的问题。我认为你对此无能为力,只能等待三星开发人员解决这个问题.. 这个问题已经在三星开发者论坛上提出了http://developer.samsung.com/forum/board/thread/view.do?boardName=General&messageId=280930

这里有更多关于此问题的报告,它只影响三星设备。 https://code.google.com/p/android/issues/detail?id=172339

编辑

他们中的一些人在三星以外的设备上也遇到了这个问题,所以这可能不完全是三星的错。此问题已分配给 Google 团队。作为 Google 团队成员之一提到的,如果有人可以将错误报告分享给团队,他们可以尽快解决此问题。

After reproducing the issue, navigate to developer settings, ensure ‘USB debugging’ is enabled, then enable ‘Bug report shortcut’. To take bug report, hold the power button and select the ‘Take bug report’ option.

Note: Please upload the bug report to google drive and share the folder to android-bugreport@google.com, then share the link here.

关于android - IncompatibleClassChangeError com.google.gson.annotations.SerializedName.value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36324416/

相关文章:

java - 无法解析日期 ["2016-08-29 11:08:37.645007"] : Invalid time zone indicator ' '

android - 如何将 Android 调试 keystore 放入颠覆存储库,然后让 Eclipse 使用它?

android - 切换到主页(到启动器)

java - 读取 XML 时出错

java - 修改 json 数组文件中的键值,并将更改后的值写入同一文件

java - 当 Gson 反序列化 JSON 时可以使用 setter 吗?

java - Java中使用gson解析tslint json

java - 通过具有 Activity 实例的类型(类)查找 View

Android,如何实例化Universal Image Loader?

javascript - 使用 Gson 将 Javascript/Json 日期字符串转换为 Java 日期