Gson: java.lang.IncompatibleClassChangeError

Created on 3 Nov 2015  Â·  43Comments  Â·  Source: google/gson

I'm getting this crash lately. It complains about SerializedName class missing the "value" method.

This is the stacktrace:

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.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:52)
at com.google.gson.Gson.getAdapter(Gson.java:359)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:122)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.access$100(ReflectiveTypeAdapterFactory.java:46)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.(ReflectiveTypeAdapterFactory.java:92)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:91)
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:875)
at com.google.gson.Gson.fromJson(Gson.java:848)

Most helpful comment

@morerohit86 If we wait 3,4 years more maybe Android 5 gonna get outdated and the issue will fix itself ¯_(ツ)_/¯

All 43 comments

Any ideas how to fix/omit this problem. I have been reading about this issue and it looks it is realted to Annotations handling on Android 5+ devices (mostly Samsung).
The related issues are:
https://code.google.com/p/android/issues/detail?id=172339
http://developer.samsung.com/forum/board/thread/view.do?boardName=General&messageId=280930

Did you upgrade to Gson 2.4? Try downgrading to Gson 2.3.1 and see if that fixes the problem.

Actually I had version 2.2.4. Is it still a case?

No, in that case, it is some other issue.

No action for us to take here.

Any hints there?
I changed JSON library from Gson to Jackson and the problem is the same. I get exceptions
java.lang.IncompatibleClassChangeError: Couldn't find com.fasterxml.jackson.annotation.JsonProperty.value

Any ideas how to omit this? Maybe different version of Android annotation from V4 library?
It looks like millions of apps across the world are affected because who doesn't use JSON with annotations processing?

That seems a stretch, our app uses Gson and annotation processing and does
not experience this problem.

On Mon, Nov 23, 2015 at 12:33 PM Dominik Tomczak [email protected]
wrote:

Any hints there?
I changed JSON library from Gson to Jackson and the problem is the same. I
get exceptions
java.lang.IncompatibleClassChangeError: Couldn't find
com.fasterxml.jackson.annotation.JsonProperty.value

Any ideas how to omit this? Maybe different version of Android annotation
from V4 library?
It looks like millions of apps across the world are affected because who
doesn't use JSON with annotations processing?

—
Reply to this email directly or view it on GitHub
https://github.com/google/gson/issues/726#issuecomment-159005293.

Really odd. I can see on my error console growing number of that exceptions.
Previously it was:
(GSON)
java.lang.IncompatibleClassChangeError: Couldn't find com.google.gson.annotations.SerializedName.value

(Jackson)
Now it is:
java.lang.IncompatibleClassChangeError: Couldn't find com.fasterxml.jackson.annotation.JsonProperty.value

I use Eclipse, Android 23 (6.0 SDK) as build SDK and latest v4/v7 libraries. I don't add special proguard file, it is a default one.
I can see this error being reported for Samsung 5.+ devices.
Any ideas are highly appreciated.

Thanks

I digged into this issue. It happens with _any_ annotation class with a "value" method in it. SerializedName it is or other.
In the libcore code, it tries to grap the Method with the "value" name through reflection, and for some reason it fails to find it "MethodNotFound" exception which is re-thrown as what we see here.
It is not related to gson specifically as I can see.

I'm from Optimizely, and we have some clients who are seeing this issue as well. Is this something that can be fixed?

We did some research and patched gson to make sure that the annotation would not use value and used a dedicated name for the annotation value. We basically we added a new annotation: @SerializedNamePatched(json = 'foo') vs @SerializedName('foo'). For reference code is available in https://github.com/potyl/gson/tree/booking/serialized-name-2.4 with unit tests changes too.

Turns out that this ended up causing crashes too, so the problem is not with the annotation using value.

The new crash we get:

java.lang.IncompatibleClassChangeError: Couldn't find com.google.gson.annotations.SerializedNamePatched.name
  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:79)
  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldNames(ReflectiveTypeAdapterFactory.java:72)
  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:167)
  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:108)
  at com.google.gson.Gson.getAdapter(Gson.java:360)
  at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:52)
  at com.google.gson.Gson.getAdapter(Gson.java:360)
  at com.google.gson.Gson.fromJson(Gson.java:813)
  at com.google.gson.Gson.fromJson(Gson.java:779)
  at com.google.gson.Gson.fromJson(Gson.java:728)

TL;DR the problem is not with the annotation using value but with the loading of the annotation.

Likely a build tools problem. Using ProGuard or similar? Those tools wreck your code.

I turned off ProGuard but it's still a problem. It's all affected Samsung 5.0 Devices
untitled

It looks like only Samsung Android 5 devices have this issue indeed

screenshot from 2015-12-23 13 27 10

We are also seeing this crash with gson 2.3.1 on Android 5 on Samsung.

screen shot 2016-02-25 at 1 21 12 pm

Anyone got a fix for this? I am also facing this issue.

Im also getting this error in Samsung device when users update app from play store.

Please check below log.

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)
    at android.os.Binder.execTransact(Binder.java:446)

Is the same error?

Fatal Exception: java.lang.IncompatibleClassChangeError: Couldn't find com.google.gson.a.c.a
       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(SourceFile:76)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldNames(SourceFile:71)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(SourceFile:156)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(SourceFile:97)
       at com.google.gson.Gson.getAdapter(SourceFile:407)
       at com.google.gson.Gson.fromJson(SourceFile:860)
       at com.google.gson.Gson.fromJson(SourceFile:826)
       at com.google.gson.Gson.fromJson(SourceFile:775)
       at com.google.gson.Gson.fromJson(SourceFile:747)
       at com.anyapp.common.GsonUtil.parse(SourceFile:23)
       at com.anyapp.dataprovider.network.UsersService$3$1.onDataChange(SourceFile:174)
       at com.firebase.client.Query$1.onDataChange(SourceFile:144)
       at com.firebase.client.core.ValueEventRegistration.fireEvent(SourceFile:53)
       at com.firebase.client.core.view.DataEvent.fire(SourceFile:45)
       at com.firebase.client.core.view.EventRaiser$1.run(SourceFile:38)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:5938)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

I've got the same issue here and using 2.6.2. Again Samsung devices on Android 5:

Caused by 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:75) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldNames(ReflectiveTypeAdapterFactory.java:70) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:155) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:96) at com.google.gson.Gson.getAdapter(Gson.java:416) at com.google.gson.Gson.fromJson(Gson.java:878) at com.google.gson.Gson.fromJson(Gson.java:844) at com.google.gson.Gson.fromJson(Gson.java:793) at com.google.gson.Gson.fromJson(Gson.java:765)

I just update to 2.2.4 ,then solve this problem , but I don not know why ?

Why is this issue closed? Was the resolution to rename all "value" keys?

Still getting these crashed on Samsung Android 5.0.1 devices

Any workaround?

Using gson 2.8.0 and still have the problem

+1

Same thing here. Has anyone found a workaround for this?

samsung5

Did anyone find a workaround for this?

This is constantly crashing our clients apps. While it only happens on a limited set of devices, it still makes up for more than 90% of our crashes.
Is there anything that can be done, beside moving away from gson?

We are also facing this issue for Android 5 only, did anyone find any solution for this ?
GSON : 2.8.0

screen shot 2018-03-24 at 12 11 35 pm

3 years later and this still happening with our app on Android 5 Samsung devices also!

Using Gson 2.8.5 and still experiencing the issue for Samsung lollipop devices. that's ridiculous.
http://crashes.to/s/57554ed9414
Is there a workaround really?

+1

+1 Also seeing on 5.0 Lollipop Samsung.

Silly question, but I suppose removing the annotations and making the POJO field names match the JSON will make the bad man go away?

@davros1970 I no longer work in the project where we had this issue, but I remember that we tried absolutely everything to get rid of this bug. If this bug is really annoying you the best thing is to try to move to another JSON parsing library.

Any updates on this?

I'm keep getting crashes on Samsung Galaxy Note 3 - Android 5.0:

Fatal Exception: 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.getFieldNames(ReflectiveTypeAdapterFactory.java:74)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:161)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
       at com.google.gson.Gson.getAdapter(Gson.java:458)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
       at com.google.gson.Gson.getAdapter(Gson.java:458)
       at com.google.gson.Gson.toJson(Gson.java:696)
       at com.google.gson.Gson.toJson(Gson.java:683)
       at com.google.gson.Gson.toJson(Gson.java:638)
       at com.google.gson.Gson.toJson(Gson.java:618)

It looks like it can't convert to String Json if the class contains List or Object.

This is how the parsing made:
String data = new Gson().toJson(product);

And this is the Product model object:

public class Product {
        private String id;
        private String name;

        private User user;

        public Product() {

        }
    }

As I said, I think the exception is thrown because the class contains another reference to another object. In my case is User

I have too many crashes with Gson 2.8.1 only on Android 5 Samsung devices. Isn't there any solution for this issue yet??

I am also facing the same issue only on Samsung 5.0 devices.
Screenshot 2019-05-16 at 5 01 47 PM

After 4 Years, We are still facing the same crash and the sad part is we haven't got the fix and the Issue is in Closed state.

@morerohit86 If we wait 3,4 years more maybe Android 5 gonna get outdated and the issue will fix itself ¯_(ツ)_/¯

I'm keep getting crashes on Samsung Galaxy Note 3 - Android 5.0:

Fatal Exception: 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.getFieldNames(ReflectiveTypeAdapterFactory.java:74)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:161)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
       at com.google.gson.Gson.getAdapter(Gson.java:458)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
       at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
       at com.google.gson.Gson.getAdapter(Gson.java:458)
       at com.google.gson.Gson.toJson(Gson.java:696)
       at com.google.gson.Gson.toJson(Gson.java:683)
       at com.google.gson.Gson.toJson(Gson.java:638)
       at com.google.gson.Gson.toJson(Gson.java:618)

It looks like it can't convert to String Json if the class contains List or Object.

This is how the parsing made:
String data = new Gson().toJson(product);

And this is the Product model object:

public class Product {
        private String id;
        private String name;

        private User user;

        public Product() {

        }
    }

As I said, I think the exception is thrown because the class contains another reference to another object. In my case is User

Is there any workaround for this problem?

Hi also have such crash. Any workaround ?

Still have this crash, waiting for 5 to deprecate, so, it must be the only way to fix it :`(

Was this page helpful?
0 / 5 - 0 ratings