# Build Commands - DMS Sales App

## Quick Build Commands

### Android APK

#### Debug APK (untuk testing)
```bash
# 1. Build React app
npm run build

# 2. Sync to Android
npx cap sync android

# 3. Build APK
cd android
gradlew assembleDebug
cd ..
```

APK location: `android/app/build/outputs/apk/debug/app-debug.apk`

#### Release APK (untuk production)
```bash
# 1. Build React app
npm run build

# 2. Sync to Android
npx cap sync android

# 3. Build Release APK
cd android
gradlew assembleRelease
cd ..
```

APK location: `android/app/build/outputs/apk/release/app-release.apk`

### iOS App

#### Development Build
```bash
# 1. Build React app
npm run build

# 2. Add iOS platform (first time only)
npx cap add ios

# 3. Sync to iOS
npx cap sync ios

# 4. Open in Xcode
npx cap open ios
```

Then in Xcode: Product > Run (⌘R)

#### Production Build
```bash
# 1. Build React app
npm run build

# 2. Sync to iOS
npx cap sync ios

# 3. Open in Xcode
npx cap open ios
```

Then in Xcode: Product > Archive

## One-Line Commands

### Android Debug
```bash
npm run build && npx cap sync android && cd android && gradlew assembleDebug && cd ..
```

### Android Release
```bash
npm run build && npx cap sync android && cd android && gradlew assembleRelease && cd ..
```

### iOS
```bash
npm run build && npx cap sync ios && npx cap open ios
```

## PowerShell Commands (Windows)

### Android Debug
```powershell
npm run build; npx cap sync android; Push-Location android; .\gradlew.bat assembleDebug; Pop-Location
```

### Android Release
```powershell
npm run build; npx cap sync android; Push-Location android; .\gradlew.bat assembleRelease; Pop-Location
```

### Open Android Studio
```powershell
npx cap open android
```

## Bash Commands (Mac/Linux)

### Android Debug
```bash
npm run build && npx cap sync android && cd android && ./gradlew assembleDebug && cd ..
```

### Android Release
```bash
npm run build && npx cap sync android && cd android && ./gradlew assembleRelease && cd ..
```

### iOS
```bash
npm run build && npx cap sync ios && npx cap open ios
```

## Build Status

✅ **Android Debug APK** - Successfully built!
- Location: `android/app/build/outputs/apk/debug/app-debug.apk`
- Size: ~4.3 MB
- Ready for testing on Android devices

⏳ **iOS App** - Requires macOS with Xcode
- Follow iOS build instructions in BUILD_IOS.md
- Requires Apple Developer Account for device testing

## Testing

### Install APK on Android Device

#### Via USB (ADB)
```bash
adb install android/app/build/outputs/apk/debug/app-debug.apk
```

#### Via File Transfer
1. Copy APK to device
2. Open file manager on device
3. Tap APK file
4. Allow installation from unknown sources if prompted
5. Install

### Test on iOS Device

#### Via Xcode
1. Connect iPhone/iPad via USB
2. Open project in Xcode
3. Select your device
4. Click Run (⌘R)

#### Via TestFlight
1. Archive and upload to App Store Connect
2. Add testers in TestFlight
3. Testers install via TestFlight app

## Clean Build

If you encounter issues, clean and rebuild:

### Android
```bash
cd android
gradlew clean
gradlew assembleDebug
cd ..
```

### iOS
```bash
cd ios/App
pod deintegrate
pod install
cd ../..
npx cap sync ios
```

## Update Native Code

After adding new Capacitor plugins:

```bash
npm install
npx cap sync
```

## Live Reload (Development)

For faster development with live reload:

```bash
# Terminal 1: Start React dev server
npm start

# Terminal 2: Run on Android with live reload
npx cap run android -l --external

# Or for iOS
npx cap run ios -l --external
```

## Production Checklist

Before building for production:

- [ ] Update version in `package.json`
- [ ] Update version code in `android/app/build.gradle`
- [ ] Update version in `ios/App/App.xcodeproj`
- [ ] Test all features
- [ ] Optimize images and assets
- [ ] Remove console.logs
- [ ] Update app icons and splash screens
- [ ] Test on multiple devices
- [ ] Create release notes

## Troubleshooting

### Gradle build fails
```bash
cd android
gradlew clean
cd ..
npm run build
npx cap sync android
cd android
gradlew assembleDebug
```

### iOS build fails
```bash
cd ios/App
pod repo update
pod install
cd ../..
npx cap sync ios
```

### Web assets not updating
```bash
npm run build
npx cap copy
```

## Resources

- [Capacitor Documentation](https://capacitorjs.com/docs)
- [Android Studio](https://developer.android.com/studio)
- [Xcode](https://developer.apple.com/xcode/)
- [Gradle Documentation](https://gradle.org/guides/)
