0

In Firebase Authentication version 33.10.0, it is not working in my project when using compile SDK version 35. However, when I use Firebase BOM version 28.2.1, the authentication section works correctly—OTP is generated and received on my phone number.But when I update to the latest Firebase version 33.10.0 while still using compile SDK 35, the authentication does not work. The OTP is not received, and the callback section is not triggered.

Plugins Used: com.android.application Declares this module as an Android application module. Required for building Android apps. org.jetbrains.kotlin.android Enables support for Kotlin in Android development. kotlin-kapt Kotlin Annotation Processing Tool. Required for libraries that use annotation processing, such as Room or Dagger. com.google.protobuf (version '0.9.0') Enables support for Protocol Buffers (protobuf), a method of serializing structured data. Useful in apps that use .proto files, often with gRPC. com.google.gms.google-services Integrates Google services like Firebase. It processes the google-services.json file to configure Firebase services such as authentication, analytics, and database.**

    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")
            }
    
    
        }
    

this code use for Call back sending phoneauthProvoder code: Triggered when Firebase successfully sends an OTP to the user. p0 = the verification ID (used to verify the code later). p1 = token that can be used to resend the code if needed. What it does: Saves the verification ID to a variable (verificationCode). Logs the event. Updates the UI (hideMaskingView) and starts a countdown timer for the OTP (startOTPCountdown()).

      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) }}

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.