This project uses Firebase for authentication, Firestore database, and analytics. Follow this guide to set up Firebase for your project.
- A Google account
- Access to Firebase Console
- Android Studio
-
Create a new project in Firebase Console:
- Go to Firebase Console
- Click "Add project"
- Enter your project name
- Follow the setup wizard
-
Add Android app to your Firebase project:
- Click on Android icon in project overview
- Register app using your package name (
dev.your.package.name
) - Get the SHA-1 using the provided Signing Report configuration:
- Open Android Studio
- Run the "Signing Report" configuration from the run configurations dropdown
- Copy the SHA-1 hash
- Enter the SHA-1 in Firebase console
-
Enable Required Services:
a. Authentication:
- Go to "Authentication" in Firebase Console
- Click "Get Started"
- Enable "Google" sign-in method
- Enable "Email/Password" sign-in method
- Add your support email
b. Firestore:
- Go to "Firestore Database"
- Click "Create Database"
- Choose your location
- Start in production mode
-
Download Configuration File:
- Download
google-services.json
from Firebase Console - Before replacing the template file, stop Git from tracking it:
git update-index --skip-worktree app/google-services.json
- Replace the template
google-services.json
in theapp
directory with your downloaded file
- Download
-
Verify Firebase Setup:
- Build and run the app
- Try signing in with Google
- Check Firebase Console to verify authentication is working
Warning
Never commit your actual google-services.json
to version control. The template file is provided
only to ensure successful builds.
Common issues and solutions:
-
Google Sign-In Not Working:
- Verify SHA-1 is correctly added in Firebase Console
- Check if
google-services.json
is up to date - Ensure the OAuth consent screen is configured
-
Firestore Access Issues:
- Check your Firestore rules
- Verify your device has internet connection
- Check if the user is properly authenticated
-
Build Issues:
- Clean and rebuild the project
- Verify
google-services.json
is in the correct location - Check if all Firebase dependencies are resolved
Tip
If you need to get the SHA-1 hash again later, you can always run the "Signing Report" configuration from Android Studio.
The project handles Firebase configuration files in several ways:
-
Development:
- Use your local
google-services.json
- Keep it private using
git update-index --skip-worktree
- Use your local
-
CI/CD:
- GitHub Actions workflow uses encoded secrets
- See GitHub CI/CD Setup for details
Note
The template google-services.json
allows the project to build but won't enable Firebase
services. You must replace it with your own configuration file.
Set up security rules in Firebase Console to protect your data:
-
Go to Firestore Database
-
Click on "Rules" tab
-
Replace the default rules with the following structure:
rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { // Helper function to check if user is authenticated function isAuthenticated() { return request.auth != null; } // Helper function to check if the user is accessing their own data function isUserOwner(userId) { return isAuthenticated() && request.auth.uid == userId; } // Helper function to validate Jetpack data structure function isValidJetpack(jetpack) { return jetpack.size() == 7 && 'id' in jetpack && jetpack.id is string // ... other validations } // Match the specific path structure: dev.atick.jetpack/{userId}/jetpacks/{jetpackId} match /dev.atick.jetpack/{userId}/jetpacks/{jetpackId} { allow read: if isUserOwner(userId); allow create: if isUserOwner(userId) && isValidJetpack(request.resource.data); allow update: if isUserOwner(userId) && isValidJetpack(request.resource.data) && request.resource.data.id == resource.data.id; allow delete: if isUserOwner(userId); } // Deny access to all other documents by default match /{document=**} { allow read, write: if false; } } }
These rules implement several security features:
- User authentication check
- Data ownership validation
- Document structure validation
- Explicit deny-by-default for unmatched paths
Important
Always test your security rules thoroughly using the Firebase Console Rules Playground before deploying to production.
-
Test Your Configuration:
// Add this in an activity or fragment FirebaseAuth.getInstance().currentUser?.let { Timber.d("Firebase Auth is working: ${it.email}") }
-
Reset Git Tracking (if needed):
git update-index --no-skip-worktree app/google-services.json
-
Multiple Environments:
- Create separate Firebase projects for development and production
- Manage different
google-services.json
files for each build variant
Important
Remember to add your google-services.json
to .gitignore
if you're setting up the project from
scratch.