google-services icon indicating copy to clipboard operation
google-services copied to clipboard

App crash onActivityResult GoogleSignInApi

Open hendrawd opened this issue 10 years ago • 109 comments

It is the library that i used:

compile 'com.google.android.gms:play-services-auth:9.0.0'

Here is the code for sign in

Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);

And here the code onActivityResult

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        if (resultCode == RESULT_OK) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            handleSignInResult(result);
        } else {
            showSignInFailedMessage();
        }
    }
} 

Stack trace:

Fatal Exception: java.lang.RuntimeException: Unable to resume activity {com.myapp/com.myapp.activity.LoginActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65538, result=0, data=null} to activity {com.myapp/com.myapp.activity.LoginActivity}: java.lang.NullPointerException
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2583)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2611)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2097)
       at android.app.ActivityThread.access$600(ActivityThread.java:133)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:4810)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65538, result=0, data=null} to activity {com.myapp/com.myapp.activity.LoginActivity}: java.lang.NullPointerException
       at android.app.ActivityThread.deliverResults(ActivityThread.java:3149)
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2570)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2611)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2097)
       at android.app.ActivityThread.access$600(ActivityThread.java:133)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:4810)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.NullPointerException
       at com.google.android.gms.internal.zznu.onCreate(Unknown Source)
       at com.google.android.gms.internal.zzpc.zza(Unknown Source)
       at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:176)
       at com.myapp.activity.BaseActivity.onActivityResult(BaseActivity.java:40)
       at com.myapp.activity.LoginActivity.onActivityResult(LoginActivity.java:165)
       at android.app.Activity.dispatchActivityResult(Activity.java:5192)
       at android.app.ActivityThread.deliverResults(ActivityThread.java:3145)
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2570)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2611)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2097)
       at android.app.ActivityThread.access$600(ActivityThread.java:133)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:4810)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
       at dalvik.system.NativeStart.main(NativeStart.java)

screen shot 2016-06-21 at 3 01 06 pm

hendrawd avatar Jun 21 '16 08:06 hendrawd

+1

hmedat avatar Jul 13 '16 11:07 hmedat

+1

idanakav avatar Jul 22 '16 13:07 idanakav

Can anyone reliably reproduce this bug? I would be happy to investigate further if there is a way to make it happen, but right now I don't have much to go on.

samtstern avatar Jul 22 '16 15:07 samtstern

Similar me

phantuanphong avatar Aug 19 '16 03:08 phantuanphong

@samtstern I got the error from Crashlytics dashboard, and it is from my users. I don't know how to reproduce the bug reliably :(

hendrawd avatar Aug 19 '16 04:08 hendrawd

I got same issue on Xiaomi Mi 3w os is 6.0.1 but i got issue because i didnt check resultCode == RESULT_OK

manthan5493 avatar Aug 29 '16 10:08 manthan5493

@manthan5493 It still happens too even we check for RESULT_OK. This is the code snippet from my onActivityResult

if (requestCode == RC_SIGN_IN) {
    if (resultCode == RESULT_OK) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        handleSignInResult(result);
    } else {
        CustomLogger.showLog(this, "Result from on activity result is not ok " + resultCode);
        showSignInFailedMessage();
    }
}

hendrawd avatar Aug 29 '16 10:08 hendrawd

I got same issue too from my users: Android 5.0 on Xiaomi Mi 4i (ferrari) Android 5.1 on Xiaomi Mi 4c (libra)

Library that I used: compile 'com.google.android.gms:play-services-auth:9.0.2'

Any solutions?

indraazimi avatar Sep 17 '16 08:09 indraazimi

@indraazimi @manthan5493 this seems to be isolated to Xiaomi devices (I don't think it's a coincidence). Does either of you know if there are any particular modifications common to those devices? Are those users in China? I don't have any Xiaomi devices handy.

samtstern avatar Sep 20 '16 16:09 samtstern

It happens in samsung devices as well

olx-gaurav-mishra avatar Sep 21 '16 07:09 olx-gaurav-mishra

@olx-gaurav-mishra are you able to reproduce this? If so that would be extremely helpful, we need to capture some additional logs.

As for the Xiaomi devices, it appears to me after some research that Xiaomi devices don't support Google Play Services natively and Play Services must be side loaded. If that's the case, I would not be surprised to see this and other strange failures happening.

samtstern avatar Sep 21 '16 15:09 samtstern

Well its not reproducible directly....you can only find crashes on crashlytics.....:-(

olx-gaurav-mishra avatar Sep 22 '16 05:09 olx-gaurav-mishra

This deliverResults flavor of issues (many very similar but slightly different crashes) is by far the main reason for crashes on our apps in Crashlytics. It seems to be related to old versions of the Google Play Services on the user's devices. It happens a lot every time we update the Google Play Services dependency and it gradually reduces over time. It is probably also related to using GoogleApiClient::enableAutoManage() and it indeed occurs on many devices not just Xiaomi. It also does not depend on the user's location since we are seeing it a lot for users currently in Spain. Additionally, this kind of crashes did not occur some months ago, but i am not sure if it only affects newer Google Play Services versions or if it started to occur due to switching from manual handling to the enableAutoManage() calls.

jrgonzalezg avatar Sep 22 '16 13:09 jrgonzalezg

+1

imidhuntv avatar Sep 24 '16 15:09 imidhuntv

Some of my users are also experiencing the same issue. For my users it happens for Xaiomi devices. Mi 4i (Android version 5.0.2) - 57% Redmi Note 3 (Android version 5.1.1) - 29% MI MAX (Android version 6.0.1) - 14 % Any fix?

imidhuntv avatar Sep 26 '16 07:09 imidhuntv

@imidhuntv thanks for the additional reports. Since Xiaomi devices do not natively support Google Play Services I don't believe there's anything we can do for those users. It's hard to know what version of Play Services they are running and if they got the APK from a trusted source.

If anyone can reproduce this on a non-Xiaomi device that would be hugely valuable to investigating.

samtstern avatar Sep 26 '16 16:09 samtstern

I removed enable auto manage and the crashes have reduced a lot...now it is crashing very less

olx-gaurav-mishra avatar Sep 29 '16 05:09 olx-gaurav-mishra

@olx-gaurav-mishra Thanks for confirming that!

With respect to the affected devices, just by looking at a few of the crashes related to this i see at least several Samsung, LG and Huawei devices, although few of them seem to be the latest devices from these manufacturers. Still some of them are popular devices like the S6, and there are surely more devices on the remaining issues i have in Crashlytics since they are so many due to small differences like line number offsets on the platform classes through the Android versions.

It seems to me that it may be possible to at least stop sending those "results" mentioned in the crashes if they are being sent by the auto manage features of Google Play services, by doing some null checks before sending them.

jrgonzalezg avatar Sep 29 '16 07:09 jrgonzalezg

@olx-gaurav-mishra that's very interesting. I will mention that to the team as well, see if that gives them any hint as to where to look.

Also would you mind sharing the code of the Activity you were using with enableAutoManage?

samtstern avatar Sep 29 '16 14:09 samtstern

@olx-gaurav-mishra how do you implement signin without enableAutoManage?

staticmetal avatar Oct 11 '16 03:10 staticmetal