Search code examples
androidfirebasereleasesha1google-signin

Google Firebase signin giving status 12501 (not working), in release build variant and jks SHA


I know this question has been asked by many and have been answered.

So, why am I asking this question again? Cuz I tried those solutions, and I did followed Google docs, followed tutorials and youtube. Still no luck.

Oright, this is what I did in my project.

Project: GoogleSignIn

dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'
        classpath 'com.google.gms:google-services:3.0.0'
      }

Gradle (Module: app)

apply plugin: 'com.android.application'

android {
    signingConfigs {
        config {
            keyAlias 'alias'
            keyPassword 'keypass'
            storeFile file('/home/reoxey/path/to/jks')
            storePassword 'storepass'
        }
    }
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "reoxey.com.googlesignin"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            signingConfig signingConfigs.config
        }
    }
}

dependencies {
    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:appcompat-v7:25.0.0'
    compile 'com.android.support:design:25.0.0'
    compile 'com.google.firebase:firebase-auth:9.8.0'
    compile 'com.google.android.gms:play-services-auth:9.8.0'
    testCompile 'junit:junit:4.12'
}

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

LoginActivity.java

gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.web_client_key))
                .requestEmail()
                .build();

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this, this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();

        findViewById(R.id.sign_in_button).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
                startActivityForResult(signInIntent, RC_SIGN_IN);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RC_SIGN_IN){
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            if (result.isSuccess()){
                Toast.makeText(getApplicationContext(),"Nailed it",Toast.LENGTH_LONG).show();
            }else {
                Snackbar.make(mLoginFormView,result.getStatus().toString(),Snackbar.LENGTH_LONG).show();
                Toast.makeText(getApplicationContext(),"Messed",Toast.LENGTH_LONG).show();

            }
        }
    }

string.xml

<string name="web_client_key">123456789-clientwebapplication.apps.googleusercontent.com</string>

There is no special configuration in manifest, and I believe that I am not missing anything there.

google-services.json

{
  "project_info": {
    "project_number": "{numeric-id}",
    "firebase_url": "https://project--123456789.firebaseio.com",
    "project_id": "project--123456789",
    "storage_bucket": "project--123456789.appspot.com"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:{numeric-id}:android:sfdjgsdkdfgsfs",
        "android_client_info": {
          "package_name": "reoxey.com.googlesignin"
        }
      },
      "oauth_client": [
        {
          "client_id": "{numeric-id}-androidkey.apps.googleusercontent.com",
          "client_type": 1,
          "android_info": {
            "package_name": "reoxey.com.googlesignin",
            "certificate_hash": "{sha1-from-jks-file}"
          }
        },
        {
          "client_id": "{numeric-id}-webapplication.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "{android-key}"
        }
      ],
      "services": {
        "analytics_service": {
          "status": 1
        },
        "appinvite_service": {
          "status": 2,
          "other_platform_oauth_client": [
            {
              "client_id": "{numeric-id}-webapplication.apps.googleusercontent.com",
              "client_type": 3
            }
          ]
        },
        "ads_service": {
          "status": 2
        }
      }
    }
  ],
  "configuration_version": "1"
}

Oright, now Firebase console.

  • created project with package name
  • added sha1 fingerprint generated from jks file
  • enabled authentication for google signin

that's it I guess, hope I provided everything,
so what am I missing here.

When I click on google sign, it gives me an error with 12501 status code. I don't know what's wrong here. Anyone?

Thanks in Advance.


Solution

  • If you are adding all the SHA-1 Finger prints in firebase still you are getting error.then (I was facing this problem. after this steps it's resolved.)Try this steps:

    1.Go to Google Console API credentials Page.

    2.Click the credentials in the Left tab.

    3.Already two default Android and Web OAuth client Id will be present. You have to create One Android Client and One Web 2.0 Client.

    4.Go to Firebase.In project setting ,download google-services.json and paste in app folder.

    (Everything is fine but still you are cannot signin google means maybe OAuth problem. so make sure to create Android and Web client ID.Finally in credential page you have 2 Android Client and Two Web client Id.)

    Fill the OAuth Content Screen also