# Panduan Build APK Android

## Langkah-langkah Build APK

### 1. Install Dependencies
```bash
npm install
```

### 2. Build Aplikasi React
```bash
npm run build
```

### 3. Sync dengan Capacitor
```bash
npx cap sync android
```

### 4. Buka di Android Studio
```bash
npx cap open android
```

### 5. Build APK di Android Studio

Setelah Android Studio terbuka:

1. Tunggu Gradle sync selesai
2. Pilih menu **Build > Build Bundle(s) / APK(s) > Build APK(s)**
3. Tunggu proses build selesai
4. Klik **locate** pada notifikasi untuk membuka folder APK
5. APK tersimpan di: `android/app/build/outputs/apk/debug/app-debug.apk`

## Alternatif: Build via Command Line

Jika sudah setup Android SDK di PATH:

```bash
cd android
./gradlew assembleDebug
```

APK akan tersimpan di `android/app/build/outputs/apk/debug/app-debug.apk`

## Build APK Release (Signed)

Untuk production APK yang bisa di-upload ke Play Store:

1. Generate keystore:
```bash
keytool -genkey -v -keystore dms-sales.keystore -alias dms-sales -keyalg RSA -keysize 2048 -validity 10000
```

2. Edit `android/app/build.gradle`, tambahkan:
```gradle
android {
    ...
    signingConfigs {
        release {
            storeFile file('../../dms-sales.keystore')
            storePassword 'your-password'
            keyAlias 'dms-sales'
            keyPassword 'your-password'
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
            ...
        }
    }
}
```

3. Build release APK:
```bash
cd android
./gradlew assembleRelease
```

APK release tersimpan di `android/app/build/outputs/apk/release/app-release.apk`

## Troubleshooting

### Error: ANDROID_HOME not set
Set environment variable ANDROID_HOME ke lokasi Android SDK:
```bash
# Windows
set ANDROID_HOME=C:\Users\YourName\AppData\Local\Android\Sdk

# Linux/Mac
export ANDROID_HOME=$HOME/Android/Sdk
```

### Error: Java version
Pastikan menggunakan JDK 11 atau lebih baru:
```bash
java -version
```

### Error: Gradle sync failed
Buka Android Studio dan sync manual, atau jalankan:
```bash
cd android
./gradlew clean
```

## Testing APK

Install APK ke device/emulator:
```bash
adb install android/app/build/outputs/apk/debug/app-debug.apk
```

Atau transfer file APK ke device dan install manual.
