【问题标题】:Android Firebase Email and password authentication does not workAndroid Firebase 电子邮件和密码身份验证不起作用
【发布时间】:2017-01-06 00:16:45
【问题描述】:

我正在尝试使用 Firebase 在 Android 应用中创建帐户。当我在应用程序 build.grade 文件中添加以下依赖项时 -

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.firebase:firebase-client-android:2.5.2'
    compile 'com.firebaseui:firebase-ui:1.0.1' 
    compile 'com.google.firebase:firebase-auth:10.0.0'//added also tried 10.0.1
    testCompile 'junit:junit:4.12'
}

我收到以下神秘的构建错误(顺便说一句,据我所知,我没有使用任何 Twitter SDK 或任何东西):

Error:Failed to resolve: com.twitter.sdk.android:twitter:2.2.0

当我将依赖项更改为:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.firebase:firebase-client-android:2.5.2'
    compile 'com.firebaseui:firebase-ui:0.6.2'//changed
    compile 'com.google.firebase:firebase-auth:9.8.0'//changed
    testCompile 'junit:junit:4.12'
}

应用程序构建和编译正常,但是当我尝试创建帐户时,出现以下错误:

Projects created at console.firebase.google.com must use the new Firebase Authentication SDKs available from firebase.google.com/docs/auth/

我不知道该怎么做,因为我认为我使用的是最新版本的 Firebase SDK。

更多信息是我同时使用了mFirebaseRef.createUser()mAuth.createUserWithEmailAndPassword 都没有成功。

我用这个link 来改变依赖关系。

任何帮助将不胜感激。

【问题讨论】:

    标签: android firebase firebase-authentication


    【解决方案1】:

    你正在混合legacy SDK

    compile 'com.firebase:firebase-client-android:2.5.2'
    

    new SDK:

    compile 'com.google.firebase:firebase-auth:10.0.0'
    

    这将导致许多问题,并且是此错误消息的原因:

    Projects created at console.firebase.google.com must use the new Firebase Authentication SDKs available from firebase.google.com/docs/auth/
    

    对于新的开发,您应该只使用新的 SDK。从你的依赖中删除这一行:

    compile 'com.firebase:firebase-client-android:2.5.2'
    

    FirebaseAuth 的最新版本需要额外的存储库。对您的项目(顶级)build.gradle 文件进行此更改:

    allprojects {
        repositories {
            jcenter()
            maven { url 'https://maven.fabric.io/public' }
            mavenLocal()
        }
    }
    

    更改摘自Firebase Sample 项目。它将消除此错误:

    Error:Failed to resolve: com.twitter.sdk.android:twitter:2.2.0
    

    【讨论】:

    • 我已将您建议的更改添加到我的 build.gradle 文件中,错误已消失。我也在我的依赖项中使用这些: compile 'com.firebase:firebase-client-android:2.5.2' compile 'com.firebaseui:firebase-ui:1.0.1' compile 'com.google.firebase:firebase-auth :10.0.0'。问题是我仍然收到原始错误消息“在 console.firebase.google.com 创建的项目必须使用 firebase.google.com/docs/auth/ 提供的新 Firebase 身份验证 SDK”。有什么想法吗?
    • 我更新了我的答案。您应该迁移到新的 SDK。 Upgrade Guide 很有帮助。
    • 所以...抱歉回复晚了。我按照您提供的指南迁移到了新的 SDK。我发现 createUser() 不能用于 createNewAccounts。一个人只能使用 mAuth.createUserWithEmailAndPassword(mUserEmail,mPassword).addOnCompleteListener(... 创建一个新帐户。问题是即使做了所有这些更改后我仍然无法创建一个帐户。可能出了什么问题?
    • @moseskimani:您应该使用task.getException().getMessage() 来查看失败原因。请参阅此答案,例如代码stackoverflow.com/a/39427322/4815718
    • 所以。我终于让它工作了。按照您的指示,我还清除了 google play 服务设置中的所有数据。非常感谢您的帮助
    【解决方案2】:

    您应该使用来自 Google 的正确 Firebase 身份验证版本:

    compile 'com.google.firebase:firebase-auth:10.0.1'
    

    你必须按照官方documentation中的描述设置Firebase

    【讨论】:

    • 对不起。我应该补充一点,我尝试同时使用 compile 'com.google.firebase:firebase-auth:10.0.0' 和 compile 'com.google.firebase:firebase-auth:10.0.1' 都没有成功。我使用提供的 github 链接中的表将依赖项降级到上面编译的集合。同样的向上读取和写入数据到firebase数据库没有任何问题,这告诉我firebase设置正确。创建帐户是我面临的问题。
    猜你喜欢
    • 2018-06-17
    • 2016-10-13
    • 1970-01-01
    • 2016-10-04
    • 2019-03-15
    • 2016-11-13
    • 1970-01-01
    • 2019-07-13
    • 1970-01-01
    相关资源
    最近更新 更多