问题
I was trying to create a login system from my app, but it crashes when I open it. I managed to locate the bug to the line
mFirebaseAuth = FirebaseAuth.getInstance();
which makes no sense to me. Here is the code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Initialize Firebase Auth
mFirebaseAuth = FirebaseAuth.getInstance();
mFirebaseUser = mFirebaseAuth.getCurrentUser();
if (mFirebaseUser == null) {
// Not logged in, launch the Log In activity
loadLogInView();
}
}
private void loadLogInView() {
Intent intent = new Intent(this, LogInActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
and the crash report:
02-20 01:04:45.137 3186-3186/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.maegner.testingfirebase, PID: 3186
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maegner.testingfirebase/com.maegner.testingfirebase.MainActivity}: java.lang.IllegalArgumentException: Given String is empty or null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)..............
回答1:
This exception can be caused by a misconfigured google-services.json
file. The error will occur if the api_key
is missing. Verify that your google-services.json
file contains this section:
"api_key": [
{
"current_key": "AIzaSyDkG-g8hH7T4TV7RrN23ccnRsXp12345678" //<-- your key here
}
],
If it does not, regenerate google-services.json
.
回答2:
Make sure you have used the plugin: apply plugin: 'com.google.gms.google-services'
Some conflicts can occur with libraries such as 'com.google.android.gms: play-services-maps: 16.0.0', and in this case the plug-in is often removed as a solution, and in the case I identified, this was the problem. Take a test without the play-services libraries.
来源:https://stackoverflow.com/questions/42335633/firebaseauth-getinstance-crashes-with-illegalargumentexception-given-string