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

北城余情 提交于 2019-11-26 16:13:25

问题


The dialog (Google form) for the credentials is opened successfully, but after I fill my credentials I'm getting this error. I followed the instructions from here. Created a Firebase project, enabled the Google Drive API (that's what I need for now) from the Google APIs Console.

The code throwing the exception:

final GoogleSignIn _googleSignIn = GoogleSignIn(
  scopes: [
    'https://www.googleapis.com/auth/drive',
  ],
);

await _googleSignIn.signIn();

That's the stack trace:

E/flutter ( 5068): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter ( 5068): PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)
E/flutter ( 5068): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:551:7)
E/flutter ( 5068): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:292:18)
E/flutter ( 5068): <asynchronous suspension>
E/flutter ( 5068): #2      GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:226:58)
E/flutter ( 5068): <asynchronous suspension>
E/flutter ( 5068): #3      GoogleSignIn._addMethodCall (package:google_sign_in/google_sign_in.dart:268:20)
E/flutter ( 5068): #4      GoogleSignIn.signIn (package:google_sign_in/google_sign_in.dart:339:48)
E/flutter ( 5068): #5      ThatsMyComponentState.theSignInFuction.<anonymous closure> (package:my_app/widgets/my_file.dart:666:45)
E/flutter ( 5068): <asynchronous suspension>
E/flutter ( 5068): #6      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
E/flutter ( 5068): #7      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
E/flutter ( 5068): #8      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
E/flutter ( 5068): #9      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
E/flutter ( 5068): #10     TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:204:7)
E/flutter ( 5068): #11     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter ( 5068): #12     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:184:20)
E/flutter ( 5068): #13     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:158:22)
E/flutter ( 5068): #14     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:138:7)
E/flutter ( 5068): #15     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
E/flutter ( 5068): #16     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
E/flutter ( 5068): #17     _invoke1 (dart:ui/hooks.dart:168:13)
E/flutter ( 5068): #18     _dispatchPointerDataPacket (dart:ui/hooks.dart:122:5)

The version of the google_sign_in plugin is 4.0.0.

That's the output of flutter doctot -v:

[√] Flutter (Channel stable, v1.0.0, on Microsoft Windows [Version 10.0.17763.253], locale en-US)
• Flutter version 1.0.0 at C:\src\flutter-0.7.3\flutter
• Framework revision 5391447fae (10 weeks ago), 2018-11-29 19:41:26 -0800
• Engine revision 7375a0f414
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
• Android SDK at C:\Users\myuser\AppData\Local\Android\Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = C:\Users\myuser\AppData\Local\Android\Sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
• All Android licenses accepted.

[√] Android Studio (version 3.3)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 32.0.1
• Dart plugin version 182.5124
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[!] IntelliJ IDEA Community Edition (version 2018.1)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1.6
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
• For information about installing plugins, see
  https://flutter.io/intellij-setup/#installing-the-plugins

[!] VS Code, 64-bit edition (version 1.30.2)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension not installed; install from
  https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.1.0 (API 27) (emulator)

! Doctor found issues in 2 categories.

Any help will be much appreciated. Thanks!


回答1:


I run into the same issue just now. This might happens if you are running on debug and you did not register a sha fingerprint in firebase. I solved it by generating a debug.keystore and registering it inside the app on Firebase. Don't forget to download the new google-services.json after that. See also https://developers.google.com/android/guides/client-auth

Edit If you are not able to use authenticate in release mode try the following:

-Add the SHA certificate fingerprints of the release key.

keytool -exportcert -list -v \
-alias <your-key-name> -keystore <path-to-production-keystore>

For more details on that see here on the section "get release certificate" https://developers.google.com/android/guides/client-auth

If your authentication is still not working, probably it is because you downloaded the app from Playstore and you enabled the "App Signing by Google Play Feature" Then for this case, go to play store publish console and go to app signing under release management. There you will find the SHA certificate fingerprint to register in Firebase console.




回答2:


When I came across this problem, I tried all other solutions described in this post. None of these worked. Eventually I figured it out: In my situation I had to make sure to have my "support email" set.




回答3:


The following solution works in flutter project:

Step 1: Generate SHA1 and SHA256 keys.
Step 2: Add both the SHA1 and SHA256 to firebase. (in you app settings)
Step 3: Download google-services.json to android/app in your project folder.
Step 4: In your terminal run the command flutter clean .
Step 5: Run your flutter app.

For more information visit:
https://developers.google.com/android/guides/client-auth
https://firebase.google.com/docs/flutter/setup




回答4:


For me I didn't need to add extra SHAs, I realized I didn't enable the Google Sign-in method in the Authentication tab in Firebase console




回答5:


Additional steps you might have to take in order for google_sign_in to work:

  • Link GooglePlay with Firebase [(https://github.com/flutter/flutter/issues/27599)

  • If you could run Google Sign In during debug but NOT in release, there is a high chance that you did not add your release key's SHA1 and SHA256 to firebase. To get the release key's SHAs, use keytool -list -v -keystore ~/key.jks -alias key

You should end up with total of at least 6 SHA credentials: 2 from the debug key, 2 from Google Play linking, and 2 from the release key. Note that you do not need to redownload the google-services.json file after adding the release SHA credentials to firebase.

  • Add GooglePlay Proguard rules (https://github.com/flutter/flutter/issues/19102)
# Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }

# GooglePlay Services
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep class com.google.common.** { *; }
-dontwarn com.google.common.**



回答6:


"Flutter clean" its the piece that everybody is missing after register the SHA1 in Firebase Console!




回答7:


One reason that you might be experiencing this error is if you did not fill out google's OAuth consent form. This is a new change to Firebase.

Here are the steps you need to follow to fill out the consent form for your app:

  1. Navigate to the google api console (currently at https://console.developers.google.com), make sure you are logged into your account which your firebase project is created under.
  2. Select your project from the "select a project" dropdown in top left of the developer console.
  3. In the left hand pane travel to "credentials" and then switch to the "OAuth consent screen".
  4. Under "Application name" enter your application's public name
  5. Under "Application logo" upload a local image file of your application
  6. Under "Support email" enter the same support email listed in your firebase application.

Your screen should now look like this example by step 6

  1. Scroll down and fill out the "Application Homepage Link", "Application Privacy Policy Link", and "Application Terms of Service Link" by adding http:// before the authorized domain which your firebase app lives at.

Here is a highlighted example of how these regions should be filled out in step 7

  1. Click Save

These steps worked for me! While the link may not still exist, I'd like to reference the source of this solution here




回答8:


Make sure SHA-1 must be a debug key which is generated in your system only, and then download google-services.json file append that to your project




回答9:


You need to configure your Google Cloud Api project with your package.

https://developers.google.com/identity/sign-in/android/start-integrating#configure_a_project

Make sure to be logged in with the same account of Firebase

  1. Select your firebase project
  2. Select Andrid
  3. Open terminal inside your flutter project
  4. cd android
  5. ./gradlew signingReport or gradlew signingReport
  6. Paste your package name and your SHA1 key
  7. Download Client Information
  8. Download and replace the google-services.json
  9. flutter clean

IOS:

  1. Select your Firebase project
  2. Select IOS
  3. Enter your Bundle ID
  4. Download credetials
  5. Download and replace GoogleService-info.plist



回答10:


In android/app/build.gradle I changed the dependencies from com.android.tools.build:gradle:3.1.3/com.google.gms:google-services:3.2.1 to com.android.tools.build:gradle:3.2.1/com.google.gms:google-services:4.2.0. And it worked.




回答11:


While registering the app in Firebase I changed my applicationId to something that suits my app. However, this resulted in a second Flutter app being installed on my phone when I ran the debugger (Of course, due to the change in applicationId). So the thing that worked for my situation, was to remove both the installations and re-install the app.




回答12:


I tried everything above and nothing worked. My mistake was I had multiple android studio version folders in my drive and I was feeding wrong SHA1 key in firebase settings.




回答13:


make sure you have added

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

in android/build.gradle and

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

in android/app/build.gradle. Also, make sure applicationId in android/app/build.gradle is the same as your package name in AndroidManifest.xml(You may forget to change applicationId after changing package name sometimes). This applicatioonId or package name in manifest file should be the name of your android package name in firebase app.




回答14:


You should generate SHA-1 and SHA-256 for each pc that you used. And add them all to firebase project settings.

And you should fill the form in OAuth Consent tab.




回答15:


Building an appbundle (which is recommended by Google Play and Flutter) will cause this error. Building an apk will resolve this.

See issue 58194425




回答16:


I had the issue and took 5 hours to get it solved. I remember I read somewhere that API Exception 10 means that there is an issue with the fingerprints. So, it had to be the keystore or a misconfiguration in firebase. Eventually, it was the keystore. I'm still not sure of why this worked but this is what I did, by the way, I'm using Windows 10:

1.) Make sure that on the file android/build.gradle I had the following:

buildscript {
    repositories {
        google()
        jcenter()
    }

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

2.) I added these two lines to the file android/gradle.properties

android.useAndroidX=true
android.enableJetifier=true

3.) Navigated to C:\Users\YOURUSER\.android and deleted the following:

debug.keystore
debug.keystore.lock

4.) Open the terminal as admin, and generated the debug keystore in this directory.

$ keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000

Obtained the fingerprints:

$ keytool -list -v -keystore debug.keystore -alias androiddebugkey -storepass android -keypass android 

5.) Added the SHA1 fingerprints to the configuration in firebase

That was it on my end. I hope it helps someone.




回答17:


Please ensure the signing certs you are using on the firebase console is same as what is used in signingConfigs >> debug configuration in app/build.gradle file while still in development. Missmatch causes error.




回答18:


This fixed it for me. I did a small refactor in a new project. I thought I was using my old google-services.json file but I had been using the wrong file. I tried everything else for two days before realizing this simple error.



来源:https://stackoverflow.com/questions/54557479/flutter-and-google-sign-in-plugin-platformexceptionsign-in-failed-com-google

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!