# Cara Install Android SDK dan Build APK

## Opsi 1: Menggunakan Android Studio (Recommended)

### 1. Download dan Install Android Studio
- Download dari: https://developer.android.com/studio
- Install Android Studio
- Saat pertama kali buka, ikuti wizard setup untuk install Android SDK

### 2. Konfigurasi SDK
Setelah Android Studio terinstall, SDK biasanya ada di:
- Windows: `C:\Users\[USERNAME]\AppData\Local\Android\Sdk`
- Mac: `~/Library/Android/sdk`
- Linux: `~/Android/Sdk`

### 3. Set Environment Variable (Optional tapi recommended)
Windows:
```
setx ANDROID_HOME "C:\Users\[USERNAME]\AppData\Local\Android\Sdk"
setx PATH "%PATH%;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools"
```

### 4. Build APK via Android Studio
```bash
# Buka project di Android Studio
npx cap open android

# Di Android Studio:
# Build > Build Bundle(s) / APK(s) > Build APK(s)
```

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

### 5. Build APK via Command Line
Setelah Android Studio terinstall:
```bash
cd dms-sales-app/android
./gradlew assembleDebug
```

---

## Opsi 2: Install Command Line Tools Only (Tanpa Android Studio)

### 1. Download Command Line Tools
- Download dari: https://developer.android.com/studio#command-tools
- Extract ke folder, misalnya: `C:\Android\cmdline-tools`

### 2. Install SDK Components
```bash
cd C:\Android\cmdline-tools\bin
sdkmanager "platform-tools" "platforms;android-33" "build-tools;33.0.0"
```

### 3. Buat local.properties
Buat file `dms-sales-app/android/local.properties`:
```
sdk.dir=C:\\Android
```

### 4. Build APK
```bash
cd dms-sales-app/android
./gradlew assembleDebug
```

---

## Opsi 3: Build Online (Tanpa Install SDK)

Gunakan layanan online seperti:
- **Expo EAS Build** (untuk React Native/Capacitor)
- **Appetize.io** (untuk testing)
- **GitHub Actions** (CI/CD dengan Android SDK pre-installed)

---

## Troubleshooting

### Error: SDK location not found
Buat file `android/local.properties`:
```
sdk.dir=C:\\Users\\[USERNAME]\\AppData\\Local\\Android\\Sdk
```

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

Download JDK dari: https://adoptium.net/

### Error: Gradle build failed
Clean dan rebuild:
```bash
cd android
./gradlew clean
./gradlew assembleDebug
```

---

## Quick Start (Jika SDK Sudah Terinstall)

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

# 2. Sync dengan Capacitor
npx cap sync android

# 3. Build APK
cd android
./gradlew assembleDebug

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

---

## Install APK ke Device

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

### Via File Transfer:
1. Copy file `app-debug.apk` ke device
2. Buka file di device
3. Allow "Install from Unknown Sources" jika diminta
4. Install aplikasi
