# Android Device Setup - FIXED & READY

## ✅ All Issues Fixed

Your development machine is now ready. Here's what was fixed:

- ✅ Java 21 installed
- ✅ Flutter 3.41.0 working
- ✅ `adb` (Android Debug Bridge) now working (replaced x86-64 with ARM64 native binary)
- ✅ Android SDK configured

---

## Ready-to-Go Commands

Copy & paste these into your terminal:

```bash
export PATH="/mnt/ssd_data/flutter/bin:$PATH"
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-arm64
export ANDROID_HOME=/mnt/ssd_data/android-sdk
```

Then verify everything works:
```bash
flutter devices
# Should show at least: Linux (desktop)
```

When you plug in your Android phone via USB, run this again and you should see your phone listed.

---

## Next Steps - Connect Your Android Phone

### 1. **Enable USB Debugging on Phone**

On your Android phone:
1. Open **Settings** 
2. Tap **About phone** (usually at bottom)
3. Find **Build number** and tap it **7 times** rapidly
4. A toast message will say "Developer mode enabled"
5. Go back to Settings, open **Developer options** (now visible)
6. Enable **USB Debugging**

### 2. **Plug Phone via USB**

- Connect your phone to the dev machine with a USB cable
- On the phone, you'll see a prompt: **"Allow USB debugging from this computer?"**
- Tap **Allow** (optionally check "Always allow")

### 3. **Verify Connection**

```bash
flutter devices
# You should now see:
# Linux (desktop) • linux • ...
# Your Phone Name  • android • ...
```

### 4. **Update API URL in Code**

Find your dev machine's LAN IP:
```bash
hostname -I
# Look for something like 192.168.1.100 (NOT 127.0.0.1)
```

Edit `/mnt/ssd_data/mysportmanager-shared/lib/config/app_constants.dart`:

Find this line (around line 19):
```dart
static const String localApiUrl = 'http://192.168.1.100/early_access/api';
```

Replace `192.168.1.100` with your actual LAN IP.

Save the file.

### 5. **Run the App**

```bash
cd /mnt/ssd_data/mysportmanager-shared

# Set environment again
export PATH="/mnt/ssd_data/flutter/bin:$PATH"
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-arm64
export ANDROID_HOME=/mnt/ssd_data/android-sdk

# Get dependencies
flutter pub get

# Run on phone (replace <DEVICE_ID> with your phone's ID from flutter devices)
flutter run -d <DEVICE_ID>
```

Example:
```bash
flutter run -d emulator-5554
# or
flutter run -d 192.168.1.50:5555
```

---

## What to Expect

1. **First run:** App will compile and install on phone (~2-3 minutes)
2. **App launches:** You'll see the **My Sport Manager** splash screen
3. **Login screen:** Shows username/password fields
4. **Test credentials:**
   - Username: `testuser`
   - Password: `TestPassword123!`
   - (Use valid test accounts from your database)

5. **After login:** Dashboard shows:
   - User info card
   - Athletes list
   - Upcoming competitions
   - Recent activities

6. **Test navigation:**
   - Tap an athlete → see detail page with best times & competition history
   - Tap back → returns to athletes list
   - Tap Dashboard tab → back to main dashboard

---

## Hot Reload During Development

While the app is running on your phone:

- Press **`R`** in terminal → Hot reload (fast, keeps app state)
- Press **`r`** → Restart app (full reload)
- Press **`q`** → Quit and disconnect

---

## Troubleshooting

### "Device not detected"
```bash
# Unplug and re-plug the USB cable
adb devices
# Should list your phone
```

### "Connection refused" when logging in
- Your phone can't reach the API server
- Verify both devices are on same Wi-Fi
- Check you updated the IP correctly in app_constants.dart
- From phone's browser, test: `http://<YOUR_IP>/early_access/api/dashboard`

### Build fails
```bash
flutter clean
flutter pub get
flutter run -d <DEVICE_ID>
```

### App crashes
```bash
flutter logs
# Shows real-time error logs from the app
```

---

## Success Indicators

✅ You'll know it's working when:
1. `flutter devices` shows your phone
2. App builds and installs without errors
3. Login succeeds with valid credentials
4. Dashboard displays athlete data from the API
5. Tapping buttons navigates between screens
6. Hot reload works (code changes appear instantly)

---

## Support

If you get stuck:
1. Check the error in the terminal
2. Run `flutter doctor` to diagnose environment issues
3. Check server logs: `tail -f /var/log/apache2/error.log`
4. Verify API is up: `curl http://<YOUR_IP>/early_access/api/dashboard`

You're all set! Plug in your phone and run `flutter run` 🚀
