I'm a beginner trying to learn to use firebase auth with android compose
I'm following the code on https://firebase.google.com/docs/auth/android/firebaseui to create a signInLauncher but I'm getting the following error
I only selected email/password authentication on Firebase, no other providers
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/auth/api/credentials/CredentialsOptions$Builder;at com.firebase.ui.auth.util.GoogleApiUtils.getCredentialsClient(GoogleApiUtils.java:29)
at com.firebase.ui.auth.viewmodel.AuthViewModelBase.onCreate(AuthViewModelBase.java:30)
at com.firebase.ui.auth.viewmodel.ViewModelBase.init(ViewModelBase.java:24)
at com.firebase.ui.auth.KickoffActivity.onCreate(KickoffActivity.java:38)
at android.app.Activity.performCreate(Activity.java:8051)
at android.app.Activity.performCreate(Activity.java:8031)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.auth.api.credentials.CredentialsOptions$Builder" on path: DexPathList[[dex file "/data/data/com.mfhc.firebasetest/code_cache/.overlay/base.apk/classes3.dex", zip file "/data/app/~~crZRGUM9m8NR4vzMFc5fFw==/com.mfhc.firebasetest-oesX28d7C_VTSFzoRDt6Gg==/base.apk"],nativeLibraryDirectories=[/data/app/~~crZRGUM9m8NR4vzMFc5fFw==/com.mfhc.firebasetest-oesX28d7C_VTSFzoRDt6Gg==/lib/x86_64, /system/lib64, /system_ext/lib64]]
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
I followed the instructions on firebase to add the json file to my app folder and the appropriate dependencies. Is there something wrong with my gradle file?
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.gms.google-services")
}
dependencies {
implementation(platform("com.google.firebase:firebase-bom:32.7.3"))
implementation("com.google.firebase:firebase-auth")
implementation("com.firebaseui:firebase-ui-auth:8.0.2")
implementation("com.google.android.gms:play-services-auth:21.0.0")
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.activity:activity-compose:1.8.2")
implementation(platform("androidx.compose:compose-bom:2023.08.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.2.2" apply false
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
id("com.google.gms.google-services") version "4.4.1" apply false
}
UPDATE:
Changing
implementation("com.google.android.gms:play-services-auth:21.0.0")
to
implementation("com.google.android.gms:play-services-auth:20.5.0")
fixed the error. does anyone know why?
Yes, the Credentials API was removed in the latest release of the play-services-auth in favour of the Credential Manager; you can read more here in the release notes https://developers.google.com/android/guides/releases#february_15_2024 .
My solution for now is to stay on com.google.android.gms:play-services-auth:20.7.0 until a new version for com.firebaseui:firebase-ui-auth is released.
If you upgrade now you will get "java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/auth/api/credentials/CredentialsOptions$Builder;"