Google signin not working on release version of android

瘦欲@ 提交于 2019-12-12 01:54:18

问题


I am getting problem for my current app. My OAuth2.0 the SHA1 is correct and generated from keystore file of release version. My problem is I am receiving resultCode =0 everytime on onActivityResult. I print out value of intent and got below: googleSignInStatus=Status{statusCode=INTERNAL_ERROR, resolution=null} But, if I run it on debug mode login working perfectly and for this case value of intent is: googleSignInAccount=com.google.android.gms.auth.api.signin.GoogleSignInAccount@31976389]

Do anybody knows how to solve this problem. NOTE: Somewhere I found one post they recommend to put Email and Project name on OAuth Contest Screen; I already tried that and still not working.


回答1:


Obviously first check your release sha1 key is correct or not. But issue here was different. I am using new google play services (i.e.compile 'com.google.android.gms:play-services:8.4.0'). And issue could be solved by modifying GoogleSignInOption object. Instead of:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail()  
       .requestIdToken("YOUR_WEB_API_ID.apps.googleusercontent.com")
                    .build();

I use :

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(new Scope(Scopes.PLUS_LOGIN))
                .requestScopes(new Scope(Scopes.PLUS_ME))
                .requestEmail()
                .build();

This solves error returning statusCode=INTERNAL_ERROR . Then this gso object could be used for creating GoogleApiClient as shown below:

 mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this, this)
                .addApi(Auth.GOOGLE_SIGN_IN_API,gso)
               // .addApi(Plus.API, null)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
               // .addScope(Plus.SCOPE_PLUS_LOGIN)
                .build(); 


来源:https://stackoverflow.com/questions/36473665/google-signin-not-working-on-release-version-of-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!