0

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.

Debashis Nandy
  • 545
  • 1
  • 7
  • 17
  • Also see https://github.com/firebase/FirebaseUI-Android/issues/1504 – Doug Stevenson Jul 12 '19 at 04:02
  • But my google-services.json is completely updated. I don't understand what is the problem. – Debashis Nandy Jul 12 '19 at 04:15
  • There are a lot of answers on that question. Read through all of them and make sure you've followed all the advice. That said, I've heard that there are situations where there is no solution - the project is just broken (it's happened to me). In that case, there is no currently known solution. Please file a bug report if you've tried all the current advice. https://firebase.google.com/support/contact/bugs-features – Doug Stevenson Jul 12 '19 at 04:34
  • Thank you @DougStevenson for the reply. I think the last possible thing I can do it now to file a bug. – Debashis Nandy Jul 12 '19 at 04:37
  • try this maybe : https://stackoverflow.com/questions/56993600/google-sign-in-not-working-on-published-app/56997532#56997532 – Xero Jul 13 '19 at 19:04
  • It's a very weird problem. I think firebase team should take this issue seriously. After 3 day of research i found nothing but after do some stuff here and there it's works perfectly fine. Also i have noticed a problem that google play services 4.3.0 also not working. – Debashis Nandy Jul 14 '19 at 01:02

0 Answers0