I am using FirebaseAuth for user registration with email and password, and I have already added the plugin and dependencies in my project.
MainActivity.java
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
EditText ed_email, ed_pass;
Button but_login;
ProgressDialog progressDialog;
FirebaseAuth firebaseAuth;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context=getApplicationContext();
FirebaseApp.initializeApp(context);
firebaseAuth=FirebaseAuth.getInstance();
ed_email= (EditText) findViewById(R.id.ed_email);
ed_pass= (EditText) findViewById(R.id.ed_pass);
but_login= (Button) findViewById(R.id.but_login);
but_login.setOnClickListener(this);
progressDialog=new ProgressDialog(this);
}
public void registerUser(){
String email=ed_email.getText().toString().trim();
String pass=ed_pass.getText().toString().trim();
if(TextUtils.isEmpty(email)){
Toast.makeText(getApplicationContext(),"Invalid Input",Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(pass)){
Toast.makeText(getApplicationContext(),"Invalid Input",Toast.LENGTH_SHORT).show();
return;
}
progressDialog.setMessage("You are registering...");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(email,pass).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();
progressDialog.hide();
} else {
Toast.makeText(getApplicationContext(), "Sorry...!!!", Toast.LENGTH_SHORT).show();
progressDialog.hide();
}
}
});
}
@Override
public void onClick(View v) {
registerUser();
}
}
logcat -
com.skapsdevelopment.firebase E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.skapsdevelopment.firebase, PID: 31993
Theme: themes:{default=overlay:com.resurrectionremix.pitchblack, iconPack:com.baranovgroup.nstyle, fontPkg:com.resurrectionremix.pitchblack, com.android.systemui=overlay:com.resurrectionremix.pitchblack, com.android.systemui.navbar=overlay:com.resurrectionremix.pitchblack}
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.skapsdevelopment.firebase/com.skapsdevelopment.firebase.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.skapsdevelopment.firebase. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.skapsdevelopment.firebase. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
at com.skapsdevelopment.firebase.MainActivity.onCreate(MainActivity.java:35)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
My App is not starting and showing the following error:
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this
process com.skapsdevelopment.firebase.
Make sure to call FirebaseApp.initializeApp(Context) first.
Why is the app not starting properly?
I also faced the above issue. I downloaded all plugins and checked for updates with NuGet. In the end, I found the crashing was due to the Application Package Name not matching the one assigned in Google Dev.
Make sure that your google-services.json is assigned a build action of GoogleServicesJson
Check that your application package name matches the one that you assigned in the Google Dev Console
Follow these steps:
FirebaseApp.initializeApp(context);
as you do not need it in the newer versions of FirebaseFor further info see the Firebase Authentication Guide.
Thanks to the answers here, I went through the check list of possible issues when I encountered this error.
Finally I realized .. I had started a new module in Android Studio, with a different package name than what's already registered on the Firebase Console for the Firebase instance I had set up. Simple mistake - I forgot to add the new package name to the Console config.
After I got this right, it started to work. Remembering all the little details expected by Firebase Console can be tricky sometimes.. gotta be alert/"config-cognizant" there for sure
First thing Make sure you register your application in the Firebase Console and you have added the google-services.json file in the app.
Second Check the whether you have add all the dependency or not. Add following dependency in the App-bulid Gradle file:-
And add in project level bulid gradle file:-
What worked for me was:
Adding
FirebaseApp.initializeApp(this);
on the activityonCreate()
method.Downgrading
com.google.gms:google-srvices
in project levelbuild.gradle
from 4.2.0 to 4.0.0that is changing:
to:
You need to add initializeApp in your program. I can show you how it's done.
First create a new class and extend
Application
.Lastly, go to Manifest and add in the application like this:
And this is all...