【问题标题】:Firebase Authentication Error: I Enabled the Email/Password optionFirebase 身份验证错误:我启用了电子邮件/密码选项
【发布时间】:2018-06-06 08:26:02
【问题描述】:

我正在尝试使用 Android 登录 Firebase,但收到了奇怪的消息:

Code Picture Here

login.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            final String Email,Pass;
            Email=email.getText().toString();
            Pass=pass.getText().toString();
            if(!TextUtils.isEmpty(Email) && !TextUtils.isEmpty(Pass))
            {
                progressBar.setVisibility(View.VISIBLE);
                if(Pass.length()>=6)
                {
                    auth = FirebaseAuth.getInstance();
                    auth.signInWithEmailAndPassword(Email, Pass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task)
                        {
                            progressBar.setVisibility(View.INVISIBLE);
                            if (task.isSuccessful())
                            {
                                Intent i = new Intent(login.this, MainActivity.class);
                                i.putExtra("Email",Email);
                                startActivity(i);
                                finish();
                            }
                            else
                            {
                                progressBar.setVisibility(View.INVISIBLE);
                                Toast.makeText(login.this, "" + task.getException(), Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                }
                else
                {
                    progressBar.setVisibility(View.INVISIBLE);
                    Toast.makeText(login.this, "Password Must be 8 Character Long", Toast.LENGTH_SHORT).show();
                }

            }
            else
            {
                progressBar.setVisibility(View.INVISIBLE);
                Toast.makeText(login.this, "Provide Email and Password", Toast.LENGTH_SHORT).show();
            }

        }
    });

构建.Gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.butt************"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 

    "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile 'com.google.firebase:firebase-database:11.8.0'
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:27.0.1'
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        implementation 'com.android.support:support-v4:27.0.1'
        implementation 'com.android.support:recyclerview-v7:27.0.1'
        implementation 'com.google.android.gms:play-services-maps:11.8.0'
        implementation 'com.google.firebase:firebase-database:11.8.0'
        testImplementation 'junit:junit:4.12'
        compile 'com.google.firebase:firebase-auth:11.8.0'
        androidTestImplementation 'com.android.support.test:runner:1.0.1'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
        implementation 'com.android.support:design:27.0.1'
        implementation 'com.android.support:cardview-v7:27.0.1'
        implementation 'com.android.support:gridlayout-v7:27.0.1'
        apply plugin: 'com.google.gms.google-services'
        implementation 'com.google.android.gms:play-services-ads:11.8.0'


    }
    apply plugin: 'com.google.gms.google-services'

带有错误消息:

W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() 返回 Gms D/ViewRootImpl:来自应用信息的缓冲区计数,使用 ::-1 && -1 for :: com.butt.mediacalradar 来自 View :: -1 DBQ Enabled ::false false

"com.google.firebase.FirebaseException. An internal Error Occur [Bad Request]".

更新后

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com**********"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    //compile 'com.google.firebase:firebase-database:11.8.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.0.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:support-v4:27.0.1'
    implementation 'com.android.support:recyclerview-v7:27.0.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    testImplementation 'junit:junit:4.12'
    compile 'com.google.firebase:firebase-auth:16.0.1'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support:design:27.0.1'
    implementation 'com.android.support:cardview-v7:27.0.1'
    implementation 'com.android.support:gridlayout-v7:27.0.1'
    apply plugin: 'com.google.gms.google-services'
    implementation 'com.google.android.gms:play-services-ads:15.0.1'


}
apply plugin: 'com.google.gms.google-services'

【问题讨论】:

  • 您能发布产生这些异常的 Java 代码吗?如果没有看到您的代码,我们将无法帮助您。您可以编辑自己的问题,然后在其中添加 Java 代码。
  • 请添加相应的代码。
  • @AlexMamo 代码添加
  • 您的代码看起来不错。请同时添加您的build.gradle 文件。
  • @AlexMamo 还添加了 build.gradle

标签: android firebase android-studio firebase-authentication


【解决方案1】:

为了使其正常工作,请对所有依赖项使用最新版本:

首先将 google 服务版本(build.gradle 项目)更改为:

classpath 'com.google.gms:google-services:4.0.1'

以及来自的依赖项:

compile 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.android.gms:play-services-maps:11.8.0'
implementation 'com.google.firebase:firebase-database:11.8.0'
compile 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.android.gms:play-services-ads:11.8.0'

//compile 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation 'com.google.firebase:firebase-core:16.0.0'

如您所见,第一行已被注释。不要忘记删除重复的apply plugin: 'com.google.gms.google-services'。应该只保留在文件的末尾。

【讨论】:

  • 在这两个库中出现错误>编译 'com.google.firebase:firebase-database:11.8.0' 和实现 'com.android.support:appcompat-v7:27.0.1'跨度>
  • 正如我所说,compile 'com.google.firebase:firebase-database:11.8.0' 必须被删除或评论。第二个错误是什么?我们很接近。
  • 错误地我将类补丁放到了应用模块gradel,但现在该错误已得到纠正。我应该从类路径'com.android.tools.build:gradle:3.0.1'更改为'com.android .tools.build:gradle:4.0.1'
  • 您应该使用最新版本。现在可以用了吗?
  • 它说所有 gms/firebase 库必须使用完全相同的版本规范
猜你喜欢
  • 2019-08-05
  • 2019-07-13
  • 1970-01-01
  • 2016-10-13
  • 2018-11-11
  • 2013-07-11
  • 2021-11-21
  • 2021-11-14
  • 2021-06-12
相关资源
最近更新 更多