Reputation: 9663
Below code I am using for Google login.I added google-services.json
file in the app folder.I am using classpath 'com.google.gms:google-services:2.0.0
' in root gradle module.I have checked my package at developer console and its correct and I added SHA1 key which i got by running command keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
on terminal(i am using ubuntu).I have enable Google+ API.I have created OAuth consent screen andOAuth client id.Still i get below error when i try to login with google-
{statusCode=DEVELOPER_ERROR, resolution=null}
I check similar question but couldn't find appropriate solution. Code
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestProfile().requestId()
.requestEmail().requestScopes(new Scope(Scopes.PLUS_ME))
.requestScopes(new Scope(Scopes.PLUS_LOGIN))
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
googleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
private void handleSignInResult(GoogleSignInResult result) {
if (result.isSuccess()) {
// Signed in successfully, show authenticated UI.
GoogleSignInAccount acct = result.getSignInAccount();
} else {
// Signed out, show unauthenticated UI.
// updateUI(false);
}
}
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
super.onStop();
if(mGoogleApiClient.isConnected())
{
mGoogleApiClient.disconnect();
}
}
@Override
protected void onResume() {
super.onResume();
if(mGoogleApiClient.isConnected())
{
mGoogleApiClient.connect();
}
}
Manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- To use account credentials -->
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Upvotes: 6
Views: 23407
Reputation: 127
I faced the same issue with my React Native
project.
I had to generate SHA-1 key
using debug.keystore in android/app
folder.
Run the below command in the terminal after changing your directory to cd C:\Program Files\Java\jdk1.8.0_251\bin
. (You may have a different JDK version).
keytool -list -v -keystore "D:\{ProjectName}\android\app\debug.keystore" -alias androiddebugkey -storepass android -keypass android
Upvotes: 0
Reputation: 201
Thanks Aleksey Gureiev for hinting... I solved my problem by making sure debug keys are actually used during builds..
For me in Android Studio the issue was the Signing Config was not set at all. I am still wondering how it happened.
Once I set Signing Config to my config with name "debug" then it all started working.
Upvotes: 1
Reputation: 1611
I have same problem and this solution has worked. Hope this will help you and others.
Apply the plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
Make Sure this applicationId is same as your package name in Manifest file (Upper case and lower case matters)
applicationId "com.example"
minSdkVersion 17
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Upvotes: 5
Reputation: 141
If you are working in two computer different, you have to generate the SHA1 again and add to console.firebase.google.com, download the google-service.json and add in your project
Upvotes: 5
Reputation: 1759
It's likely that your issue is in that you picked the SHA1 from the ~/.android/debug.keystore
, but not using it to sign your build.
Go to the module options Signing tab and add a profile with the only field Store File
set to /Users/<your_user>/.android/debug.keystore
On the Flavors tab pick it in the Signing Config
drop-down.
On the Build Types tab pick it in the Signing Config
drop-down for your build type (likely to be Debug
).
Cleanup and rebuild.
Upvotes: 7
Reputation: 10906
solved by adding SHA-1 of debug key store in firebase console for my app which is located here C:\Users\my name.android when you make key store for release change it in firebase console
Upvotes: 3
Reputation: 3134
Use .requestIdToken(BACKEND_CLIENT_ID) with your GoogleSignInOptions.
How to get the BACKEND_CLIENT_ID can be found here: https://developers.google.com/identity/sign-in/android/start-integrating#get_your_backend_servers_oauth_20_client_id
Hope this helped!
Upvotes: 3