简单的Firebase Auth UI检查和应用程序崩溃

时间:2018-11-21 23:31:04

标签: android firebase firebase-authentication firebaseui

我遵循以下“如何添加Firebase ui auth”工作流程到我的应用程序,并且我有一个主要活动,无论用户是否登录,该活动只会更改文本视图。代码是这样的:

public class MainActivity extends AppCompatActivity {

    private static final int RC_SIGN_IN = 123;

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

    }
    public void createSignInIntent() {
        // [START auth_fui_create_intent]
        // Choose authentication providers
        List<AuthUI.IdpConfig> providers = Arrays.asList(
                new AuthUI.IdpConfig.EmailBuilder().build());

        // Create and launch sign-in intent
        startActivityForResult(
                AuthUI.getInstance()
                        .createSignInIntentBuilder()
                        .setAvailableProviders(providers)
                        .build(),
                RC_SIGN_IN);
        // [END auth_fui_create_intent]
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == RC_SIGN_IN) {
            IdpResponse response = IdpResponse.fromResultIntent(data);

            if (resultCode == RESULT_OK) {
                TextView tv = (TextView)findViewById(R.id.tv);
                tv.setText("Signed");
                FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                // ...
            } else {

                // Sign in failed. If response is null the user canceled the
                // sign-in flow using the back button. Otherwise check
                // response.getError().getErrorCode() and handle the error.
                                    TextView tv = (TextView)findViewById(R.id.tv);
                tv.setText("Not Signed In");
            }
        }
    }
}

该应用程序崩溃且Logcat为空!

1 个答案:

答案 0 :(得分:0)

当firebase和firebaseUI的库不兼容时,我已经看到了这一点。

在清单文件中检查您的firebaseUI是否与正确的对应。 这是firebaseUI 4.2.1的示例

dependencies {
...
implementation 'com.firebaseui:firebase-ui:4.2.1'
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-database:16.0.5'
}

有关FirebaseUI兼容库的完整列表 检查此链接Firebase Compatibility