Firebase, Credential Manager and Other Backends
Do You Need a Backend?
Many apps work fully on the device with Room and DataStore. You need a backend when users need accounts, shared data or sync across devices.
| Option | Good for | Notes |
|---|---|---|
| Room + DataStore | Local only apps | No server, works offline |
| Firebase | Accounts, database, storage, analytics, push | Fast start, free tier |
| Your own REST API | Company backends | Retrofit and kotlinx.serialization |
| Supabase, Appwrite and others | Open-source style backends | Similar ideas |
Adding Firebase (Overview)
- Create a project in the Firebase console and register your Android app with its package name.
- Download
google-services.jsonand put it in theapp/folder. - Add the Google services Gradle plugin and the Firebase BoM to your project.
- Add the libraries you need, for example Authentication and Firestore.
kotlin
dependencies {
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.auth)
implementation(libs.firebase.firestore)
}
kotlin
// Sign up with email and password
val auth = Firebase.auth
val result = auth.createUserWithEmailAndPassword(email, password).await() // kotlinx-coroutines-play-services
println(result.user?.uid)
// Save a document
val db = Firebase.firestore
db.collection("notes").add(mapOf("text" to "Hello", "createdAt" to FieldValue.serverTimestamp())).await()
// Listen to changes as a Flow
fun notes(): Flow<List<Note>> = callbackFlow {
val registration = db.collection("notes").addSnapshotListener { snapshot, error ->
if (error != null) { close(error); return@addSnapshotListener }
trySend(snapshot?.toObjects(Note::class.java).orEmpty())
}
awaitClose { registration.remove() }
}
Security rules: Always write Firestore security rules so each user can only read and write their own data. A database open to everyone is the most common beginner mistake.
Sign-in with Credential Manager
Credential Manager is Android's unified API for passwords, passkeys and Sign in with Google. It replaces older sign-in APIs.
kotlin
val credentialManager = CredentialManager.create(context)
val googleOption = GetGoogleIdOption.Builder()
.setFilterByAuthorizedAccounts(false)
.setServerClientId(WEB_CLIENT_ID)
.build()
val request = GetCredentialRequest.Builder().addCredentialOption(googleOption).build()
val result = credentialManager.getCredential(context, request)
val credential = result.credential
// read the Google ID token and send it to Firebase Auth or your backend to create the sessio
Advice: For your first projects stay local with Room. Add a backend later, when a real feature needs accounts or sharing.
Conclusion
Pick the simplest backend that solves your problem. Firebase gives you quick cloud features and Credential Manager handles modern sign-in.
Quick Summary: Use Firebase for fast cloud features with security rules, Credential Manager for sign-in and your own API with Retrofit when needed.

