# Generate Android APK for RBS Regal Business Suite

You can convert this PWA into a Google-Play-ready Android APK using either of these zero-server-side-setup paths.

---

## 🚀 Fastest: PWABuilder (Microsoft) — 2 minutes, no install

1. Open <https://www.pwabuilder.com> in any browser.
2. Paste the production URL: `https://offline-billing-pro-2.emergent.host`
3. Click **Start**. PWABuilder will score the PWA (manifest + SW + HTTPS).
4. Click **Package for Stores** → **Android** → **Generate**.
5. Choose:
   - Package name: `com.rbsregal.business`
   - App version: `6.0.0`
   - Signing key: **Let PWABuilder generate a new one** (download the `.keystore` + `signing-key-info.txt` — **store these safely**, you'll need them for every future update).
6. Download the `.zip` — it contains:
   - `app-release-signed.apk`  ← direct-install APK (sideloadable)
   - `app-release-bundle.aab`  ← Google Play upload bundle
   - `assetlinks.json`         ← see below
7. Upload the APK to your server at `/downloads/rbs-regal.apk` (place at `/app/frontend/public/downloads/rbs-regal.apk`). The `/install` page will auto-detect it and enable the "Download APK" button.
8. Upload `assetlinks.json` to `/.well-known/assetlinks.json` (place at `/app/frontend/public/.well-known/assetlinks.json`). This unlocks **Trusted Web Activity** — the APK loads your live PWA instead of bundling assets, so updates are instant.

---

## 🛠️ Power-user: Bubblewrap CLI (Google) — full control

Run on your own machine (Linux/Mac with Node 18+ and JDK 17+):

```bash
npm i -g @bubblewrap/cli
bubblewrap init --manifest https://offline-billing-pro-2.emergent.host/manifest.json
# Follow prompts. Output is a Gradle project in ./
bubblewrap build
# Produces ./app-release-signed.apk
```

Then upload the same way as above (APK → `/downloads/`, assetlinks → `/.well-known/`).

---

## 📦 Why this approach?

- **APK is just a TWA (Trusted Web Activity) wrapper** — it opens your live PWA inside a Chrome Custom Tab without browser chrome. Updates to your web app reach all installed APKs instantly. No re-publishing needed unless you change package identity.
- **One signing key, forever** — keep the `.keystore` somewhere safe (offline + cloud backup). Lose it and you can't push updates to Play Store.
- **No native compile in this container** — we don't ship JDK/Gradle in this Kubernetes pod (would bloat the image by ~1 GB), so APK signing happens externally. PWABuilder does it for free in 2 minutes.

---

## ✅ Once the APK is uploaded

1. Upload to: `/app/frontend/public/downloads/rbs-regal.apk`
2. Upload assetlinks to: `/app/frontend/public/.well-known/assetlinks.json`
3. **Redeploy** to production.
4. Users visit `https://offline-billing-pro-2.emergent.host/install` → "Download APK" button is now live.
5. Share QR code from the same page with your team.

---

## 🧪 Test locally

```bash
# Verify the install page renders
curl -I https://offline-billing-pro-2.preview.emergentagent.com/install
# Verify the APK is served (after upload):
curl -I https://offline-billing-pro-2.emergent.host/downloads/rbs-regal.apk
# Verify Digital Asset Links:
curl https://offline-billing-pro-2.emergent.host/.well-known/assetlinks.json
```

The `/install` page probes the APK URL via HEAD request — if 200, the "Download APK" CTA shows. If 404, a "Generate APK on PWABuilder.com" fallback is shown instead.
