Flutter: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)

3,767

I also faced this issue..In my case, I tried to implement GoogleSignIn in one of my apps that is already at production level..

When I tried to do this..I also got the same error.. APIException: 10.. looks like yours is also the same case..

I tried many times..but, finally, I ended up compromising and decided not to include GoogleSignIn in my app..

But, again..I solved it..by adding 2 SHA1 keys to the FireBase Project..one for the debug mode and other for release mode..

If I put only debug SHA1 key..it is not working in release mode but working fine in debug mode and if I put only release SHA1 key..it is not working in debug mode but working fine in release mode .

Not sure why is it happening..but it is happening..and somehow it is working fine..

Ok..now..what is debug and release key.. aren't they the same..how do I get them..?

Here it is..

Go to your project in Command Prompt.. then cd android and then type..

gradlew signingReport

It will give the SHA1 keys..

There is one key generated by the debug keystore and the other by the release keystore..

Add both of them to the project..and it works(hopefully)..as it did for me..

Hope it helps..

Note: I'm using Windows..not sure if it is the same process to generate keys on Mac as well..

Share:
3,767
Riley Fitzpatrick
Author by

Riley Fitzpatrick

Updated on December 14, 2022

Comments

  • Riley Fitzpatrick
    Riley Fitzpatrick over 1 year

    I have a Flutter app and I am trying to allow users to sign into their Gmail because I want to be able to list out their emails. When I press my LoginButton, I get prompted with a Gmail login, and I enter in my credentials, but then it goes back to the screen with the LoginButton and I am faced with the error:

    Unhandled Exception: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)

    What I have tried:

    • Added google-services.json to /android/app and added GoogleService-Info.plist to ios/Runner.
    • Enabling gmail for Firebase authentication.
    • Adding my debug SHA1 and SHA256 to my firebase authentication.
    • Filling out the OAuth consent form (I did this after everything else. I don't know if that would affect it.)

    Any ideas? Thanks!

    Here is my code:

    class AuthService {
      final GoogleSignIn _googleSignIn = GoogleSignIn();
      final FirebaseAuth _auth = FirebaseAuth.instance;
      final Firestore _db = Firestore.instance;
    
      Observable<FirebaseUser> user;
      Observable<Map<String, dynamic>> profile;
      PublishSubject loading = PublishSubject();
    
      AuthService() {
        user = Observable(_auth.onAuthStateChanged);
    
        profile = user.switchMap((FirebaseUser u) {
          if (u != null) {
            return _db
                .collection('users')
                .document(u.uid)
                .snapshots()
                .map((snap) => snap.data);
          } else {
            return Observable.just({});
          }
        });
      }
    
      Future<FirebaseUser> googleSignIn() async {
        loading.add(true);
        GoogleSignInAccount googleUser = await _googleSignIn.signIn();
        GoogleSignInAuthentication googleAuth = await googleUser.authentication;
        final AuthCredential credential = GoogleAuthProvider.getCredential(
          accessToken: googleAuth.accessToken,
          idToken: googleAuth.idToken,
        );
        FirebaseUser user = (await _auth.signInWithCredential(credential)).user;
    
        updateUserData(user);
        print("signed in " + user.displayName);
    
        loading.add(false);
        return user;
      }
    
      void updateUserData(FirebaseUser user) async {
        DocumentReference ref = _db.collection('user').document('user.uid');
    
        return ref.setData({
          'uid': user.uid,
          'email': user.email,
          'photoURL': user.photoUrl,
          'displayName': user.displayName,
          'lastSeen': DateTime.now()
        }, merge: true);
      }
    
      void signOut() {
        _auth.signOut();
      }
    }
    
    final AuthService authService = AuthService();
    
    Launching lib\main.dart on Android SDK built for x86 in debug mode...
    Initializing gradle...
    Resolving dependencies...
    Running Gradle task 'assembleDebug'...
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    Built build\app\outputs\apk\debug\app-debug.apk.
    Installing build\app\outputs\apk\app.apk...
    I/FA      ( 4974): Tag Manager is not found and thus will not be used
    W/d.memail.memai( 4974): Accessing hidden method Landroid/view/accessibility/AccessibilityNodeInfo;->getSourceNodeId()J (light greylist, reflection)
    W/d.memail.memai( 4974): Accessing hidden method Landroid/view/accessibility/AccessibilityRecord;->getSourceNodeId()J (light greylist, reflection)
    W/d.memail.memai( 4974): Accessing hidden field Landroid/view/accessibility/AccessibilityNodeInfo;->mChildNodeIds:Landroid/util/LongArray; (light greylist, reflection)
    W/d.memail.memai( 4974): Accessing hidden method Landroid/util/LongArray;->get(I)J (light greylist, reflection)
    Syncing files to device Android SDK built for x86...
    I/OpenGLRenderer( 4974): Initialized EGL, version 1.4
    D/OpenGLRenderer( 4974): Swap behavior 1
    D/        ( 4974): HostConnection::get() New Host Connection established 0xd831cb40, tid 5016
    D/EGL_emulation( 4974): eglCreateContext: 0xec485d80: maj 2 min 0 rcv 2
    D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
    D/        ( 4974): HostConnection::get() New Host Connection established 0xd3f22780, tid 5005
    D/EGL_emulation( 4974): eglCreateContext: 0xec485a80: maj 2 min 0 rcv 2
    D/EGL_emulation( 4974): eglMakeCurrent: 0xec485a80: ver 2 0 (tinfo 0xec483c50)
    D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
    I/d.memail.memai( 4974): Background concurrent copying GC freed 35614(5MB) AllocSpace objects, 27(1068KB) LOS objects, 50% free, 1856KB/3MB, paused 498us total 214.123ms
    I/OpenGLRenderer( 4974): Davey! duration=719ms; Flags=1, IntendedVsync=65710145267, Vsync=66060145253, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=66062704600, AnimationStart=66062759800, PerformTraversalsStart=66062789600, DrawStart=66070699600, SyncQueued=66071765200, SyncStart=66073102800, IssueDrawCommandsStart=66074268300, SwapBuffers=66323835100, FrameCompleted=66431085200, DequeueBufferDuration=26966000, QueueBufferDuration=372000, 
    E/EnhancedIntentService( 4974): binding to the service failed
    D/EGL_emulation( 4974): eglMakeCurrent: 0xec485a80: ver 2 0 (tinfo 0xec483c50)
    W/ActivityThread( 4974): handleWindowVisibility: no activity for token android.os.BinderProxy@b021561
    D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
    D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
    D/EGL_emulation( 4974): eglCreateContext: 0xec485b40: maj 2 min 0 rcv 2
    D/EGL_emulation( 4974): eglMakeCurrent: 0xec485b40: ver 2 0 (tinfo 0xec483c50)
    D/EGL_emulation( 4974): eglMakeCurrent: 0xec485b40: ver 2 0 (tinfo 0xec483c50)
    D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
    D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
    D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
    E/flutter ( 4974): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)
    E/flutter ( 4974): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
    E/flutter ( 4974): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)
    E/flutter ( 4974): <asynchronous suspension>
    E/flutter ( 4974): #2      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:344:48)
    E/flutter ( 4974): <asynchronous suspension>
    E/flutter ( 4974): #3      GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:218:23)
    E/flutter ( 4974): <asynchronous suspension>
    E/flutter ( 4974): #4      GoogleSignIn._addMethodCall (package:google_sign_in/google_sign_in.dart:257:20)
    E/flutter ( 4974): #5      GoogleSignIn.signIn (package:google_sign_in/google_sign_in.dart:324:48)
    E/flutter ( 4974): #6      AuthService.googleSignIn (package:memail/auth.dart:33:58)
    E/flutter ( 4974): <asynchronous suspension>
    E/flutter ( 4974): #7      LoginButton.build.<anonymous closure>.<anonymous closure> (package:memail/main.dart:86:46)
    E/flutter ( 4974): #8      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14)
    E/flutter ( 4974): #9      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:711:32)
    E/flutter ( 4974): #10     GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
    E/flutter ( 4974): #11     TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
    E/flutter ( 4974): #12     TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7)
    E/flutter ( 4974): #13     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:455:9)
    E/flutter ( 4974): #14     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:75:13)
    E/flutter ( 4974): #15     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:102:11)
    E/flutter ( 4974): #16     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
    E/flutter ( 4974): #17     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
    E/flutter ( 4974): #18     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
    E/flutter ( 4974): #19     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
    E/flutter ( 4974): #20     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
    E/flutter ( 4974): #21     _rootRunUnary (dart:async/zone.dart:1136:13)
    E/flutter ( 4974): #22     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
    E/flutter ( 4974): #23     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
    E/flutter ( 4974): #24     _invoke1 (dart:ui/hooks.dart:250:10)
    E/flutter ( 4974): #25     _dispatchPointerDataPacket (dart:ui/hooks.dart:159:5)
    E/flutter ( 4974):