Google SignIn API Exception 10

42,557

Solution 1

This error might happen if you are not using same project at console.developers.google and console.firebase.google.com. If project is same at both console make sure you have add your SHA1 Key properly. Get SHA1 from Android studio.

  1. Open Android Studio
  2. Open your Project
  3. Click on Gradle (From Right Side Panel, you will see Gradle Bar)
  4. Click on Refresh (Click on Refresh from Gradle Bar, you will see List Gradle scripts of your Project)
  5. Click on Your Project (Your Project Name form List (root))
  6. Click on Tasks
  7. Click on Android
  8. Double Click on signingReport (You will get SHA1 and MD5 in Run Bar(Sometimes it will be in Gradle Console))
  9. Select app module from module selection dropdown to run or debug your application 
 You also need to get google-services.json from firebase console and put into your project.

Solution 2

I landed into the same problem and wasted hours. On digging deeper into OAuth and OpenId, I figured out the reason. We are doing a conceptual error here.

For android or any other platform (except web), you need to create at least two types of client id in the same project of google API console. These Client ID types are:

  1. Web Application
  2. Android

You can create them in any order. While creating Android type Client Id, you need to give package name and SHA1. While creating Web Application Id, you just need to give a name.

You don't need to do anything with any of these id's further until you want to verify the user at your backend. In other words, if you want your backend server to ask google server about this user's information, then only you would need Web Application Id. The conceptual flow is as follows:

  1. First send Web Application Client Id from Android App to Google Sign-in Server as an additional option using requestIdToken(your_web_app_client_id).
  2. You will get back a token in Android app upon user's sign in.
  3. Send this token to your backend.
  4. Now your backend can exchange this token with Google Servers to get user's information

Send this Web Appplication Client Id from Android App to backend server.

Use this Web Application Id if you want to verify user at your backend.

Solution 3

I fixed this problem by this way

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

where my AUTH_ID is enter image description here

Solution 4

The answer for me was that you actually need to combine the two main answers given here:

  1. Make sure that you created Google OAuth client ids for Android (one for Debug and one for release) and then assure that they have assigned the right SHA1 as described in the accepted answer.

  2. Then you also need to create an OAuth client ID for Web and use that one for the actual SignIn:

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestIdToken(WEB_CLIENT_ID)
        .requestEmail()
        .build();               
    

Solution 5

I've found another source of the problem.

In my case the keys were alright, but applicationId field in build.gradle script differed from app's package name.

Small research showed that applicationId field value takes some kind of "precedence" before app's package name conserning Google autentication.

After commenting applicationId line in build.gradle, app autenticates itself in Google by package name.

Share:
42,557
max podgorny
Author by

max podgorny

Updated on July 09, 2022

Comments

  • max podgorny
    max podgorny almost 2 years

    Approaching to the final stage of the authentification, but something is going wrong in handleSignInResult method. It returns Exception code 10 (Developer error) in logs. Google provides comprehensive description:

    The application is misconfigured. This error is not recoverable and will be treated as fatal. The developer is an idiot...

    What should I do to handle this (get an account) and finally retrive values from account?
    Thank you in advance for your help!!!

    MainActivity:

    package ru.podgorny.carcall;
    
    import ...
    
    public class MainActivity extends AppCompatActivity {
    
            SignInButton signInButton;
            public static final int RC_SIGN_IN = 07;
            public static final String TAG = "MainActivity";
            TextView tw1;
            TextView tw2;
    
    
            GoogleSignInOptions gso;
            GoogleSignInClient mGSC;
    
    
            @Override
            protected void onCreate (Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Log.d(TAG, "Activity Works");
            findViews();
    
                gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                        .requestEmail()
                        //.requestProfile()
                        .build();
    
                mGSC = GoogleSignIn.getClient(this, gso); //smth with mGSC variable....
    
                 View.OnClickListener onClickListener = new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onClick2(v);
                    }
                };
                 signInButton.setOnClickListener(onClickListener);
    
    
    
    
        }
    
        private void findViews() {
                Log.d (TAG, "findViews started");
            signInButton = findViewById(R.id.idButtonGoogle);
    
            tw1 = findViewById(R.id.textView1);
            tw1 = findViewById(R.id.textView2);
    
            Log.d(TAG, "Views finded");
    
    
        }
    
        public void onClick2(View view) {
                Log.d(TAG, "onClick started");
            switch (view.getId()) {
                case R.id.idButtonGoogle:
                    signIn();
                    break;
            }
            Log.d(TAG, "OnClick Started");
        }
    
        public void signIn() {
    
            Intent signInIntent = mGSC.getSignInIntent();
            startActivityForResult(signInIntent, RC_SIGN_IN);
            Log.d(TAG, "startActivityForResult works");
    
        }
    
        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            Log.d(TAG, "OnActivityResult started");
            // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
            if (requestCode == RC_SIGN_IN) {
                // The Task returned from this call is always completed, no need to attach
                // a listener.
                Log.d(TAG, "TASK started");
                Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
                handleSignInResult(task);
                Log.d(TAG, "OnActivityResult returned");
            }
        }
    
        private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
            try {
                GoogleSignInAccount account = completedTask.getResult(ApiException.class);//ERROR -- Code 10
                Log.d(TAG, "Account received");
    
    
                updateUI(account);
                Log.d(TAG, "updateUI Launched");
            } catch (ApiException e) {
    
                Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
                updateUI(null);
            }
        }
    
        private void updateUI(GoogleSignInAccount account) {
                if (account!=null) {
                    tw1.setText("OK");
                    tw2.setText("Name: " + account.getGivenName() + ", Family name: " + account.getFamilyName() + ", Email: " + account.getEmail() /*+ " image: " +
                            account.getPhotoUrl()*/);
                }else {
                    tw1.setText("SMTH wrong");
                }
    
            }
    
    }
    
  • max podgorny
    max podgorny about 6 years
    Thank you for answer. At the step 8 I've got an SHA1 from Debug key, but I provided SHA1 code while registered app at google console from my primary key. Does it matter and how can i fix it?
  • Patrick R
    Patrick R about 6 years
    Please use SHA1 generated from singingReport at step 8, and let us know if it works or not.
  • max podgorny
    max podgorny about 6 years
    THANK YOU! It works! But how can I replace a debug key by my own (generated) key?
  • Sam Chen
    Sam Chen almost 4 years
    Perfect answer. Thank you!
  • gulab patel
    gulab patel over 3 years
    i have added all this but still i get this error i have added in firebase also
  • Jan Rozenbajgier
    Jan Rozenbajgier over 3 years
    Did you update your google-services.json after adding SHA 1 to firebase?
  • Nongthonbam Tonthoi
    Nongthonbam Tonthoi over 3 years
    This was my exact problem. I was going crazy thinking what the hell was wrong.
  • papo
    papo over 3 years
    thx man i solved this problem, i send cliendID but android and must be clientID web application
  • Chris Neve
    Chris Neve about 3 years
    I don't understand step 9. What do I do with the signingReport output ?
  • padlanau
    padlanau about 3 years
    Thanks @Syed Umair. This solution works for me
  • DIRTY DAVE
    DIRTY DAVE about 3 years
    Have you tried this in production? It works with debug, but when publishing to app store using release apk, it gives the error again
  • hugo der hungrige
    hugo der hungrige about 3 years
    @DIRTYDAVE As far as I know, this should work. You can check the code here: github.com/johannesjo/super-productivity-android/blob/master‌​/… and download the app here: github.com/johannesjo/super-productivity/releases
  • DIRTY DAVE
    DIRTY DAVE about 3 years
    Thanks hugo, using the web application one is working for me in production. Google makes it so confusing I may have looked through 20+ questions on this GoogleSignIn issue...
  • Hoang Viet Nguyen
    Hoang Viet Nguyen almost 3 years
    If you use Play App Signing, make sure to use SHA1 from its certificate, not your debug or release keystore
  • AXE
    AXE almost 3 years
    That's what solved it for me! I thought only the web key was being used as that's what you send in the request. And couldn't figure out why it was working on my environment and not on my colleague's!
  • Mahmoud Mabrok
    Mahmoud Mabrok almost 3 years
    I was using wrong id instead of your_web_app_client_id
  • Hoàng Vũ Anh
    Hoàng Vũ Anh over 2 years
    It's not work for me :((
  • axita.savani
    axita.savani over 2 years
    @NongthonbamTonthoi Hi, Where should i check for another certificate.
  • Code Name Jack
    Code Name Jack about 2 years
    It works. very weird thing from google though.
  • Sam
    Sam about 2 years
    4 years later, yet saved my day. THANK!