Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sign in for Android - Release vs Debug

So currently, I am trying to implement google sign-in .. I have followed the instructions on developer.android.com .. I am having a weird issue and I see several people on SO talk about this but it never gets anywhere so I am posting this here ...

I am able to use google sign in AFTER I generate a signed apk; and if I don't follow that method I am not able to use google sign in (i.e if I plug my phone in and hit run on android studio, google sign in tells me my request result was unsuccessful)

My question is 1) Whats really going on here? and 2) How can I use google sign in without needing to generate a signed apk each time ..

UPDATE

I believe it is because of the SHA-1 hash function that is either run on the debug keystore vs release ...

like image 881
Arjun Avatar asked Dec 17 '16 01:12

Arjun


People also ask

What is the difference between debug and release Android?

Major differences are the debug apk and the release apk: For debug builds the apk will be signed with the default debug signing keys with debug flag enabled. For release apk you will have to explicitly specify the apk to sign with and the debug flag will be turned off so that it cannot be debugged.

What is debug and release mode in Android Studio?

By default on gradle, the commands assembleDebug and installDebug build the application in debug mode. Android Studio signs your app in debug mode automatically when you run or debug your project from the IDE. An APK built by commands assembleRelease and installRelease is by default in release mode.

What is debug app in Android?

Debugging allows you to go through each line of code, evaluating your app's variables, methods and how well your code is working. It's easier to find small mistake in large pieces of code. In this article we will go through basic tips and tricks on debugging an Android app.


1 Answers

After signing your apk is using your signed SHA1 for using google services..like gmail login..

so your debug SHA1 will not work..in this case.

Answer to your first question..i think your OAuth 2.0 client IDs SHA1 is for release version. so in debug mode it is not working

And your second question yes you can use google sign in without generating signed apk each time..

For this first find your debug SHA1

  1. Click on the Gradle tab on the right hand side of the view.
  2. Go to the ROOT folder -> Tasks -> android -> signingReport
  3. Double click, this will build with the signingReport and post in your bottom view your SHA1.

Now go to

  1. https://console.developers.google.com

  2. select credential tab on leftside

  3. select OAuth 2.0 client IDs at bottom and select Android client 1

enter image description here

  1. Now change the release SHA1 to your debug SHA1 and save it
  2. Now your google sign in work in debug mode also.

N.B: during build apk change your Build variant from release to debug

And during release you have to replace back your release SHA1 in the OAuth2.0

like image 137
rafsanahmad007 Avatar answered Oct 23 '22 00:10

rafsanahmad007