28

I have been following this tutorial to get Google SignOn going: https://developers.google.com/identity/sign-in/android/start-integrating

When I run my application locally with a virtual device it works fine but when I deploy it to my device via debugging or if I generate a signed jar file and copy it manual GoogleSignInResult always returns false with an INTERNAL ERROR message.

I'm struggling since quite a while to be able to use google login when deploying the application via debug to my device. Any help is highly appreciated!

Solution for My Issue:

Where you download the json file you have to copy past the code that you can generate with the java key tool. I totally missed that a few times in a row.

Markus
  • 1,452
  • 2
  • 21
  • 47
  • Facing the same issue. Same error even with a virtual device. I thought my `google-services.json` file might have a problem, but it wasn't the case. Also, this used to work awhile back, and I just noticed that it's breaking. Can't figure out the point where it changed either... – Vedavyas Bhat Dec 09 '15 at 18:55
  • Okay, it was my fault. WHere you download the json file you have to copy past the code that you can generate with the java key tool. I totally missed that a few times in a row.. so maybe this helps. – Markus Dec 09 '15 at 18:58
  • What code from the java keytool? The SHA1 of the signing certificate? I thought you didn't have to modify the json file... – Vedavyas Bhat Dec 09 '15 at 19:06
  • You use the SHA1 of your keystore when creating the google-services.json file. No need to temper with the file manually after that. – Markus Dec 09 '15 at 19:45
  • I have done that. Still have the problem. Any idea? – Vedavyas Bhat Dec 09 '15 at 19:47
  • I'm sorry I follwed the official google tutorial and this was my mistake. Did you sign the APK with your keystore when exporting it? – Markus Dec 10 '15 at 07:19
  • Yes, I did sign the apk. Still same problem. – Vedavyas Bhat Dec 10 '15 at 12:40
  • 1
    I've similar problem. The same code is working on my Nexus 7 tablet with Android 4.4.4 but I'm getting INTERNAL_ERROR on Nexus 6 with Android 6.0 – radzio Dec 13 '15 at 10:38
  • Is this issue resolved for you? I'm facing the same issue. Could you share any fix you've made? – Priya Kathir Jan 04 '16 at 06:48
  • I'm really sorry. I followed all the steps in the url I posted. The only thing I forgot was: There is a step where you download your json file. I forgot to copy past my key into the broad input field. – Markus Jan 04 '16 at 08:58
  • 1
    My problem was that the app wasn't signed with my certificate: http://stackoverflow.com/questions/34652682/android-googlesigninresult-always-failing – Vedavyas Bhat Jan 22 '16 at 11:43
  • 1
    @Markus I have similiar problemm but on release mode. what json file?client_id.json or google-services.json? and where I can put the code? – Eggy Jul 20 '16 at 01:49
  • 2
    @Markus I am having similar problem. can you please eloborate more on how you fixed the issue? what do you mean by "copy past the code that you can generate with the java key tool" ?? – Minions Mar 26 '17 at 04:17

7 Answers7

13

You are probably missing dev console registration. It's very common developers will have multiple signing cert configuration: debug key store, test environment signing cert, production signing cert. signing cert SHA1 + package name uniquely identifies an Android client and needs to be registered individually in dev console.

See below blogpost to understand more about OAuth clients registration:

http://android-developers.blogspot.com/2016/03/registering-oauth-clients-for-google.html

Or see this post: Test google signin on Android in development phase

Community
  • 1
  • 1
Isabella Chen
  • 2,421
  • 13
  • 25
  • As I mentioned in a comment: Okay, it was my fault. Where you download the json file you have to copy past the code that you can generate with the java key tool. I totally missed that a few times in a row.. so maybe this helps. But your answer may help the other people comming to this thread, so thank you! – Markus Feb 01 '16 at 06:39
5

I had the same problem and it was due to

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

not being at the bottom of the app build.gradle.

Figured it out by looking at the Gradle Console. No errors were raised.

George
  • 1,224
  • 12
  • 21
5

As per this you need 3 SHA1 keys in Firebase project settings

In most of the case, the problem is the third key.

  1. The debug key

    keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore

  2. The release key

    keytool -list -v -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH

  3. Google Play App signing key

    https://play.google.com/apps/publish/

    Update for new play publish console

    • in your app's Release menu > Setup > App signing > App signing key certificate

    In old play publish console

    • in your app's Release management > App signing > App signing certificate

    it's SHA1 key

You need THREE keys to figure out ONE Google SignIn.

Make Sure it's always SHA1, not SHA256

Mihir Trivedi
  • 1,458
  • 18
  • 39
3

Reason for the can be: - You might be using an unsigned apk to test you app.

Go to Build->Generate Signed APK -> sign it with the key you used to get your SHA1 Fingerprint to make clientID on google developer console

Run app-debug.apk and its done!!

  • Thank you for your input. It might help some other people. I updated my answer with the solution to my problem. I already had it as a comment but now its better readable :) – Markus Mar 17 '16 at 09:49
  • hai, I have similiar problem but on release version.. i wan't try your answer maybe it can help.. but I not really understand your answer, you say `sign it with the key` it's your mean is SHA1 Fingerprint? and where I put that when I generate Signed APK? Thanks before – Eggy Jul 20 '16 at 01:32
3

EDITED

The answer is derived from this, as it will applicable for this problem also

I am Enclosing the Answer here

The problem is due to the Signing Certificate and the SHA-1 certificate fingerprint. Add the following SHA-1 certificates into your googleApi credentials. there are 2 cases

1.If you are running in debug mode add the SHA-1 fingerprint generated by the following

"C:\Program Files\Java\jre1.8.0_101\bin\keytool" -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

2.If you have configured Signing Config then use SHA-1 fingerprint generated by following

"C:\Program Files\Java\jre1.8.0_101\bin\keytool" -list -v -keystore "[youKeyPath]\youKey.jks"

I recommend you to add both the SHA-1 fingerprints in your googleApi credentials

Community
  • 1
  • 1
jafarbtech
  • 6,842
  • 1
  • 36
  • 55
1

In addition to the above answers, I came across one case where the problem was caused due to the configuration was mismatched to the google-services.json file:

It is also possible that the clientId was specifically assigned in the GoogleSignInOptions Builder as shown below:

    String serverClientId = "xxxxx-yyyy.apps.googleusercontent.com";
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestIdToken(serverClientId)
            .build();

If this is the case, it is possible to remove the reference to the serverClientId and the requestIdToken call as shown below:

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

This would then rely on the google-services.json as opposed to the hard-coded value during configuration.

I hope it saves someone else the trouble that I had trying to diagnose the fault with my project.

Matthew Spencer
  • 2,265
  • 1
  • 23
  • 28
1

I had issues with this, and banging my head against the monitor hurt, until I found a combo that works:

  • In Firebase, go to your_project > Project Settings > General. There's a section "Your Project", then below that a section "Your Apps". Make sure your app is in it. Then when it's selected, there's a section "SDK setup and configuration". You can add SHA1 certificate fingerprints there; add one for release, one for debug, etc.

enter image description here

enter image description here

  • Download the resulting google-services.json from there, and add that to your project. That json file has an entry for each of the certs you added.

  • In your code when you call GoogleSignInOptions.Builder.requestIdToken(your_token)... there are several choices for the token parameter. I tried all of the client_ids from google-services-json until one worked; it was the one with client_type = 3, NOT the ones with a package or cert. Presumably because those are android app ids, and the token has to be the server one, which seems to be the other one.

None of this seems to be documented, and I haven't found this elsewhere in SO or on the web.

Sofi Software LLC
  • 3,879
  • 1
  • 36
  • 34