Firebase -Authentifizierung funktioniert nicht in Android 14Android

Forum für diejenigen, die für Android programmieren
Anonymous
 Firebase -Authentifizierung funktioniert nicht in Android 14

Post by Anonymous »

In der Firebase -Authentifizierung Version 33.10.0 funktioniert es in meinem Projekt nicht, wenn ich sdk Version 35 kompilieren kann. Wenn ich jedoch Firebase BOM Version 28.2.1 verwendet, funktioniert der Authentifizierungsabschnitt richtig - OTP wird generiert und auf meiner Telefonnummer empfangen. Der OTP wird nicht empfangen und der Rückrufabschnitt wird nicht ausgelöst. Erforderlich zum Erstellen von Android-Apps.
org.jetbrains.kotlin.android
Ermöglicht die Unterstützung von Kotlin in Android-Entwicklung. Erforderlich für Bibliotheken, die Annotationsverarbeitung verwenden, wie z. B. Raum oder Dolch. Nützlich in Apps, die .Proto-Dateien verwenden, häufig mit GRPC. Es verarbeitet die Datei von Google-services.json, um Firebase-Dienste wie Authentifizierung, Analyse und Datenbank zu konfigurieren. ** < /p>

Code: Select all

    plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'com.google.protobuf' version '0.9.0'
id 'com.google.gms.google-services'

}

android {

compileSdk 35

defaultConfig {
applicationId "com.example" // Live env
// applicationId "com.com.example" // Test env
minSdk 26
targetSdk 35
versionCode 42
versionName "1.5.2"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
/*sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8*/

sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17

}

kotlinOptions {
//jvmTarget = "1.8"
jvmTarget = "17"
}

buildFeatures {
viewBinding true
dataBinding true
buildConfig true  // Add this line to explicitly enable BuildConfig generation

}

bundle {
language {
enableSplit = false
}
}

namespace 'com.com.example'
}

dependencies {

// Kotlin
// implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.0"
// Kotlin Standard Library – note that the version here can be omitted if you want to rely on the version from your project-level file.
// Google Services
implementation 'com.google.android.gms:play-services-ads-lite:24.0.0'

// Networking
implementation "com.android.volley:volley:1.2.1"
implementation "com.squareup.okhttp3:logging-interceptor:4.9.0"
implementation "com.squareup.retrofit2:retrofit:2.11.0"
implementation "com.squareup.retrofit2:converter-gson:2.11.0"
// UI &  Navigation
implementation "androidx.navigation:navigation-fragment-ktx:2.8.8"
implementation "androidx.navigation:navigation-ui-ktx:2.8.8"
implementation "androidx.appcompat:appcompat:1.7.0"
implementation "androidx.constraintlayout:constraintlayout:2.2.1"
implementation "androidx.core:core-ktx:1.15.0"
implementation "androidx.cardview:cardview:1.0.0"
implementation "androidx.viewpager2:viewpager2:1.1.0"
implementation "androidx.recyclerview:recyclerview:1.4.0"
implementation "com.google.android.material:material:1.12.0"

// Firebase

// Import the BoM for the Firebase platform and Authentication Library
def firebase_bom = "28.2.1"
// implementation platform("com.google.firebase:firebase-bom:33.10.0")
implementation(platform("com.google.firebase:firebase-bom:28.2.1"))

// Firebase Authentication
implementation 'com.google.firebase:firebase-auth'
//implementation 'com.google.firebase:firebase-auth-ktx'

// Realtime Database (if needed)
implementation 'com.google.firebase:firebase-database'
//implementation 'com.google.firebase:firebase-database-ktx'

implementation 'com.google.android.gms:play-services-safetynet:18.1.0'

// Play Services Auth (For Google Sign-In)
//implementation 'com.google.android.gms:play-services-auth:21.1.1'
//implementation 'com.google.firebase:firebase-auth-ktx' //17.03.2025 close
//Firebase real-time database
// implementation 'com.google.firebase:firebase-database-ktx' //17.03.2025 close

// Kotlin Co-routines
def coroutines_play_services_version = "1.3.9"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutines_play_services_version"

// Google Play Core - In App Updates
def playCoreVersion = "1.8.1"
implementation "com.google.android.play:core-ktx:$playCoreVersion"
//implementation platform("com.google.firebase:firebase-bom:33.10.0")
//implementation 'com.google.firebase:firebase-auth-ktx'
// implementation 'com.google.firebase:firebase-database-ktx'
// implementation platform('com.google.firebase:firebase-bom:33.10.0') // Use latest BOM version
// implementation 'com.google.android.recaptcha:recaptcha:18.7.0'

// Lifecycle & LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.8.7"
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.7'

// Data Persistence: Room &  DataStore
implementation "androidx.datastore:datastore-preferences:1.1.3"
// Android Preferences
implementation 'androidx.preference:preference-ktx:1.2.1'
// implementation 'androidx.preference:preference-ktx:1.2.1'
//implementation 'com.google.android.play:app-update-ktx:2.1.0'
//implementation 'com.google.android.play:core-ktx:1.8.0'
//implementation 'com.google.android.gms:play-services-safetynet:18.1.0' // For reCAPTCHA
// implementation 'com.google.android.play:integrity:1.4.0'

def room_version = "2.5.2"
implementation "androidx.room:room-runtime:2.6.1"
implementation "androidx.room:room-ktx:2.6.1"
kapt "androidx.room:room-compiler:2.6.1"
implementation 'androidx.room:room-common:2.6.1'
kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0"
// MultiDex
implementation "androidx.multidex:multidex:2.0.1"

// Animation
implementation "com.airbnb.android:lottie:6.6.2"

// Dependency for country code picker
implementation "com.hbb20:ccp:2.7.3"

// GSON - JSON Converter
implementation "com.google.code.gson:gson:2.11.0"

// RazorPay Integration
implementation 'com.razorpay:checkout:1.6.41'

// Glide - Image Loading
implementation 'com.github.bumptech.glide:glide:4.16.0'

// Testing
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'

}

/////////////////////////////////////////////////////////////////////////////////////////

//this code is use for sendVerificationCode :

private fun sendVerificationCode(phoneNumber: String) {
if (networkControl.isConnected()) {
val options = PhoneAuthOptions.newBuilder(firebaseAuth)
.setPhoneNumber(phoneNumber)
.setTimeout(90L, java.util.concurrent.TimeUnit.SECONDS)
.setActivity(this)
.setCallbacks(mCallBack)
.build()

val firebaseService: FirebaseServiceInterface = FirebaseService(firebaseAuthInstance)
firebaseService.sendVerificationCode(options)

} else {
displayError(this, "not_connected")
Log.i(getLogName(), "Send Verification Code: Network Connection is unavailable")
}

}

< /code>
Dieser Code verwendet für den Rückruf von PhoneAuthProvoder -Code:
Ausgelöst, wenn Firebase erfolgreich einen OTP an den Benutzer sendet. (VerificationCode).
Protokolliert das Ereignis.      private val mCallBack: PhoneAuthProvider.OnVerificationStateChangedCallbacks =
object : PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
override fun onCodeSent(p0: String, p1: PhoneAuthProvider.ForceResendingToken) {
super.onCodeSent(p0, p1)
verificationCode = p0
Log.i(getLogName(), "Secret key is $p0")
Log.i(getLogName(), "OTP Code is sent")
hideMaskingView(true)
startOTPCountdown()
}

override fun onVerificationCompleted(p0: PhoneAuthCredential) {
val otpCode = p0.smsCode
if (otpCode != null) {
Log.i(getLogName(), "OTP code received $otpCode")
otpTextView.setText(otpCode)
verifyCode(otpCode)

/*CoroutineScope(Dispatchers.Main).launch{
// delay function (a suspend function) must called within coroutine
removeButtonPressed()
// or another suspend function
}*/

}

}

override fun onVerificationFailed(p0: FirebaseException) {
val error = p0.localizedMessage
if (error != null) {
Log.i(getLogName(), "OTP Code could not be sent: $error")
}
showOneButtonAlert("OTP Failed", error ?: "", null, null) }}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post