Build & Compilation Issues
Build fails with 'Gradle sync failed' on Android
Build fails with 'Gradle sync failed' on Android
- AGP (Android Gradle Plugin) version incompatibility
- Java version mismatch
- Cached build artifacts
-
Clean the build cache:
-
Check AGP version in
android/build.gradle: -
Ensure Java 17 is installed:
-
Update Gradle wrapper:
activity_recognition_flutter.iOS build fails with CocoaPods errors
iOS build fails with CocoaPods errors
pod install fails or iOS build errors related to dependencies.Solutions:-
Update CocoaPods:
-
Clean and reinstall pods:
-
Check Xcode version:
-
Set deployment target in
ios/Podfile:
Flutter SDK version mismatch
Flutter SDK version mismatch
-
Check Flutter version:
-
Update Flutter:
-
Switch Flutter channel (if needed):
-
Verify Dart SDK:
Package version conflicts
Package version conflicts
flutter pub get.Solutions:-
Run pub get with verbose output:
-
Check for conflicting dependencies:
-
Update specific package:
-
Clear pub cache:
google_generative_aidowngraded from ^0.5.0 to ^0.4.0 for stabilityscreen_statepinned to exact version 5.0.0
Permission Errors
Camera permission denied on Android
Camera permission denied on Android
-
Add permissions to
android/app/src/main/AndroidManifest.xml: -
Request runtime permissions (Android 6+):
-
Check app settings:
- Settings → Apps → Vitu → Permissions → Camera → Allow
-
Test on different Android versions:
- Android 6-10: Runtime permissions
- Android 11+: Scoped storage
Location permission denied
Location permission denied
-
Android: Add to
AndroidManifest.xml: -
iOS: Add to
Info.plist: -
Runtime request (lib/main.dart:1739-1769):
-
Enable location services:
- Android: Settings → Location → On
- iOS: Settings → Privacy → Location Services → On
Sensor access errors
Sensor access errors
-
Check sensor availability:
-
Android: Add to
AndroidManifest.xml: - Test on physical device: Sensors don’t work on most emulators
- Calibrate sensors: Settings → System → Sensors (device-specific)
Photo library access denied on iOS
Photo library access denied on iOS
-
Add to
ios/Runner/Info.plist: -
Check iOS version compatibility:
- iOS 14+: Limited photos access
- iOS 11-13: Full library access
-
Reset permissions (for testing):
- Settings → General → Reset → Reset Location & Privacy
Gemini API Issues
Gemini API key invalid or expired
Gemini API key invalid or expired
-
Generate new API key:
- Visit: https://aistudio.google.com/app/apikey
- Create new key or regenerate existing
- Copy to clipboard
-
Update in code (lib/main.dart:489):
-
Use environment variables (recommended):
Run with:
-
Verify key restrictions:
- Check API key hasn’t been restricted by IP/domain
- Ensure Generative Language API is enabled
Rate limit exceeded
Rate limit exceeded
- 60 requests per minute
- 1,500 requests per day
- 1 million tokens per day
-
Implement request throttling:
-
Cache responses:
- Store recent analyses in Hive
- Avoid re-analyzing same image
- Upgrade to paid tier: https://ai.google.dev/pricing
- Monitor usage: Check quota in Google Cloud Console
Gemini returns empty or invalid response
Gemini returns empty or invalid response
resp.text is null or doesn’t match expected format.Solutions:-
Check prompt format (lib/main.dart:646-658):
-
Add response validation:
-
Handle parsing errors (lib/main.dart:681-711):
-
Verify model name:
- Use
gemini-2.5-flash(latest) - Fallback to
gemini-pro-visionif needed
- Use
Image too large for Gemini API
Image too large for Gemini API
- Max file size: 4MB (recommended < 2MB)
- Supported formats: JPEG, PNG, WebP
- Max dimensions: 3000x3000px
-
Compress image (lib/main.dart:536-539):
-
Check file size before upload:
-
Use image compression package:
Network connectivity issues
Network connectivity issues
SocketException or “No internet connection” errors.Solutions:-
Check internet connectivity:
-
Add timeout to requests (lib/main.dart:665-666):
-
Implement retry logic:
-
Add error UI (lib/main.dart:614-627):
Data & Storage Issues
Hive box not opened or corrupted
Hive box not opened or corrupted
-
Ensure boxes are opened (lib/main.dart:23-28):
-
Delete corrupted box:
-
Clear all Hive data (for testing):
-
Check box names match:
User data not persisting
User data not persisting
-
Verify save operations (lib/main.dart:150-153):
-
Check key format:
-
Flush data manually:
-
Debug stored data:
Exercise/hydration data not showing
Exercise/hydration data not showing
-
Verify date key format (lib/main.dart:221-222):
-
Check composite keys:
-
Inspect box contents:
-
Verify data structure:
Platform-Specific Issues
Android build fails with 'MultiDex' error
Android build fails with 'MultiDex' error
-
Enable MultiDex in
android/app/build.gradle: -
Update Application class (if custom):
iOS app crashes on launch
iOS app crashes on launch
-
Check Xcode console for error:
-
Verify Info.plist is valid XML:
-
Clean derived data:
-
Check minimum iOS version:
- Vitu requires iOS 12.0+
- Update in
ios/Podfileif needed
Web build size too large
Web build size too large
-
Build in release mode:
-
Enable tree shaking:
-
Split deferred loading (advanced):
Runtime Errors
'setState() called after dispose()' error
'setState() called after dispose()' error
-
Check mounted before setState:
-
Cancel async operations in dispose:
-
Use State lifecycle properly:
Memory leaks / app slowdown over time
Memory leaks / app slowdown over time
-
Dispose controllers properly:
-
Cancel stream subscriptions:
-
Use DevTools to profile:
-
Limit list growth (lib/main.dart:1796-1802):
Debugging Tips
Enable Verbose Logging
Check Logs by Platform
Android:Use Flutter DevTools
- Widget Inspector
- Memory Profiler
- Performance Timeline
- Network Monitor
Getting Help
Resources
- Flutter Docs: https://docs.flutter.dev
- Gemini AI Docs: https://ai.google.dev/docs
- Hive Docs: https://docs.hivedb.dev
- Stack Overflow: https://stackoverflow.com/questions/tagged/flutter
Reporting Issues
When reporting bugs, include:- Flutter version (
flutter --version) - Platform and OS version
- Full error stack trace
- Steps to reproduce
- Expected vs actual behavior
Debug Checklist
- Run
flutter doctorand fix all issues - Check all permissions are granted
- Verify API keys are valid
- Test on physical device (not just emulator)
- Check network connectivity
- Review logs for error messages
- Try
flutter clean && flutter pub get - Update to latest stable Flutter version