143
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class); //exception is here

        // Signed in successfully, show authenticated UI.
        System.out.println("google token ---> " + account.getIdToken());
    } catch (ApiException e) {
        // The ApiException status code indicates the detailed failure reason.
        // Please refer to the GoogleSignInStatusCodes class reference for more information about this error.
        e.printStackTrace();
    }
}
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Arsen Budumyan
  • 1,431
  • 2
  • 7
  • 5
  • 2
    Did you read the 2 lines you have in comments in the `catch` block? – pleft Nov 22 '17 at 15:14
  • 18
    Actually I did but there is nothing about status code 10:, so I don't get it. – Arsen Budumyan Nov 22 '17 at 15:47
  • 3
    @ArsenBudumyan in the page for ´GoogleSignInStatusCodes` there is actually a link in the first paragraph that sends you to https://developers.google.com/android/reference/com/google/android/gms/common/api/CommonStatusCodes and from there to https://developers.google.com/android/reference/com/google/android/gms/common/api/CommonStatusCodes.html#DEVELOPER_ERROR Also, if you run the debugger and use AndroidStudios `Evaluate Expression` function, you can look at the `e`, your `ApiException` or `completedTask.exception` to view the field `mStatus` which actually shows `DEVELOPER_ERROR` – Benjamin Basmaci Oct 23 '19 at 07:29

28 Answers28

223

Quoting the documentation:

Certain Google Play services (such as Google Sign-in and App Invites) require you to provide the SHA-1 of your signing certificate so we can create an OAuth2 client and API key for your app.

If you are using Firebase and try on the debug app :

1. First, get your SHA-1 debug key :

  1. Click on Gradle (From Right Side Panel, you will see Gradle Bar)
  2. Click on Tasks
  3. Click on Android
  4. Double Click on signingReport (You will get SHA-1 and MD5)

2. Add your key to your Firebase project :

  1. Go to Project settings -> SHA certificate fingerprints -> Add SHA-1 key of debug app.

  2. Then you can update your google-services.json file in your Android project.

Its works for me.

Akshay
  • 6,029
  • 7
  • 40
  • 59
Johnny
  • 2,989
  • 4
  • 17
  • 28
  • 5
    In my case I had to add the SHA-1 fingerprint because I was using Google Sign-In service which requires it. – vovahost Aug 16 '19 at 15:11
  • 3
    Thanks, buddy. you made my day. I was struggling with the wrong SHA1 and resulted in above ERROR 10. My issue was, the project were built on embedded keystore() and SHA1 were generated from default in the android root. – Faisal Aug 29 '19 at 16:28
  • 4
    Not sure if things have changed or I do something wrong but after adding SHA-1 to google API console I unable to add it to Firebase. So I skipped step 2 and still get working solution. – user9440008 Nov 01 '19 at 11:35
  • 1
    @Johnny Johnson Thank you, it worked very perfectly :) – deeptimancode Mar 01 '20 at 08:59
  • Thank you, your answer helped me solve the issue :) – Carlos Parra Jul 09 '20 at 12:06
  • As of latest firebase adds the credentials for you, no need; but you have to as well add the sha1 from android store (https://play.google.com/console/developers//app//keymanagement) to firebase for it to work on release (additionally to the release sha1) – shredding Oct 05 '20 at 13:22
  • it's enough to add sha1 certificate to firebase project and update your google-services.json file in Android project to work on emulator. – NeoFar Jan 08 '21 at 06:50
  • I get the same error as user9440008. It says: Error when creating. The package name and provided fingerprint pair are already used in this or another project by the client ID for Android OAuth 2.0. How can I create a new OAuth-Client-ID in the google developer console? – LoveCoding Jan 11 '21 at 17:05
  • Thanks a lot, it solved my problem. I skipped 2. Add new credentials to API Console, but it worked fine – Alexandre Cavalcante Apr 21 '21 at 21:17
  • Thx @Johnny! in case someone can't find the Tasks in Gradle tab see [here](https://stackoverflow.com/a/67636646/5144446) – Tomer Petel Nov 09 '21 at 20:07
  • It's 2022 and the production (Google Play SHA-1) is in the Play Store itself. Read https://stackoverflow.com/a/72440651 on why you have 3 different SHA-1s and you must be careful. – Aidin May 30 '22 at 22:49
  • You can get SHA-1 with the comand-line too: `./gradlew signingReport` – Michał Dobi Dobrzański Nov 14 '22 at 10:48
45

This status code means that you are providing unknown server client id. In https://console.developers.google.com/apis/credentials in your project you might need to generate: OAuth client ID -> Web Application and use this web application client id here:

val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestIdToken(webApplicationClientId)
        .requestEmail()
        .build()
Adam Johns
  • 35,397
  • 25
  • 123
  • 176
bojan
  • 870
  • 9
  • 7
  • 2
    It might be also that you haven't add or misspelled your package in the same https://console.developers.google.com/apis/credentials but in Oauth 2.0 Client ID for Android. – bojan Nov 25 '17 at 03:21
  • 26
    Why do I need `Web application` instead of `Android`? I'm not even using a browser for google-auth (but rather integrated account), what origins are we talking about? – deathangel908 Apr 03 '18 at 11:23
  • 5
    Be sure to select current project on **console.developers.google.com**, because if you open it from a link(firebase docs page) there could be selected another project, as simple as that, shit! – Choletski Aug 03 '18 at 13:44
  • 6
    The key is Web Application, not Android – B-GangsteR Sep 17 '18 at 08:13
  • @B-GangsteR Dude, you are savior! – coderpc Aug 19 '20 at 04:37
  • 3
    I'v the same message and resolved by using "web" clientid instead with "android" clientid, I think, the reason is that the retutuned idtoken is used for web-application (use https request to get extra info). ref doc, [developers.google.com/identity/sign-in/android](https://developers.google.com/identity/sign-in/android/backend-auth) "When you configure Google Sign-in, call the requestIdToken method and pass it your server's **web** client ID." – wade.ec Jan 11 '21 at 11:59
  • 1
    Don't forget to download google-services.json again from the Firebase after finishing setup and adding you app's fingerprints – B-GangsteR Mar 25 '21 at 18:19
  • Note that you probably need one `Web` and **3** `Android` ones for it to work everywhere: https://stackoverflow.com/a/72440651 – Aidin May 30 '22 at 22:45
  • 1
    **IT SHOULD USE WEB KEY, NOT ANDROID KEY** you saved my life!!! – Sang Jul 17 '22 at 08:17
  • 1
    you need to create the Android key with correct sha1 finger print and bundle name, **even if you do not use it**. Otherwise, 12500 error will occur and **none** of the fixes [here](https://stackoverflow.com/questions/47632035/google-sign-in-error-12500) work – Sang Jul 17 '22 at 13:16
  • @deathangel908 I'm guessing that you need to provide the Web OAuth2 server ID, even on Android, because the Android client uses a Web redirect at the end of the authentication flow. – Luke Hutchison Jul 18 '23 at 22:00
29

I have solved this problem using these steps:

1). Goto https://console.developers.google.com/ and delete (Android Client) if it is created.

2). Click on Create Credential and click on OAuthClientID and select android

3). copy and paste your SHA 1 fingerprint

4). type your package name then saved

5). Goto console.firebase.com

6). download google-service.json move it into your project into app directory

7). Open google-service.json and find out client id type 3 and use it as default_web_client_id

8). Run your App

Danish Ahmed
  • 490
  • 5
  • 6
  • 2
    I have more than one type 3 reference – Dani Nov 20 '19 at 23:37
  • Thanks for help. It nowhere mention. "oauth_client": [ { "client_id": "686324707383-hvqft1dmcn363e92v2qb5fqthd65l96g.apps.googleusercontent.com", "client_type": 1, "android_info": { "package_name": "com.example.calendardemotwo", "certificate_hash": "2ca5f25b0b4f6b2beaba534af36a255ff89ee4c3" } }, { "client_id": "686324707383-55etv3nkvb6u2jod76njvc6ijn9e5cp6.apps.googleusercontent.com", "client_type": 3 } ], – Deepak Gupta May 17 '20 at 09:59
  • Thank you. this solved the problem for me. – Sab Oct 03 '21 at 12:20
18

I have this thing in 2-3% of the occasions in production and it works seamlessly for everyone else.

Given the sheer amount of problems and differing answers this is causing, it's fair to say that this is a problem on behalf of firebase. They've implemented a catch-all error routine that is just bad api design. The api must point to the problem where it fails.

A long term solution is to convince firebase that this is bad-api design and they need to do better.

We're strong together.

Please write a support ticket to firebase roughly with this:

Hey Firebase Support,

i have a com.google.android.gms.common.api.ApiException: 10 in my app.

The problem for me - and for a lot of people all over the forums - is that your api seems to have a catch-all error routine that roughly speaking is saying "something went wrong, please fix it".

You could release your support team and a lot of people from headache if you would fix this.

The API should be able to figure what's wrong and give a better error message from the context where it occurs.

It's really a burden and I think that since firebase has a quasi-monopoly on these matter on Android it's your obligation to do better.

While this is obviously not your fault, I'd like to encourage you to escalate this problem.

It's fundamentally bad api design and harms an otherwise great product.

Thanks anyway.

shredding
  • 5,374
  • 3
  • 46
  • 77
  • 2
    Glorious. All I need now is the link to the support ticket! – Chris Neve Mar 05 '21 at 16:42
  • You have to open a new one on firebase. – shredding Mar 05 '21 at 20:07
  • 3
    For the ones who ask: https://firebase.google.com/support/troubleshooter/report/bugs – tpbafk Jun 24 '21 at 09:13
  • Yes, Yes, Yes! It's happening only 2~3% but it prevents the user from logging in via Google until they reinstall the app! It sucks. Any update or workaround or findings, @shredding? – Aidin May 30 '22 at 20:18
  • Update: I found that I was using the wrong SHA-1! And the reason that it was happening only 1 in 30 times for me was that I had the same build version number between prod (Play Store) and dev (Android Studio), so the OS was caching the APKs. Read the full story + solution here: https://stackoverflow.com/a/72440651 – Aidin May 30 '22 at 22:47
14

My problem was trying to use Google Sign-In yet I had accidentally enter the wrong SHA1 in Firebase. Try running Gradle > Your app name > Tasks > android > signingReport, get your SHA1 key and compare it with the one on Firebase. If they are different, change the Firebase SHA1 key to match the one you got from the signingReport. Don't forget to also download the google-services.json afterwards.

Andrew Chelix
  • 1,012
  • 11
  • 16
  • Technically there are 3 SHA-1s. You can keep them separate and have 3 Client IDs for them: https://stackoverflow.com/a/72440651 – Aidin May 30 '22 at 22:47
11

The ApiException Error Code 10 is a developer error. You get this error when your firebase app is not well configured. One sure case is when you do not supply the SHA1 fingerprint for your android app when you want to use Firebase authentication with Google Signin. (It is a requirement for Google Signin). So supply the SHA1 fingerprint, download the google-services.json configuration file to your app folder and build. You should be good to go.

Google sign-in is automatically configured on your connected iOS and web apps. To set up Google sign-in for your Android apps, you need to add the SHA1 fingerprint for each app on your Project Settings.

Check this out Common Status Error Codes

landrykapela
  • 442
  • 6
  • 15
  • 1
    please check my issue at https://stackoverflow.com/questions/55235295/google-signin-working-in-release-apk-but-not-on-play-store?noredirect=1#comment97203989_55235295 – Shikhar Mar 19 '19 at 07:12
7

In my case the problem was with the SHA1 and google-services.json file

i solved the problem follow this steps:

1.- Open https://console.cloud.google.com/apis/credentials and delete file at OAuth 2.0 Client IDs

2.- Open https://console.firebase.google.com/ clic gear icon -> Proyect Settings -> Select your Android App -> add fingerprint -> save -> and download google-services.json file

3.- Open your android proyect and replace de google-services.json file -> clic Sync Proyect with Gradle Files

4.- The new default_web_client_id at values works fine for me and solved the problem

vicente esparza
  • 171
  • 2
  • 2
5

that is because you are using the wrong default_client_token_id. to solve this go to the JSON file downloaded from firebase and open it: your client_id is located right after the "certificate_hash":xxxxxxzxzxzzzxzxzxzxzxzx.... good luck :) and I hope it helped.

user10702679
  • 69
  • 1
  • 2
  • This worked for me and really saved me a ton of time. Thanks a lot. You have to copy the client_id to where you put the id in the String values file. – Paul Nov 17 '20 at 03:58
5

Don`t forget to add

<application
...
    <meta-data
    android:name="com.google.android.gms.wallet.api.enabled"
    android:value="true" />
...
</application>

under your manifest file application tag. In my case problem was because of absent this lines.

Csaba Toth
  • 10,021
  • 5
  • 75
  • 121
4

ApiException 10 is a DEVELOPER_ERROR, which means something's wrong with your app configuration.

This answer worked for me, but then I realized our app authenticates with a backend server. So, if your app authenticates with a backend server, you only need to use the web application client ID. But you still need to create client ID of Android type or you're going to get ApiException 12500 . You can read more about it from the documentation. (note that the link has authuser=0)

zeenosaur
  • 888
  • 11
  • 16
3

If you remove this line it will work:

System.out.println("google token ---> " + account.getIdToken());

This is because you don't have the request to the idToken:

.requestIdToken(getString(R.string.google_app_id))

where the app_id will have the value of "OAuth client ID -> Web Application"

Lukas
  • 1,216
  • 12
  • 25
3

When you are doing setup of google login, it normally take Signed keystore hash key. So try with signed APK then it will work. For debugging try to add your debug SHA key on google console.

Abeer Iqbal
  • 1,256
  • 10
  • 10
2

I guess the question is answered. But for me it was a little different. So if some googlers come along this and may have the same problem as I had:

Special Case

  • multiple firebase projects
  • client ids whitelisted
  • installed app through app sharing can't sign up with google

In case anybody is using multiple firebase projects for one application (i.e. for different flavors) and has whitelisted the "external" client ID in Google-Authentication in one project.

Then the solution is, to generate new credentials in the Google APIs console of the "master" / whitelisted project with the sha-1 (found in app sharing) of the other project.

Add new credentials to API Console

  1. Go to Google APIs of whitelisted project
  2. Create new OAuth Client ID
  3. Add everything needed, also package name of other project
  4. Paste the SHA-1 hash from App Sharing of other project

Done

Sorry for my bad english. It's not my mother tongue.

JacksOnF1re
  • 3,336
  • 24
  • 55
2

This Error because of Wrong Client Id

GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestIdToken(getString(R.string.default_web_client_id))
                    .requestEmail()
                    .build();

You must pass your server's client ID to the requestIdToken method.

client Id can be found eaisly in google-services.json file

{
      "client_id": "",
      "client_type": 3
    }

No need to go to Credentials page in the GCP Console.

Please to follow instructions from

https://firebase.google.com/docs/auth/android/google-signin

Islam Alshnawey
  • 692
  • 10
  • 15
2

If you came here because of an error with the Google Login iOS & Android Unity library, this is what helped for me.

I changed the Google project and kept getting ApiException: 10. I later found out that it was because you need to use a web client, not an Android one.

If you want to check if you have a web client or an Android one, open the client_secret_(some text).apps.googleusercontent.com.json file - if it starts with {"web" it's a web client.


Step by step instructions for replacing the client:

  1. Remove the client_secret_(some text).apps.googleusercontent.com.json file from your Unity project. If you have a plist file (for iOS) too, don't remove it.
  2. Go here, click "Configure a project" and configure an Android client.
  3. Go to the Google Cloud Credentials page (select your project if necessary), download the auto-generated web client and place it in your project.
  4. Click Assets > External Dependency Manager > Android Resolver > Force Resolve.
  5. Change the client ID passed to LCGoogleLoginBridge.InitWithClientID in the script where you call this function.
  6. Build and see if the issue has been resolved.
Narek Torosyan
  • 99
  • 2
  • 10
2

I was facing the same issue. I was using SHA-1 credentials. But the problem was that I was directly installing the app to the testing device by using the Run button of Android Studio. In this way, I hadn't defined the debug keystore in Android Studio with which I had created the SHA-1 fingerprint.

To set the debugKeyStore Where is debug.keystore in Android Studio

Talha Akbar
  • 621
  • 4
  • 17
1
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestIdToken(OAUTH_2_CLIENT_ID)
    .requestEmail()
    .build()
val mGoogleSignInClient = GoogleSignIn.getClient(this, gso)
val signInIntent = mGoogleSignInClient.signInIntent
startActivityForResult(signInIntent, GOOGLE_LOGIN)

OAUTH_2_CLIENT_ID is Web client (auto created by Google Service). Not Android

DaFengA
  • 31
  • 3
1

If you don't use your own backend server you don't need to provide OAuth 2.0 client id (as it said here). Of course check that you provided correct SHA-1 code, but remember that you are providing the release variant SHA-1 key, so this error might appear when you are trying to use Google SignIn with debug app variant. So you have 2 options:

  1. Build and run release APK
  2. Add your debug SHA-1 key to the Firebase console and then you'll be able to run your debug APK without this exception
the korovay
  • 563
  • 4
  • 16
1

Possible solve:

If you once renamed project's package check that package name in AndroidManifest.xml and applicationId in app gradle file are the same. It helped me when I named applicationId like my application package

Nik
  • 29
  • 4
  • 1
    bro, i spent like a week looking for the problem and your solution works for me... – Francisco Mendoza Dec 30 '21 at 06:22
  • 1
    In my case the problem was also with package name of my application class (in which my auth methods are working). For example, if my application package name is "com.my_app.application", then in firebase console (https://console.firebase.google.com) in my project settings I had to write Package name = "com.my_app.debug" (and also in file google-services.json in my project). Also, if you move auth methods to another class, you will have to change package name in firebase console and in file google-services.json. – Maxim Jan 08 '23 at 15:35
1

From my experience it is a problem with SHA1. Solution which worked for me:

  1. Delete OAuth listings if you have created any (probably optional)
  2. Launch this command in your project terminal keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android and copy SHA1 fingerprint.
  3. Go to Firebase console, click gear on your project and delete old fingerprint's. Replace them with the one you copied during step 2
  4. Download new google-services.json file and replace the old one
  5. Sync project with Gradle files.

Should be working :)

Giedrius Šlikas
  • 1,073
  • 12
  • 12
1

I fixed this issue by going to

PlayConsole -> Setup -> App Integrity -> App signing -> SHA-1 certificate fingerprint (Copy)

.

Then Go to

Firebase console -> Select your project -> Add fingerprint -> Paste the SHA-1 key (which you copied from PlayConsole).

Ahamadullah Saikat
  • 4,437
  • 42
  • 39
0

In my case, it resolved by reconnect my Android Studio to Firebase.

Kirill_code
  • 129
  • 1
  • 9
0

I was getting the same error but I obtained the web client token from Google Cloud Console and placed it right where the GoogleSignInOptions is declared. Replace the

.requestIdToken("getString(R.string.default_web_client_id)")

with the web client ID for your particular Google Cloud project.

Muiruri
  • 45
  • 6
0

I were using this command from documentation ...

 keytool -exportcert -keystore ~/.android/debug.keystore -list -v

i just change it to

 keytool -exportcert -keystore ./.android/debug.keystore -list -v

and using SHA-1 and copy it into firebase android section. it just wokrs fine.

0

For me the mistake was simple. I had initialized google signin options outside the oncreate callback.

m4n0
  • 29,823
  • 27
  • 76
  • 89
OtienoSamwel
  • 316
  • 2
  • 12
0

If using Google Internal Sharing for testing, make sure to add also the SHA string of your internal sharing (Setup - Internal App sharing in Google Play Console)

marmay
  • 39
  • 3
0

I solved this issue with the following steps:

  1. Filling the requirement of **OAuth consent screen ** in https://console.developers.google.com/

  2. In Create credentials needs first time to choose Android then web in Android you need SHA-1 that can generate with the below steps: (go to the Android studio and select the Gradle button on the right side and Choose your app module > Tasks > android > signingReport to generate the SHA-1 for debugging mode and select the SHA1 in debug config and enter the package name correctly ) and in web after filling the requirement use the below code:

    GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(getString(R.string.web)).requestEmail().build()
    

consider that R.string.web is a web client id that can find in a JSON file.

-2

I solve this problem by redo my Firebase Auth connection again.

  1. Click the right top little square to login to your google account
  2. Go to the Tool - > Firebase
  3. Select the Authentication
  4. Connect

After that it may say you are already connect, but you need to update the connection. After that it works fine. I think sometime Android Studio mixed up with different Firebase account.

MaxV
  • 2,601
  • 3
  • 18
  • 25
Josepharaoh
  • 137
  • 2
  • 3