Bird
Raised Fist0
Android Kotlinmobile~10 mins

Firebase project setup in Android Kotlin - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize Firebase in your Android app's main activity.

Android Kotlin
override fun onCreate(savedInstanceState: Bundle?) {
  super.onCreate(savedInstanceState)
  setContentView(R.layout.activity_main)
  Firebase[1].initializeApp(this)
}
Drag options to blanks, or click blank then click option'
AApp
BAuth
CDatabase
DFirestore
Attempts:
3 left
💡 Hint
Common Mistakes
Using FirebaseAuth or FirebaseDatabase instead of FirebaseApp.
Forgetting to call initialize in onCreate.
2fill in blank
medium

Complete the code to add Firebase Analytics to your app.

Android Kotlin
val analytics = FirebaseAnalytics[1](this)
Drag options to blanks, or click blank then click option'
A.setup
B.initialize
C.getInstance
D.create
Attempts:
3 left
💡 Hint
Common Mistakes
Using initialize or create instead of getInstance.
Not passing the context 'this' as parameter.
3fill in blank
hard

Fix the error in the Firebase Realtime Database reference code.

Android Kotlin
val database = FirebaseDatabase.getInstance()
val myRef = database.[1]("message")
Drag options to blanks, or click blank then click option'
AgetRef
BgetReference
Cref
Dreference
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'reference' or 'ref' which are not methods.
Using 'getRef' which does not exist.
4fill in blank
hard

Fill both blanks to complete the Firebase Cloud Firestore initialization and get a collection reference.

Android Kotlin
val db = FirebaseFirestore[1]()
val usersRef = db.[2]("users")
Drag options to blanks, or click blank then click option'
AgetInstance
Bcollection
CgetCollection
Dinitialize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'initialize' instead of 'getInstance'.
Using 'getCollection' which is not a Firestore method.
5fill in blank
hard

Fill all three blanks to complete the Firebase Authentication sign-in with email and password code.

Android Kotlin
val auth = FirebaseAuth[1]()
auth.[2]WithEmailAndPassword(email, password)
  .addOnCompleteListener(this) { task ->
    if (task.[3]()) {
      // Sign in success
    } else {
      // Sign in failed
    }
  }
Drag options to blanks, or click blank then click option'
AgetInstance
Binstance
CisSuccessful
DsignIn
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'signIn' instead of 'getInstance' for first blank.
Using 'instance' instead of 'signIn' for second blank.
Checking 'task.success' instead of 'task.isSuccessful()'.

Practice

(1/5)
1. What is the first step to connect your Android app to Firebase?
easy
A. Add dependencies in the app's build.gradle file
B. Create a Firebase project in the Firebase console
C. Download the google-services.json file
D. Run the app on an emulator

Solution

  1. Step 1: Access Firebase Console

    You need to start by creating a Firebase project in the Firebase console to link your app with Firebase services.
  2. Step 2: Prepare for app integration

    Only after creating the project can you download configuration files and add dependencies.
  3. Final Answer:

    Create a Firebase project in the Firebase console -> Option B
  4. Quick Check:

    First step = Create Firebase project [OK]
Hint: Start by creating the Firebase project online [OK]
Common Mistakes:
  • Trying to add dependencies before creating the project
  • Downloading google-services.json before project setup
  • Running app without Firebase configuration
2. Which line correctly adds the Firebase plugin in the project-level build.gradle file?
easy
A. classpath 'com.google.gms:google-services:4.3.15'
B. implementation 'com.google.firebase:firebase-analytics:21.3.0'
C. apply plugin: 'com.android.application'
D. compile 'com.google.firebase:firebase-core:16.0.9'

Solution

  1. Step 1: Identify plugin declaration

    The Firebase plugin is added in the project-level build.gradle under dependencies using the classpath keyword.
  2. Step 2: Match correct syntax

    classpath 'com.google.gms:google-services:4.3.15' uses classpath with the correct Firebase plugin version format.
  3. Final Answer:

    classpath 'com.google.gms:google-services:4.3.15' -> Option A
  4. Quick Check:

    Firebase plugin uses classpath in project build.gradle [OK]
Hint: Firebase plugin uses classpath, not implementation [OK]
Common Mistakes:
  • Using implementation instead of classpath for plugin
  • Adding plugin in app-level build.gradle instead of project-level
  • Using outdated or incorrect plugin versions
3. Given this snippet in the app-level build.gradle file:
plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
}
dependencies {
    implementation 'com.google.firebase:firebase-analytics:21.3.0'
}
What happens when you sync the project?
medium
A. The project syncs but Firebase Analytics is not included
B. Build fails because the google-services plugin is not applied correctly
C. The app runs without Firebase Analytics features
D. The Firebase Analytics library is added and the google-services plugin is applied successfully

Solution

  1. Step 1: Check plugin application

    The plugin 'com.google.gms.google-services' is applied correctly in the plugins block, which is the modern way.
  2. Step 2: Verify dependency inclusion

    The Firebase Analytics library is included in dependencies, so it will be added on sync.
  3. Final Answer:

    The Firebase Analytics library is added and the google-services plugin is applied successfully -> Option D
  4. Quick Check:

    Correct plugin + dependency = successful sync [OK]
Hint: Check plugins block for google-services plugin [OK]
Common Mistakes:
  • Applying plugin in wrong Gradle file
  • Forgetting to add Firebase dependencies
  • Using old apply plugin syntax with plugins block
4. You added the google-services.json file but your app crashes on startup with a missing resource error. What is the likely cause?
medium
A. You forgot to add Firebase dependencies in build.gradle
B. You did not create a Firebase project in the console
C. The google-services.json file is placed in the wrong folder
D. You did not enable internet permission in AndroidManifest.xml

Solution

  1. Step 1: Understand google-services.json placement

    This file must be placed in the app module folder (usually app/) to be recognized during build.
  2. Step 2: Identify error cause

    If placed elsewhere, the build system cannot find required resources, causing crashes.
  3. Final Answer:

    The google-services.json file is placed in the wrong folder -> Option C
  4. Quick Check:

    Correct file location prevents resource errors [OK]
Hint: Place google-services.json inside the app folder [OK]
Common Mistakes:
  • Putting google-services.json in the project root
  • Not syncing project after adding the file
  • Ignoring build errors related to Firebase
5. You want to add Firebase Authentication to your Android app. After creating the Firebase project and adding google-services.json, what is the correct sequence to set up your app?
hard
A. Add Firebase Auth dependency, apply google-services plugin, sync project, then initialize FirebaseAuth in code
B. Initialize FirebaseAuth in code, add dependency, apply plugin, then sync project
C. Apply google-services plugin, initialize FirebaseAuth in code, add dependency, then sync project
D. Sync project, add dependency, apply plugin, then initialize FirebaseAuth in code

Solution

  1. Step 1: Add Firebase Auth dependency

    First, add the Firebase Authentication library in the app-level build.gradle dependencies.
  2. Step 2: Apply google-services plugin and sync

    Apply the google-services plugin in the app-level build.gradle and sync the project to integrate Firebase services.
  3. Step 3: Initialize FirebaseAuth in code

    Finally, initialize FirebaseAuth in your Kotlin code to use authentication features.
  4. Final Answer:

    Add Firebase Auth dependency, apply google-services plugin, sync project, then initialize FirebaseAuth in code -> Option A
  5. Quick Check:

    Dependency -> plugin -> sync -> code init [OK]
Hint: Add dependency and plugin before coding FirebaseAuth [OK]
Common Mistakes:
  • Initializing FirebaseAuth before adding dependencies
  • Forgetting to sync project after changes
  • Applying plugin after coding initialization
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard