gson: java.lang.IncompatibleClassChangeError

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)

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 45 (1 by maintainers)

Commits related to this issue

Most upvoted comments

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

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

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?

Still getting these crashed on Samsung Android 5.0.1 devices

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

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.

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)

Using gson 2.8.0 and still have the problem

Any updates on this?

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.

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

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.

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

7 years later and this still happening with our app on Android 14 Vivo devices also!

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??

@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.

+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?

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?

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