It's not a duplicate question. In the previous, I don't find the right solution. This Question here asked after try all possible things that are mentioned in the previous question.
So I have read all the answers that are available in StackOverflow. Nothing is work for me, I have implemented this authentication as guided in the firebase documentation. Also, I have entered the right SHA1 and google-service.json is correctly placed in mine project. So I am stuck in the problem from 2days, and I have checked everything from cloud console to firebase. StackOverflow to GitHub. But I didn't find any solution.
Error code is: com.google.android.gms.common.api.ApiException: 12500:
Here is my gradle dependencies
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
This is My Kotlin code
package com.medlance.team.medlance.medlance.user
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.api.ApiException
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.FirebaseUser
import com.google.firebase.auth.GoogleAuthProvider
import com.medlance.team.medlance.medlance.R
import com.medlance.team.medlance.medlance.home.HomeActivity
import kotlinx.android.synthetic.main.activity_user_login.*
import org.jetbrains.anko.longToast
import org.jetbrains.anko.toast
class UserLoginActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
private lateinit var googleSignInClient: GoogleSignInClient
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_user_login)
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build()
googleSignInClient = GoogleSignIn.getClient(applicationContext, gso)
auth = FirebaseAuth.getInstance()
signInButtonGoogle.setOnClickListener {
loginProgress.visibility = View.VISIBLE
val signInIntent = googleSignInClient.signInIntent
startActivityForResult(signInIntent, RC_SIGN_IN)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == RC_SIGN_IN) {
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
try {
val account = task.getResult(ApiException::class.java)
firebaseAuthWithGoogle(account!!)
} catch (e: ApiException) {
loginProgress.visibility = View.GONE
longToast("Something went wrong")
Log.w(TAG, "Google sign in failed"+resultCode, e)
}
}
}
private fun firebaseAuthWithGoogle(acct: GoogleSignInAccount) {
val credential = GoogleAuthProvider.getCredential(acct.idToken, null)
auth.signInWithCredential(credential)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success")
val user = auth.currentUser
updateUI(user)
} else {
Log.w(TAG, "signInWithCredential:failure", task.exception)
updateUI(null)
}
}
}
private fun updateUI(user: FirebaseUser?) {
val intent = Intent(applicationContext,HomeActivity::class.java)
if (user != null) {
intent.putExtra("user",auth.currentUser.toString())
startActivity(intent)
finish()
}
}
override fun onStart() {
super.onStart()
val currentUser = auth.currentUser
updateUI(currentUser)
}
companion object {
private const val TAG = "GoogleActivity"
private const val RC_SIGN_IN = 9001
}
}
Here is Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" package="com.debashis.projectISRO">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".home.HomeActivity"
android:label="@string/title_activity_home">
</activity>
<activity android:name=".user.UserLoginActivity">
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
I'm waiting for some help from this awsome developer community.