【问题标题】:Firebase AuthResult on task shows cannot resolve symbol任务显示上的 Firebase AuthResult 无法解析符号
【发布时间】:2017-03-06 14:46:52
【问题描述】:

在任务上划出红线。我也导入了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);
}

【问题讨论】:

  • 您是否从 SDK 管理器添加了 google 存储库? Android Studio 是否高于 1.5?您是否将 firebase 添加到 gradle 依赖项?你能在这里发布更多信息吗?
  • 是的,我已经添加了所有 gradle 依赖项。我的工作室版本是2.2.2。谷歌存储库也在那里。
  • 好的...您是否尝试再次清理、编译和构建? Android Studio 重启?另外,如果可能,请发布实际错误...
  • 是的..我尝试了多次..仍然存在..实际错误是,public void onComplete(@NonNull Task task),在此,AuthResult 显示找不到符号错误。
  • 清除它。我已将 9.0.2 用于身份验证,而 9.6.1 用于其他依赖项。现在将其更改为 9.6.1 后,它正在工作。谢谢老兄。

标签: java android firebase firebase-authentication


【解决方案1】:

确保您编译的 authresult 版本与核心版本相同,例如:-

编译'com.google.firebase:firebase-core:10.0.1'

编译'com.google.firebase:firebase-database:10.0.1'

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

编译'com.google.firebase:firebase-auth:10.0.1'

都是一样的 10.0.1

【讨论】:

    【解决方案2】:

    将您的 firebase 版本更改为最新版本,这对我在颤振中添加 pubspec.yml 有用

    firebase_auth: ^0.15.0+1
    

    【讨论】:

      【解决方案3】:

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

      1) 从 SDK 管理器添加 google 存储库。

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

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

      4) Clean and Build 并在有/没有重启 Android Studio 的情况下再次构建。

      希望这会有所帮助。

      【讨论】:

        【解决方案4】:

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

        compile 'com.google.firebase:firebase-messaging:9.2.0'
        

        【讨论】:

          【解决方案5】:

          请补充

          编译'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());
          

          【讨论】:

            【解决方案6】:

            在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'
            

            【讨论】:

            • 请改进代码块并描述您的建议,以便更好地理解答案。
            【解决方案7】:

            对此文件进行更改 build.gradle(Module: 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'
            

            完成文件编辑后,单击同步 gradle。在撰写本文时,我使用的是 android studio 3.1.3,当你同步时,lint 会通知你是否有更新的版本,你可以简单地更改版本号并再次同步。

            【讨论】:

              【解决方案8】:

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

              然后在我的课堂上我包含了以下导入:

              import com.google.firebase.auth.AuthResult;
              

              Gradle Sync 后,“AuthResult”不再突出显示为红色

              【讨论】:

                【解决方案9】:

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

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

                【讨论】:

                  猜你喜欢
                  • 2015-10-19
                  • 2017-08-09
                  • 1970-01-01
                  • 1970-01-01
                  • 2016-10-06
                  • 1970-01-01
                  • 1970-01-01
                  • 2016-12-04
                  • 2019-06-16
                  相关资源
                  最近更新 更多