Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IncompatibleClassChangeError #726

Closed
kdehairy opened this issue Nov 3, 2015 · 45 comments
Closed

java.lang.IncompatibleClassChangeError #726

kdehairy opened this issue Nov 3, 2015 · 45 comments
Labels
android Issues which are exclusive to Android, and don't occur with a JDK (even if ProGuard / R8 is used)

Comments

@kdehairy
Copy link

kdehairy commented Nov 3, 2015

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)
@dominolog
Copy link

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

@inder123
Copy link
Collaborator

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

@dominolog
Copy link

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

@inder123
Copy link
Collaborator

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

@swankjesse
Copy link
Collaborator

No action for us to take here.

@dominolog
Copy link

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?

@JakeWharton
Copy link
Contributor

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 notifications@github.com
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
#726 (comment).

@dominolog
Copy link

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

@kdehairy
Copy link
Author

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.

@pamoptly
Copy link

pamoptly commented Dec 3, 2015

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

@potyl
Copy link

potyl commented Dec 18, 2015

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.

@swankjesse
Copy link
Collaborator

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

@cuongthai
Copy link

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

@amadofelipe
Copy link

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

screenshot from 2015-12-23 13 27 10

@KamilMroczek
Copy link

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

@nizamsp
Copy link

nizamsp commented Mar 7, 2016

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

@skkakadiya
Copy link

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)

@tonilopezmr
Copy link

tonilopezmr commented May 5, 2016

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)

@GaborPeto
Copy link

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)

@zengjingfang
Copy link

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

@sophiataskova
Copy link

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

@vit001
Copy link

vit001 commented Jun 28, 2017

Still getting these crashed on Samsung Android 5.0.1 devices

@alexanderkjeldaas
Copy link

Any workaround?

@papirovdavid
Copy link

Using gson 2.8.0 and still have the problem

@mvij
Copy link

mvij commented Oct 3, 2017

+1

@4gus71n
Copy link

4gus71n commented Oct 23, 2017

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

samsung5

@gaurav-algorythma
Copy link

Did anyone find a workaround for this?

@catt-stefano
Copy link

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?

@tasneembohra
Copy link

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

@MohNage7
Copy link

MohNage7 commented May 6, 2018

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

@Sdghasemi
Copy link

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?

@squarelab-slee
Copy link

+1

@davros1970
Copy link

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

@4gus71n
Copy link

4gus71n commented Aug 4, 2018

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

@sepehr1014
Copy link

Any updates on this?

@leventepal
Copy link

leventepal commented Sep 7, 2018

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

@nazaninds
Copy link

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

@Mihir3646
Copy link

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

@morerohit86
Copy link

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.

@4gus71n
Copy link

4gus71n commented Jun 12, 2019

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

@FazalHussain
Copy link

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?

facebook-github-bot pushed a commit to facebook/litho that referenced this issue Feb 14, 2020
…ldsSummary

Summary:
PROBLEM
-------
This constitutes 89.2% of overall ComponentUtils.hasEquivalentFields crashes in production. This is a known error which exists in Android Lollypop which was fixed in later OS versions.

Details of the issue which was reported to Google :
https://issuetracker.google.com/issues/37045084
google/gson#726

To summarise,  libraries which uses annotations is facing this intermittently. Google closed this saying it is infeasible to fix this in older OS versions.

Reviewed By: astreet

Differential Revision: D19835819

fbshipit-source-id: cebef218bd97531d8892e31e8d40654edaaa97de
@AnastasiyaVia
Copy link

Hi also have such crash. Any workaround ?

@repitch
Copy link

repitch commented Aug 17, 2020

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

@quibbler01
Copy link

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!

@Marcono1234
Copy link
Collaborator

As mentioned originally in #726 (comment), this is an issue with Android itself, see https://issuetracker.google.com/issues/37045084, and affected more than just Gson as also mentioned in some of the comments here.

I assume that was why this Gson issue was closed because most likely there is nothing which can be done by Gson to fix this issue, instead this had to be fixed in the Android OS.

@quibbler01, the situation might be the same for you. Maybe try contacting Vivo first (or reporting it on the Android bug tracker; not sure what the correct procedure is) and then please report here back.

@eamonnmcmanus eamonnmcmanus added the android Issues which are exclusive to Android, and don't occur with a JDK (even if ProGuard / R8 is used) label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Issues which are exclusive to Android, and don't occur with a JDK (even if ProGuard / R8 is used)
Projects
None yet
Development

No branches or pull requests