任务显示中的Firebase AuthResult无法解析符号

时间:2016-10-24 18:20:53

标签: java android firebase firebase-authentication

在任务上获得红线。我也导入了import com.google.firebase.auth.AuthResult;,但它也显示了cannot resolve symbol authresult

    auth = FirebaseAuth.getInstance();
    sign_up_button = (Button) findViewById(R.id.sign_up_button);
    email = (EditText) findViewById(R.id.email);
    password = (EditText) findViewById(R.id.password);    
    sign_up_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String email_a = email.getText().toString().trim();
            String password_a = password.getText().toString().trim();
            //create user
            auth.createUserWithEmailAndPassword(email_a, password_a)
                    .addOnCompleteListener(RegisterStaff.this, new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            Toast.makeText(RegisterStaff.this, "Registration Complete..:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
                            progressBar.setVisibility(View.GONE);
                            // If sign in fails, display a message to the user. If sign in succeeds
                            // the auth state listener will be notified and logic to handle the
                            // signed in user can be handled in the listener.
                            if (!task.isSuccessful()) {
                                Toast.makeText(RegisterStaff.this, "Registration failed..." + task.getException(),
                                        Toast.LENGTH_SHORT).show();
                            } else {
                                startActivity(new Intent(RegisterStaff.this, StaffLogin.class));
                                finish();
                            }
                        }
                    }
             );}
    });
}
@Override
protected void onResume() {
    super.onResume();
    progressBar.setVisibility(View.GONE);
}

9 个答案:

答案 0 :(得分:5)

确保将相同版本的authresult编译为核心,如: -

编译com.google.firebase:firebase-core:10.0.1&#39;

编译com.google.firebase:firebase-database:10.0.1&#39;

编译&#39; com.google.firebase:firebase-messaging:10.0.1&#39;

编译&#39; com.google.firebase:firebase-auth:10.0.1&#39;

都是相同的10.0.1

答案 1 :(得分:0)

我有一些可能会有所帮助的建议:

1)从SDK Manager添加Google存储库。

2)根据FireBase的要求,Android Studio应高于1.5

3)FireBase的Gradle依赖关系必须正确且一致。

4)使用/不使用Android Studio重新进行清洁,构建和构建。

希望这会有所帮助。

答案 2 :(得分:0)

在您的Dependecy中添加此版本。我也遇到了这个问题。但最后通过添加:

来解决这个问题
compile 'com.google.firebase:firebase-messaging:9.2.0'

答案 3 :(得分:0)

在app gradle中添加以下内容,然后同步

compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.firebase:firebase-core:11.0.1'
compile 'com.google.firebase:firebase-database:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'

答案 4 :(得分:0)

请添加

编译'com.google.firebase:firebase-messaging:11.0.1

在build.gradle并尝试重新编译。

我曾使用以下代码剪切创建用户ID和密码

    FirebaseUser currentUser= FirebaseAuth.getInstance().getCurrentUser();

    if(currentUser ==null)
    {
        startActivity(new Intent(this,FirebaseAuthActivity.class));
        finish();
        return;

    }

    TextView email=(TextView) findViewById(R.id.email);
    TextView displayName= (TextView) findViewById(R.id.displayName);

    email.setText(currentUser.getEmail());
    displayName.setText(currentUser.getDisplayName());

答案 5 :(得分:0)

对此文件build.gradle(模块:app)进行更改

您可以通过为每个软件包提供最新版本来解决此问题。

注意:它们不必都相同...例如,我的情况就是这样...

 compile 'com.google.firebase:firebase-core:16.0.1'
 compile 'com.google.firebase:firebase-auth:16.0.2'
 compile 'com.google.android.gms:play-services-gcm:15.0.1'

完成文件编辑后,单击sync gradle。在撰写本文时,我正在使用android studio 3.1.3,并且当您进行同步时,棉绒会通知您是否有更新的版本,您只需更改版本号并再次同步即可。

答案 6 :(得分:0)

将您的Firebase版本更改为最新版本,这对我来说非常有用,它可以在pubspec.yml中添加

firebase_auth: ^0.15.0+1

答案 7 :(得分:0)

我已将Dependency Ver:9.6.1用于所有firebase软件包。

然后在我的课堂上,我包括以下导入:

import com.google.firebase.auth.AuthResult;

Gradle同步后,“ AuthResult”不再以红色突出显示

答案 8 :(得分:-1)

尝试使用com.google.firebase.auth.AuthResult包而不是AuthResult的完整路径。

为什么呢?我无法解释。它对我有用。

相关问题