1

I'm trying to create an Authentication Activity using Firebase like such:

private TextView mStatusTextView;
private TextView mDetailTextView;
private EditText mEmailField;
private EditText mPasswordField;

private FirebaseAuth mAuth;

private FirebaseAuth.AuthStateListener mAuthListener;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_authentication);

    // Views
    mStatusTextView = (TextView) findViewById(R.id.status);
    mDetailTextView = (TextView) findViewById(R.id.detail);
    mEmailField = (EditText) findViewById(R.id.field_email);
    mPasswordField = (EditText) findViewById(R.id.field_password);

    // Buttons
    findViewById(R.id.email_sign_in_button).setOnClickListener(this);
    findViewById(R.id.email_create_account_button).setOnClickListener(this);
    findViewById(R.id.sign_out_button).setOnClickListener(this);

    mAuth = FirebaseAuth.getInstance();

    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            updateUI(user);          
        }
    };      
}

But I receive the following error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{trakr.Authentication}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process trakr.kade_c.trakr. Make sure to call FirebaseApp.initializeApp(Context) first.

Even if I add FirebaseApp.initializeApp(this) the same exception is thrown.

Please note that my MainActivity simply calls my Authentication class like such:

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

    startActivity(new Intent(this, Authentication.class));
}
  • have you added `google-services.json` to your project (as per https://firebase.google.com/docs/android/setup). – John O'Reilly Jan 03 '17 at 13:35
  • I am connected to Firebase and my dependencies are set up correctly –  Jan 03 '17 at 13:46
  • In my case, this same error was fixed when I put the statement "apply plugin: 'com.google.gms.google-services' " at the bottom of the app module's build.gradle. (I had forgotten to do that earlier.) Also see: https://stackoverflow.com/a/39772133/3482621 – albert c braun Aug 30 '17 at 20:53

0 Answers0