Google sign-in Android with Firebase - statusCode

2019-01-18 02:58发布

I try to implement Google login in my Firebase connected Android app. When I run the app and press Google Sign In button - nothing happen. And I receive this error in onActivityResult: Status{statusCode=DEVELOPER_ERROR, resolution=null}.

My code looks like this:

     protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == REQUEST_CODE_GOOGLE_LOGIN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);

        if (result.isSuccess()){
            GoogleSignInAccount account = result.getSignInAccount();
            String emailAddres = account.getEmail();
            getGoogleQAuthToken(emailAddres);
        }
    }
}

         private void getGoogleQAuthToken(final String emailAddres){
             AsyncTask<Void,Void,String> task = new AsyncTask<Void, Void, String>() {
                 String errorMessage = null;

                 @Override
                 protected String doInBackground(Void... params) {
                     String token = null;
                     try {
                         String scope = "oauth2:profile email";
                         token = GoogleAuthUtil.getToken(MainActivity.this, emailAddres, scope);
                     } catch (IOException transientEx) {

                         errorMessage = "Network error: " + transientEx.getMessage();
                     } catch (UserRecoverableAuthException e) {
                         Intent recover = e.getIntent();
                         startActivityForResult(recover, MainActivity.REQUEST_CODE_GOOGLE_LOGIN);
                     } catch (GoogleAuthException authEx) {
                         errorMessage = "Error authenticating with Google: " + authEx.getMessage();
                     }
                     return token;
                 }

I've added JSON config file in app/ directory and added dependencies:

     buildscript {
repositories {
    jcenter()
}

dependencies {
    classpath 'com.google.gms:google-services:1.5.0-beta2'
}
     }


     dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.+'
compile 'com.firebase:firebase-client-android:2.3.0+'

/* For Google Play Services */
compile 'com.google.android.gms:play-services-safetynet:8.3.0'
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile 'com.google.android.gms:play-services:8.3.0'

compile('com.afollestad.material-dialogs:core:0.8.3.0@aar') {
    transitive = true
}

/* Firebase UI */
compile 'com.firebaseui:firebase-ui:0.2.2'

compile 'com.android.support:cardview-v7:23.1.+'
compile 'com.android.support:recyclerview-v7:23.1.+'
compile 'com.android.support:design:23.1.+'


     }
     apply plugin: 'com.google.gms.google-services'

I am looking for solution hours already... Please help!!

11条回答
放我归山
2楼-- · 2019-01-18 03:26

I had the same issue and I got it working by doing these steps:

1. Add DEBUG_KEYSTORE SHA1 fingerprint to the firebase project. use the following command(MAC/LINUX)

keytool -exportcert -list -v \-alias androiddebugkey -keystore ~/.android/debug.keystore  

2. Now Generate a signed apk of your project. The process includes generating a keystore for your app's release version. Copy the path of the newly generated .jks file.

3. Now generate RELEASE_KEYSTORE SHA1 fingerprint using the following command

keytool -list -v -keystore FULL_PATH_TOJKS_FILE -alias ALIAS_NAME

4. Copy the new SHA1 from the output and add it as another SHA1 fingerprint in your firebase application console.

Now you are good to go! ---- Hope! it helps.

查看更多
聊天终结者
3楼-- · 2019-01-18 03:30

I had the same issue. After 2 days of pain, I observed that my release SHA1 was incorect (I used to get it using the keytool in java/bin and it gave me a bad SHA1. Probably because now Android Studio uses its own java package and not the JDK). Better way to get the corect SHA1 here SHA-1 fingerprint of keystore certificate

查看更多
啃猪蹄的小仙女
4楼-- · 2019-01-18 03:32

DEVELOPER_ERROR means Google Play services was unable to find a matching client from the console based on your SHA1 and package name. You can add SHA1s in the settings page on the Firebase console for a given package name, or add a new package name through the Add Firebase to your Android app button.

In general, some things to check for:

  • Make sure your package name is what you expect - e.g. its the one in your build.gradle, and its not being overriden in a build variant or product flavor.
  • Make sure you have registered your debug and release SHA1 keys in the console.
查看更多
混吃等死
5楼-- · 2019-01-18 03:33

If Google Play App Signing is enabled for your app, then it will replace your release signing key with the one on googles server before publishing. You can check if it is enabled from the Google Play Console -> Release Management -> App Signing.

In my case, I had to copy the SHA1 from the 'App signing certificate' section and add it to the Firebase projects general settings section, regenerate the json file, add it to the project and reupload the apk, and the error was resolved.

查看更多
孤傲高冷的网名
6楼-- · 2019-01-18 03:35

Click Here (Google Developer gide line) and create new project for Firebase console this link is set default setting, so you don't need to add it manual

查看更多
Emotional °昔
7楼-- · 2019-01-18 03:37

I think you need to change your play-service version.

See Firebase Android Codelab to add Firebase Auth dependency to your app/build.gradle file.

Try to update your play-service in gradle as below:

/* For Google Play Services */
...
compile 'com.google.android.gms:play-services:9.0.0'
...

DEVELOPER_ERROR :

The application is misconfigured. This error is not recoverable and will be treated as fatal. The developer should look at the logs after this to determine more actionable information.

查看更多
登录 后发表回答