google / gson

A Java serialization/deserialization library to convert Java Objects into JSON and back
Apache License 2.0
23.36k stars 4.28k forks source link

Verifier rejected class com.google.gson.Gson #1353

Closed RobMans426 closed 6 years ago

RobMans426 commented 6 years ago

Hi, I am developing Android app and I faced wired issue recently. My app worked smoothly before, then it broke down few days ago. When I run my app, I got this error. java.lang.VerifyError: Verifier rejected class com.google.gson.Gson due to bad method void com.google.gson.Gson.<clinit>() (declaration of 'com.google.gson.Gson' appears in /data/app/com.xxx.xx-1/base.apk)

I tried many ways, but I still did not fix this error. Could someone help me for this error?

Best Regards.

lavkush-verma commented 6 years ago

I am also facing the same issue. Play store sending prelaunch report with errors. Issue: java.lang.NoSuchMethodError: No virtual method a(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object; in class Lcom/google/gson/d; or its super classes (declaration of 'com.google.gson.d' appears in /data/app/com.google.android.apps.mtaas.crawler-1/base.apk)

java.lang.IllegalAccessError: Illegal class access: .Network.e' attempting to access 'com.google.gson.d' (declaration of '.Network.e' appears in /data/app/-1/base.apk)

Any quick work around for this issue.

RobMans426 commented 6 years ago

Hi, @Iavkush

This is not related with this gson library. This is related with other 3rd part libraries that you used in your app level gradle. Some libraries include gson inside. You need to exclude gson from other libraries.

Please add following code in the app level gradle.

configurations.all{ exclude group: 'com.google.code.gson', module: 'gson' }

Hope this will help you!

lavkush-verma commented 6 years ago

@RobMans426 My App module uses the GSON library extensively. I have tried your solution but now getting compilation issues with errors as below -- error: package com.google.gson.annotations does not exist import com.google.gson.annotations.Expose; error: package com.google.gson.annotations does not exist import com.google.gson.annotations.SerializedName;

If I do not add below line in my app/build.gradle file, compilation is success. But when I upload my app to playstore, it gives me errors which I have mentioned in previous comment [These errors I am getting in latest release to my app, previously no errors].

configurations.all{ exclude group: 'com.google.code.gson', module: 'gson' }

Please help.

RobMans426 commented 6 years ago

@lavkush-verma Can you run your app in your device with release mode without any issues?

please exclude gson from all libraries. And add gson module like this. implementation 'com.google.code.gson:gson:2.8.5

lavkush-verma commented 6 years ago

Yes, I am able to run on Release mode in my device set running on L, M, N and O variant.

On Wed, Jul 25, 2018 at 19:28 RobMans426 notifications@github.com wrote:

@lavkush-verma https://github.com/lavkush-verma Can you run your app in your device with release mode?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/google/gson/issues/1353#issuecomment-407763377, or mute the thread https://github.com/notifications/unsubscribe-auth/ACK414XJJ6i3lP92kmbl4xG6qBxet-czks5uKHl-gaJpZM4VVtud .

--

RobMans426 commented 6 years ago

Could u copy your app level gradle file here?

tomerpetel commented 6 years ago

Hi, I'm getting the same thing in Google's Pre-Launch report. The strange thing is that I haven't changed a thing regarding the JSON library from the previous version and that version passed Pre-Launch without any errors

Issue: java.lang.VerifyError: Verifier rejected class com.google.gson.Gson: void com.google.gson.Gson.<clinit>() failed to verify: void com.google.gson.Gson.<clinit>(): [0x5] register v0 has type Precise Reference: com.google.gson.Gson$1 but expected Reference: com.google.gson.reflect.TypeToken (declaration of 'com.google.gson.Gson' appears in /data/app/com.bluegate.app-TXgbYn54WvvOMWt27q0CxQ==/base.apk)

Occurs on Pixel w/Android 8.0 and Pixel 2 w/Android P Preview

lavkush-verma commented 6 years ago

@RobMans426
Dependencies are add in this way ... With GSON version = 2.8.2 or 2.8.5 (same issues)

dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation project(':volley') implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') { transitive = true exclude group: 'com.android.support', module: 'support-annotations' }

implementation "com.android.support:support-v4:$rootProject.supportLibraryVersion"
implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
implementation "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
implementation "com.android.support:design:$rootProject.supportLibraryVersion"
implementation "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
implementation "com.android.support:support-vector-drawable:$rootProject.supportLibraryVersion"
implementation "com.android.support.constraint:constraint-layout:$rootProject.constraintLayoutVersion"

implementation "com.google.code.gson:gson:$rootProject.gsonVersion"
implementation "com.google.firebase:firebase-core:$rootProject.firebaseCoreVersion"
implementation "com.google.firebase:firebase-messaging:$rootProject.firebaseMessagingVersion"

implementation "com.facebook.android:facebook-android-sdk:$rootProject.facebookSDKVersion"
implementation "com.squareup.okhttp3:okhttp:$rootProject.okhttpVersion"

implementation "com.github.bumptech.glide:glide:$rootProject.glideVersion"
implementation "com.github.chrisbanes:PhotoView:$rootProject.photoViewVersion"

implementation "com.jakewharton:butterknife:$rootProject.butterKnifeVersion"
annotationProcessor "com.jakewharton:butterknife-compiler:$rootProject.butterKnifeVersion"
implementation "org.greenrobot:eventbus:$rootProject.eventBusVersion"

}

nostel commented 6 years ago

I have the same problem with @tomerpetel . Everything is fine until yesterday... Do you have any idea about this problem?

dixit712 commented 6 years ago

I have the same problem with @tomerpetel @nostel Everything is fine until yesterday... Do you have any idea about this problem?

Dependencies are added in this way ...

dependencies { implementation 'com.android.support.constraint:constraint-layout:1.1.2' compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' })

compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.github.badoualy:stepper-indicator:1.0.6'
compile 'com.google.android.gms:play-services-analytics:11.2.2'
compile 'com.google.android.gms:play-services-ads:11.2.2'
compile 'com.google.android.gms:play-services-location:11.2.2'
compile 'com.google.android.gms:play-services-gcm:11.2.2'
compile 'com.google.android.gms:play-services-auth:11.2.2'
compile 'com.facebook.android:audience-network-sdk:4.27.1'
compile 'com.github.nguyenhoanglam:ImagePicker:1.1.3'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.jakewharton.retrofit:retrofit1-okhttp3-client:1.1.0'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.google.code.gson:gson:2.7'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.onesignal:OneSignal:3.6.2'
compile 'com.getkeepsafe.relinker:relinker:1.2.3'
compile 'com.android.support:multidex:1.0.1'
compile 'io.huq:sourcekit:1.1.19'
compile 'com.writingminds:FFmpegAndroid:0.3.2'
compile 'org.bytedeco:javacv:1.2'
compile 'org.bytedeco:javacpp:1.2.3'
testCompile 'junit:junit:4.12'
compile project(':colorselector')
compile files('libs/jar_sans.jar')
nostel commented 6 years ago

Hi, guy. I'm sure this is a bug from Firebase Testlab. And I found the steps to reproduce it and a quick fix:

Steps to reproduce:

Here is a quick Cheat:

Replace: final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { Gson gson = new Gson(); } }, 5000); With: Gson gson = new Gson();

So basically, create a new Gson () instance immeadiately when app launch will prevent the crashes on Firebase test lab.

Hope that help you!

ispam commented 6 years ago

I think this is related to this: https://github.com/googlesamples/google-services/issues/358

tomerpetel commented 6 years ago

@ispam Why do you think it's related? @nostel So do you think it's the pre-launch report bug? I was about to upload a version to production but I'm not sure now...

ispam commented 6 years ago

@tomerpetel Because Im experiencing the same issue only in production. Tested on 4 Real devices from API 19-23. Plus im not rlly using GSON but i know some other libraries rely big on it.

tomerpetel commented 6 years ago

@ispam thanks for the answer. So if I'm understanding it right the fix was pushed to 100% of Android users (version v12.8.74) 3 days ago. So why I'm still seeing it in a report from 2 days ago?

ispam commented 6 years ago

@tomerpetel Its been rolling out, but currently not update on my phones yet.

tomerpetel commented 6 years ago

@ispam Thanks mate 👍

anudeepreddygopu commented 6 years ago

Hey,

I am getting this issue all of a sudden. Is there anything which should be fixed. Everything seemed to work fine until today. I have rolled out a build which was not at all related to this, but it started crashing.

Fatal Exception: java.lang.VerifyError: Verifier rejected class com.google.gson.Gson: void com.google.gson.Gson.() failed to verify: void com.google.gson.Gson.(): [0x5] register v0 has type Precise Reference: com.google.gson.Gson$1 but expected Reference: com.google.gson.reflect.TypeToken (declaration of 'com.google.gson.Gson' appears in /data/app/com.appname-aj6tBqViZ3DxYl_xUqAW_g==/base.apk:classes2.dex) at com.google.gson.GsonBuilder.create(GsonBuilder.java:569)

How can I fix this? It seems like this error came only on the pixel device.

tomerpetel commented 6 years ago

@anudeepreddygopu see @ispam answer, fix has been released but it'll take time until propagated to all devices

jasonandress commented 6 years ago

For me it was a pre-launch update on Google Publish. Once I opted out for pre-signing, everything passed. Go to the settings under pre-launch reports, go down to "Pre-launch report version", and select to opt-out so your app doesn't get recompiled.