This project uses local.properties to store sensitive API keys. This file is gitignored and will not be committed to version control.
- News API Key (
NEWS_API_KEY)- Used for: Fetching news articles from NewsAPI.org
- Location:
local.properties - Access in code:
BuildConfig.NEWS_API_KEY
- Copy
local.properties.exampletolocal.properties - Add your actual API keys to
local.properties - Never commit
local.propertiesto Git
- local.properties - Stores the actual API keys (gitignored)
- build.gradle.kts - Reads from
local.propertiesand creates BuildConfig fields - Code - Uses
BuildConfig.NEWS_API_KEYto access the key
To add a new API key:
-
Add to
local.properties:YOUR_NEW_API_KEY=your_actual_key_here -
Add to
app/build.gradle.ktsin thedefaultConfigblock:buildConfigField("String", "YOUR_NEW_API_KEY", "\"${properties.getProperty("YOUR_NEW_API_KEY", "")}\"")
-
Use in code:
val apiKey = BuildConfig.YOUR_NEW_API_KEY
-
Update
local.properties.examplewith placeholder:YOUR_NEW_API_KEY=your_key_here
✅ DO:
- Keep API keys in
local.properties - Use BuildConfig to access keys
- Add new keys to
local.properties.exampleas placeholders - Rotate keys if they are compromised
❌ DON'T:
- Hardcode API keys in source code
- Commit
local.propertiesto Git - Share API keys publicly
- Log API keys to console
- Immediately revoke the compromised key from the API provider's dashboard
- Generate a new key from the API provider
- Update
local.propertieswith the new key - Notify team members to update their local files
- Review commit history to ensure the key wasn't committed
- If committed, consider using tools like
git-filter-branchor BFG Repo-Cleaner to remove it from history
bcad6e37557b454d41130d680f6ec8b9 was previously hardcoded and may be exposed in Git history.
Action Required:
- Generate a new API key from https://newsapi.org/
- Update
local.propertieswith the new key - Revoke the old key from the NewsAPI dashboard
When setting up CI/CD:
- Add API keys as environment variables or secrets in your CI/CD platform
- Use build scripts to inject them into
local.propertiesduring build - Never expose keys in build logs