【问题标题】:FirebaseAuth.getInstance() crashes with "IllegalArgumentException: Given String is empty or null"FirebaseAuth.getInstance() 因“IllegalArgumentException:给定字符串为空或为空”而崩溃
【发布时间】:2022-01-25 12:27:07
【问题描述】:

我试图从我的应用程序创建登录系统,但是当我打开它时它崩溃了。我设法将错误定位到该行

mFirebaseAuth = FirebaseAuth.getInstance();

这对我来说毫无意义。代码如下:

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);
}

和崩溃报告:

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)..............

【问题讨论】:

    标签: android firebase firebase-authentication


    【解决方案1】:

    此异常可能是由配置错误的google-services.json 文件引起的。如果缺少api_key,则会发生错误。验证您的 google-services.json 文件是否包含此部分:

      "api_key": [
        {
          "current_key": "AIzaSyDkG-g8hH7T4TV7RrN23ccnRsXp12345678" //<-- your key here
        }
      ],
    

    如果没有,请重新生成google-services.json

    【讨论】:

      【解决方案2】:

      我通过升级依赖项解决了这个问题

      implementation 'com.google.firebase:firebase-auth:16.0.5'
      

      implementation 'com.google.firebase:firebase-auth:19.2.0'
      

      详情请见this

      【讨论】:

        【解决方案3】:

        确保您已使用该插件: 应用插件:'com.google.gms.google-services'

        与“com.google.android.gms: play-services-maps: 16.0.0”之类的库可能会发生一些冲突,在这种情况下,插件通常会作为解决方案被删除,并且在这种情况下我发现,这就是问题所在。在没有播放服务库的情况下进行测试。

        【讨论】:

          【解决方案4】:

          确保您已在 Firebase 中启用身份验证。 确保您在 Gradle 模块应用程序中添加了 auth 依赖项。 创建一个应用程序类并添加这些 2 - FirebaseApp.initializeApp(this); Firebase.setAndroidContext(this);

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-05-04
            • 1970-01-01
            • 2023-03-09
            • 2020-12-07
            • 2014-05-30
            • 2015-03-18
            相关资源
            最近更新 更多