# Set Up Supabase SQL, Secrets And Firebase

> Prepare the backend tables, auth configuration and Firebase Android project you need before the app's first serious run.

- URL: https://dantech.academy/en/courses/kotlin-accelerator/engineer-builder/00-setup-app-running/lesson-04-configure-local-files-secrets
- Course: [Mobile Action Pro](https://dantech.academy/en/courses/kotlin-accelerator.md)
- Module: Setup App Running
- Duration: 18 min
- Difficulty: beginner
- Access: Free, full lesson
- Tiếng Việt: https://dantech.academy/courses/kotlin-accelerator/engineer-builder/00-setup-app-running/lesson-04-configure-local-files-secrets.md

## Objectives

- Create a Supabase dev project and run the setup SQL to create the tables
- Put the Supabase and Google OAuth values in local.properties instead of hardcoding secrets
- Register the Android app in Firebase and keep google-services.json out of Git

---

## Lesson Goal

You will set up the minimum backend the app needs before its first serious build: Supabase, Google OAuth values, the `local.properties` file and a Firebase Android project.

This lesson doesn't build any features. The goal is to clear away vague setup errors before you start reading the architecture.

## Part 1: Create A Supabase Dev Project

Open the [Supabase dashboard](https://supabase.com/dashboard) and create a dev project:

```text
kotlin-accelerator-dev
```

| Value                                  | Does Android need it? | Notes                                   |
| -------------------------------------- | --------------------- | --------------------------------------- |
| Project URL                            | Yes                   | The client calls Supabase through this URL |
| Publishable key (`sb_publishable_...`) | Yes                   | Client-safe, but it identifies the project |
| Service role or secret key             | No                    | Backend-only; never paste it into Android |
| Database password                      | No                    | For admin/server use only               |

## Part 2: Run The Minimum Supabase SQL

### Option 1: Run It Manually

Open the Supabase `SQL Editor`, then open `scripts/sql/setup.sql` in the `kotlin-accelerator-ai` repo and copy its contents. The repo also has `scripts/sql/setup.vi.sql`, the same SQL with Vietnamese comments. Run only one of the two files.

Paste it into the SQL Editor and run it. Then open the `Database` tab and you will see the tables that were created.

### Option 2: Through The Supabase MCP

Go to your Supabase project, choose `Connect` > `MCP` > pick your AI client > leave Read-only unticked > Copy Prompt > paste it into the AI client > Run. The AI client installs the MCP server for you.

Then restart the AI client, call @scripts/sql/mcp-bootstrap-prompt.md so the MCP runs the setup, and call @scripts/sql/mcp-seed-prompt.md to seed sample data.

## Part 3: Configure The Auth Secrets

The repo doesn't ship any key. You use your own Supabase project, the one you created in Part 1.

Open a terminal, `cd` into the root of the `kotlin-accelerator-ai` repo and create `local.properties` from the example file:

```bash
cp local.properties.example local.properties
```

In the Windows Command Prompt, use `copy local.properties.example local.properties`.

`local.properties` is already in `.gitignore`. The example file, `local.properties.example`, is committed to the repo. Apart from its comment lines, it holds these keys, all with placeholder values:

```properties
supabase.url=https://YOUR-PROJECT.supabase.co
supabase.publishable.key=sb_publishable_YOUR_KEY
google.server.clientId=YOUR_WEB_CLIENT_ID.apps.googleusercontent.com
revenuecat.api.key=goog_YOUR_KEY
premium.gate.enabled=false
daily.challenge.enabled=false
```

In the Supabase dashboard, click your project's **Connect** button to get the Project URL and the publishable key. The publishable key is also under **Project Settings > API Keys**. It's a short string that starts with `sb_publishable_`. Paste the two values into `supabase.url` and `supabase.publishable.key` in place of the placeholders.

The app only reads `supabase.publishable.key`, not the old name `supabase.anon.key`. The Android build stops if this key is empty, if you copied the long key that starts with `eyJ` by mistake (the legacy anon key Supabase will deprecate at the end of 2026), or if it's a secret key that starts with `sb_secret_`. The error message names the property to fix and doesn't print the value. The placeholder `sb_publishable_YOUR_KEY` passes this check, so if you forget to replace it, the app still builds but can't reach Supabase.

`app/build.gradle.kts` reads these keys and puts them into `BuildConfig` at build time, so the values never sit in the source code. Only `supabase.publishable.key` is required to build, and a missing key becomes an empty string. The three lines `revenuecat.api.key`, `premium.gate.enabled` and `daily.challenge.enabled` are optional. With `premium.gate.enabled=false` the app doesn't set up RevenueCat, so you don't need to touch those three lines yet.

The example file has no `sdk.dir`, because the Android SDK path is different on every machine. When Android Studio syncs Gradle, it writes `sdk.dir` into `local.properties` if the file doesn't have that line yet, and it keeps the other keys. If you build from the command line and the file has no `sdk.dir`, set the `ANDROID_HOME` environment variable to the Android SDK folder, the one Android Studio's SDK Manager shows (Settings, Languages & Frameworks, Android SDK). If you write `sdk.dir` yourself on Windows, the `\` and `:` characters in the path must be escaped, for example `sdk.dir=C\:\\Users\\<name>\\AppData\\Local\\Android\\Sdk`.

With your own project's URL and publishable key, the app can use Supabase for practicing Login by Email. You still need `app/google-services.json` from Part 4 before the app builds. Google Sign-In also needs an OAuth web client in Google Cloud.

Go to the [Google Cloud Console](https://console.cloud.google.com/apis/credentials) and follow these steps.

- Create a project with any name, for example `kotlin-accelerator-dev`.
- Create the credentials as shown in the video:

[YouTube](https://www.youtube.com/watch?v=2pvAm5-dy_A)

The client ID in the video is a web client. Paste it into `google.server.clientId` in `local.properties`. iOS needs its own iOS OAuth client as well, but only if you run the iOS build on a Mac.

## Part 4: Create A Firebase Android Project

Open the [Firebase Console](https://console.firebase.google.com/), create `kotlin-accelerator-dev`, then add an Android app:

1. Find the project's real Android package name: `applicationId` in `app/build.gradle.kts`, currently `com.creative.kta`.
2. Register exactly that package name in Firebase.
3. Add the debug SHA-1 if the app uses Google sign-in or Firebase Auth.
4. Download `google-services.json`.
5. Put the file at `app/google-services.json`.

To get the debug SHA-1:

```bash
./scripts/get-sha1-fingerprint.sh
```

On Windows (Command Prompt or PowerShell), run `scripts\get-sha1-fingerprint.bat`.

Don't commit `google-services.json` to Git. The file doesn't hold much sensitive data, but it identifies your Firebase project. The repo already has an `app/google-services.json` line in `.gitignore`; don't remove it.

Firebase is only wired into the Android side. On iOS the app uses stand-in implementations for Analytics and Remote Config, so you don't need to create an iOS app in Firebase for this course.

## Part 5: Fill In Local Config, Don't Hardcode

You now have every value `local.properties` needs. Paste each one under the right key, and don't hardcode any of them in a Kotlin file. iOS reads the same values from a separate file, `iosApp/Configuration/Config.xcconfig`, which Git also ignores. You only need that file when you run the iOS build on a Mac.

## Verification Pass

- Launch the app on a device or emulator
- Go through Splash and Onboarding to the Menu
- Choose Login with Email -> check login, logout, register, reset password
- Choose Sign in with Google. If Google auth isn't set up yet, this step fails. Set it up with the video and check again

## Checkpoint

You are done when the Supabase SQL is applied, Auth is configured, Firebase has an Android app, `app/google-services.json` is ignored, `local.properties` holds only client-safe values, and the sign-in flows work.

---

- Previous lesson: [Service Account Checklist](https://dantech.academy/en/courses/kotlin-accelerator/engineer-builder/00-setup-app-running/lesson-03-service-account-checklist.md)
- Next lesson: [First Build, Test And Commit](https://dantech.academy/en/courses/kotlin-accelerator/engineer-builder/00-setup-app-running/lesson-05-first-build-test-commit.md)
