Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

com.google.firebase.FirebaseException: An internal error has occurred. [ API key not valid. Please pass a valid API key. ]

Tags:

android

I delete my old fire-base project and create a new project. after that I got this error.

First The error was sha 1 that why I delete the old project and create new one.

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.firebase.ui.auth.AuthUI;
import com.google.firebase.auth.FirebaseAuth;

import java.util.Arrays;

public class MainActivity extends AppCompatActivity {public static final int RC_SIGN_IN = 1;


private FirebaseAuth mFirebaseAuth;
private FirebaseAuth.AuthStateListener mAuthStateListener;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mFirebaseAuth = FirebaseAuth.getInstance();

    startActivityForResult(
            // Get an instance of AuthUI based on the default app
            AuthUI.getInstance()
                    .createSignInIntentBuilder()
                    .setAvailableProviders(Arrays.asList(
                            new AuthUI.IdpConfig.EmailBuilder().build(),
                            new AuthUI.IdpConfig.PhoneBuilder().build(),
                            new AuthUI.IdpConfig.GoogleBuilder().build()
                    ))
                    .setIsSmartLockEnabled(!BuildConfig.DEBUG /* credentials */, true /* hints */)
                    .build(),
            RC_SIGN_IN);
 }

}

This is very simple code no error is there. It was work before.

I think the problem is somewhere technical. like somewhere in fire-base console.

Probem Screenshot

like image 910
Sushen Biswas Avatar asked Nov 01 '19 04:11

Sushen Biswas


3 Answers

What worked for me was going to "Build" -> "Clean Project" and running it.

(I also tried syncing Firebase on Android Studio, recreated google-services.json, but none actually worked for me until cleaning the project)

like image 62
E.Akio Avatar answered Sep 17 '22 12:09

E.Akio


I was also facing this issue.

Solution: change the version of google services at project level gradle and sync your project and reinstall.

classpath 'com.google.gms:google-services:4.3.0'
like image 25
khurram shahzad Avatar answered Sep 18 '22 12:09

khurram shahzad


Similar to E.Akio I also needed to clean and then rebuild.
However in VSCode I see no menu option for clean so from command line:

cd android
.\gradlew.bat clean

Then I launched the app again with F5 and the new google-services.json must have been incuded in the build because the error disappeared.

like image 33
crowne Avatar answered Sep 18 '22 12:09

crowne