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" />
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.