当我尝试单击登录按钮时遇到此错误
操作 RecaptchaAction(action=signInWithPassword) 的初始任务失败,但有异常 - 提供的身份验证凭据不正确、格式错误或已过期。
我想进行登录活动,到目前为止我的代码是这样的
登录活动.kt
package com.example.cafe
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.textfield.TextInputEditText
import com.google.firebase.Firebase
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.auth
class LoginActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
@SuppressLint("MissingInflatedId")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
val email = findViewById<TextInputEditText>(R.id.loginEmail)
val password = findViewById<TextInputEditText>(R.id.loginpassword)
val loginBtn = findViewById<Button>(R.id.signinBtn)
auth = Firebase.auth
loginBtn.setOnClickListener {
val mail = email.text.toString()
val pass = password.text.toString()
if(mail.isNotEmpty() && pass.isNotEmpty()) {
auth.signInWithEmailAndPassword(mail, pass).addOnCompleteListener {
if(it.isSuccessful){
val intent = Intent(this,MainActivity::class.java)
startActivity(intent)
}else{
Toast.makeText(this,it.exception.toString(),Toast.LENGTH_LONG).show()
}
}
} else{
Toast.makeText(this,"Fields cannot be empty",Toast.LENGTH_LONG).show()
}
}
}
}
菜单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Cafe"
tools:targetApi="31">
<activity
android:name=".LoginActivity"
android:exported="false" />
<activity
android:name=".firstpage"
android:exported="false" />
<activity
android:name=".splashscreen"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".orderActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="false" />
</application>
</manifest>
**gradle 文件 **
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.gms.google-services")
}
android {
namespace = "com.example.cafe"
compileSdk = 34
defaultConfig {
applicationId = "com.example.cafe"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.google.firebase:firebase-database:20.3.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
implementation ("com.google.firebase:firebase-core:21.1.1")
implementation ("com.google.firebase:firebase-auth:22.3.1")
implementation(platform("com.google.firebase:firebase-bom:32.7.2"))
implementation("com.google.firebase:firebase-auth")
}
这对我来说是一个问题,所以我将其从项目中删除 - >实现(平台(“com.google.firebase:firebase-bom:32.7.2”))
并且 auth = Firebase.auth 替换为 auth = FirebaseAuth.getInstance()