Total rebrand across KMM project: - Kotlin package: com.example.casera -> com.tt.honeyDue (dirs + declarations) - Gradle: rootProject.name, namespace, applicationId - Android: manifest, strings.xml (all languages), widget resources - iOS: pbxproj bundle IDs, Info.plist, entitlements, xcconfig - iOS directories: Casera/ -> HoneyDue/, CaseraTests/ -> HoneyDueTests/, etc. - Swift source: all class/struct/enum renames - Deep links: casera:// -> honeydue://, .casera -> .honeydue - App icons replaced with honeyDue honeycomb icon - Domains: casera.treytartt.com -> honeyDue.treytartt.com - Bundle IDs: com.tt.casera -> com.tt.honeyDue - Database table names preserved Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
6.6 KiB
Environment Configuration Guide
This guide explains how to easily switch between local development and the dev server when developing the HoneyDue iOS and Android apps.
Quick Start
To switch environments, change ONE line in ApiConfig.kt:
// File: composeApp/src/commonMain/kotlin/com/honeydue/shared/network/ApiConfig.kt
object ApiConfig {
// ⚠️ CHANGE THIS LINE ⚠️
val CURRENT_ENV = Environment.LOCAL // or Environment.DEV
}
Environment Options
1. Local Development (Environment.LOCAL)
Use this when:
- Running the Django API on your local machine
- Debugging API changes
- Working offline
Connects to:
- Android:
http://10.0.2.2:8000/api(Android emulator localhost alias) - iOS:
http://127.0.0.1:8000/api(iOS simulator localhost)
Setup:
val CURRENT_ENV = Environment.LOCAL
Requirements:
- Django API running on
http://localhost:8000 - Use
./dev.shto start the API with auto-reload
2. Dev Server (Environment.DEV)
Use this when:
- Testing against the deployed server
- You don't have the API running locally
- Testing with real data
Connects to:
- Both platforms:
https://honeyDue.treytartt.com/api
Setup:
val CURRENT_ENV = Environment.DEV
Requirements:
- Internet connection
- Dev server must be running and accessible
Step-by-Step Instructions
Switching to Local Development
-
Start your local API:
cd honeyDueAPI ./dev.sh -
Update
ApiConfig.kt:val CURRENT_ENV = Environment.LOCAL -
Rebuild the app:
- Android: Sync Gradle and run
- iOS: Clean build folder (⇧⌘K) and run
-
Verify in logs:
🌐 API Client initialized 📍 Environment: Local (10.0.2.2:8000) 🔗 Base URL: http://10.0.2.2:8000/api
Switching to Dev Server
-
Update
ApiConfig.kt:val CURRENT_ENV = Environment.DEV -
Rebuild the app:
- Android: Sync Gradle and run
- iOS: Clean build folder (⇧⌘K) and run
-
Verify in logs:
🌐 API Client initialized 📍 Environment: Dev Server (honeyDue.treytartt.com) 🔗 Base URL: https://honeyDue.treytartt.com/api
Platform-Specific Localhost Addresses
The localhost addresses are automatically determined by platform:
| Platform | Localhost Address | Reason |
|---|---|---|
| Android Emulator | 10.0.2.2 |
Special alias for host machine's localhost |
| iOS Simulator | 127.0.0.1 |
Standard localhost (simulator shares network with host) |
| Android Device | Your machine's IP | Must manually set in ApiClient.android.kt |
| iOS Device | Your machine's IP | Must manually set in ApiClient.ios.kt |
Testing on Physical Devices
If you need to test on a physical device with local API:
-
Find your machine's IP address:
# macOS/Linux ifconfig | grep "inet " # Look for something like: 192.168.1.xxx -
Update platform-specific file:
Android (
ApiClient.android.kt):actual fun getLocalhostAddress(): String = "192.168.1.xxx"iOS (
ApiClient.ios.kt):actual fun getLocalhostAddress(): String = "192.168.1.xxx" -
Ensure your device is on the same WiFi network as your machine
-
Update Django's
ALLOWED_HOSTS:# honeyDueAPI/honeyDue/settings.py ALLOWED_HOSTS = ['localhost', '127.0.0.1', '192.168.1.xxx']
File Structure
HoneyDueKMM/composeApp/src/
├── commonMain/kotlin/com/honeydue/shared/network/
│ ├── ApiConfig.kt # ⭐ TOGGLE ENVIRONMENT HERE
│ └── ApiClient.kt # Uses ApiConfig
├── androidMain/kotlin/com/honeydue/shared/network/
│ └── ApiClient.android.kt # Android localhost: 10.0.2.2
└── iosMain/kotlin/com/honeydue/shared/network/
└── ApiClient.ios.kt # iOS localhost: 127.0.0.1
Troubleshooting
Android: "Unable to connect to server"
Problem: Android can't reach localhost
Solutions:
- Use
10.0.2.2instead oflocalhostor127.0.0.1 - Make sure API is running on
0.0.0.0:8000, not just127.0.0.1:8000 - Check that
CURRENT_ENV = Environment.LOCAL
iOS: "Connection refused"
Problem: iOS simulator can't connect
Solutions:
- Use
127.0.0.1for iOS simulator - Make sure Django is running
- Try accessing
http://127.0.0.1:8000/apiin Safari on your Mac - Check firewall settings
Dev Server: SSL/Certificate errors
Problem: HTTPS connection issues
Solutions:
- Verify server is accessible:
curl https://honeyDue.treytartt.com/api - Check that SSL certificate is valid
- Make sure you're using
https://nothttp://
Changes not taking effect
Problem: Environment change not working
Solutions:
- Clean and rebuild:
- Android: Build → Clean Project, then rebuild
- iOS: Product → Clean Build Folder (⇧⌘K)
- Invalidate caches:
- Android Studio: File → Invalidate Caches
- Check logs for current environment:
- Look for
🌐 API Client initializedlog message
- Look for
Best Practices
-
Commit with LOCAL: Always commit code with
Environment.LOCALso teammates use their local API by default -
Document API changes: If you change the API, update both local and dev server
-
Test both environments: Before deploying, test with both LOCAL and DEV
-
Use dev server for demos: Switch to DEV when showing the app to others
-
Keep localhost addresses: Don't commit IP addresses, use the platform-specific aliases
Quick Reference
| Action | Command/File |
|---|---|
| Toggle environment | Edit ApiConfig.kt → CURRENT_ENV |
| Start local API | cd honeyDueAPI && ./dev.sh |
| Android localhost | 10.0.2.2:8000 |
| iOS localhost | 127.0.0.1:8000 |
| Dev server | https://honeyDue.treytartt.com |
| View current env | Check app logs for 🌐 emoji |
Example Workflow
Morning: Start work
// ApiConfig.kt
val CURRENT_ENV = Environment.LOCAL // ✅ Use local API
cd honeyDueAPI
./dev.sh # Start local server
# Work on features...
Testing: Check remote data
// ApiConfig.kt
val CURRENT_ENV = Environment.DEV // ✅ Use dev server
# Rebuild app and test
Before commit
// ApiConfig.kt
val CURRENT_ENV = Environment.LOCAL // ✅ Reset to LOCAL
git add .
git commit -m "Add new feature"
Need help? Check the logs when the app starts - they'll tell you exactly which environment and URL is being used!