Skip to content

Implementing Firebase features [Auth, Remote Config] Using Jetpack Compose.

Notifications You must be signed in to change notification settings

Brindha-m/FirebaseKit

Repository files navigation

Firebase Kit

An Android application showcasing the implementation of Firebase features using Clean Architecture and MVVM design pattern.

Dark Mode (Emulator) Light Mode (Real Device)

Features

  • Firebase Authentication: Implementing user authentication using Firebase Authentication [Google Sign and Anonymous].
Google SignIn/SignUp Profile Screen Anonymous SignIn (Skip)
  • Remote Config: Dynamic app configuration using Firebase Remote Config.
Remote Config (Dark) Remote Config (Light)

Architecture

The project follows the Clean Architecture principles and MVVM design pattern. It is structured into multiple layers:

  • Presentation: Contains UI (view) components and ViewModels.
  • Domain: Holds business logic and use case implementations.
  • Data: Manages data sources, repositories, and interacts with external APIs (Firebase in this case).

Firebase Setup

Before building and running the project, you need to set up your Firebase project:

  1. Create a new project on the Firebase Console.
  2. Add your Android app to the project and download the google-services.json file.
  3. Place the google-services.json file in the app module of your project.

1. Obtain the SHA-1 Release Fingerprint:

Using Android Studio:

  1. Open Android Studio.
  2. Click on the "Gradle" tab on the right side.
  3. Navigate to Your App -> Tasks -> android -> signingReport.
  4. Run signingReport. The SHA-1 fingerprint will be displayed in the "Run" tab at the bottom.
image image

2. Add the SHA-1 Fingerprint to Firebase:

  1. Go to the Firebase Console. Open your Firebase project.
  2. Navigate to "Authentication" in the left-hand menu.
  3. Go to the "Sign-in method" tab.
  4. Enable "Google" and "Anonymous" as a sign-in provider.

image

  1. In the "Web client ID" section, copy the client id.
  2. In the "Project settings" page, navigate to the "General" tab.
  3. In the "SHA certificate fingerprints" section, click on "Add fingerprint." and save the changes.

Storing Secret Keys in Android

  1. Create a file called apiKeys.properties in root directory.
  WEB_CLIENT_ID = "9...435.apps.googleusercontent.com"
  1. In build.gradle.kts (module)

    android {
    
       val apikeyPropertiesFile = rootProject.file("apiKeys.properties")
       val apikeyProperties = Properties()
    
       /** Just use it here or separately in release and debug buildtypes. **/
      
       defaultConfig {
            buildConfigField("String", "WEB_CLIENT_ID",
                   apikeyProperties["WEB_CLIENT_ID"].toString()
            )
       }
    
       buildTypes {
           degug {
              // Build Config field
           }
           release {
                // Build Config field
           }
       }
       
       buildFeatures {
           compose = true
           buildConfig = true
       }
    
    }
    

Remote Config Essentials

  1. In Firebase console navigate to Remote Config dashboard. Click on "Add Parameter" to define a new parameter.
  2. Configure the parameter with a key, default value, and optional description.
  3. After setting up parameters, click on "Publish Changes" to make them live.
  4. You can provide default values for Firebase Remote Config in Android Studio either using an XML file (R.xml) or directly in Kotlin code.
  5. For Sample JSON data Click here
image

Using XML (R.xml file):

  1. Create an XML file in the res/xml directory, e.g., remote_config_defaults.xml:

    <!-- res/xml/remote_config_defaults.xml -->
    <defaultsMap>
        <entry>
            <key>your_parameter_key</key>
            <value>default_value</value>
        </entry>
    </defaultsMap>
  2. In your Kotlin code, set the default values using the resource ID:

    val defaultResId = R.xml.remote_config_defaults
    firebaseRemoteConfig.setDefaultsAsync(defaultResId)

Directly in Kotlin:

val firebaseRemoteConfig = FirebaseRemoteConfig.getInstance()
val configSettings = FirebaseRemoteConfigSettings.Builder()
    .setMinimumFetchIntervalInSeconds(3600) // 1 hour
    .build()
firebaseRemoteConfig.setConfigSettingsAsync(configSettings)

// Set default values directly in Kotlin
firebaseRemoteConfig.setDefaultsAsync(
    mapOf(
        "your_parameter_key" to "default_value",
        // Add more entries as needed
    )
)

Contributing

Feel free to contribute to this project by opening issues, providing feedback, or submitting pull requests. Your contributions are highly appreciated.

License

Releases

No releases published

Packages

No packages published

Languages