Spaces:
Running
Running
feat(android): bake SDK in Docker; return debug APK from download (zip fallback)
Browse files- ANDROID.md +23 -27
- Dockerfile +42 -5
- README.md +1 -1
- README_HF.md +1 -1
- RESULT.md +29 -41
- SPEC.md +2 -2
- backend/app/api/routes.py +4 -2
- backend/app/config.py +2 -1
- backend/app/converters/base.py +1 -0
- backend/app/converters/mobile/android.py +28 -63
- backend/app/converters/mobile/android_sdk.py +48 -0
- backend/app/converters/mobile/finalize.py +227 -0
- backend/app/providers/huggingface.py +11 -5
- backend/app/services/builds.py +18 -3
- backend/tests/test_converters.py +11 -4
- backend/tests/test_provider.py +2 -2
- frontend/src/i18n/en.ts +1 -1
- scripts/docker_warmup_android.sh +50 -0
ANDROID.md
CHANGED
|
@@ -4,41 +4,37 @@
|
|
| 4 |
|
| 5 |
| | |
|
| 6 |
|--|--|
|
| 7 |
-
| **
|
|
|
|
| 8 |
| **Mode** | **Hosted Wrapper** (Hybrid runtime — WebView loads live Space URL) |
|
| 9 |
-
| **
|
| 10 |
-
| **Converter** | `backend/app/converters/mobile/android.py` |
|
| 11 |
|
| 12 |
## Compatibility badges (UI)
|
| 13 |
|
| 14 |
-
- ✓ **project** —
|
| 15 |
-
-
|
|
|
|
| 16 |
- ✗ **GPU local impossible** — when Space needs GPU; inference stays on Hugging Face
|
| 17 |
|
| 18 |
## What the user installs
|
| 19 |
|
| 20 |
-
1.
|
| 21 |
-
2.
|
| 22 |
-
3.
|
| 23 |
-
**or** `./scripts/build-android.sh` (needs `ANDROID_HOME`, JDK 17, Node 18+).
|
| 24 |
-
4. Install the **locally built** debug APK on a device/emulator.
|
| 25 |
|
| 26 |
## Labeling rules
|
| 27 |
|
| 28 |
-
- Never call the
|
| 29 |
-
- Correct: “Hosted Wrapper
|
| 30 |
-
-
|
| 31 |
-
|
| 32 |
-
##
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
README.md
|
| 42 |
-
ANDROID.md
|
| 43 |
-
spaceforge.json # binary_included/apk_included: false
|
| 44 |
-
```
|
|
|
|
| 4 |
|
| 5 |
| | |
|
| 6 |
|--|--|
|
| 7 |
+
| **Preferred** | **Debug APK** (`.apk`) when Android SDK + JDK are in the SpaceForge Docker image |
|
| 8 |
+
| **Fallback** | Capacitor 6 **Android project ZIP** if APK build fails / SDK missing |
|
| 9 |
| **Mode** | **Hosted Wrapper** (Hybrid runtime — WebView loads live Space URL) |
|
| 10 |
+
| **Unsigned** | Debug APK is **unsigned** (sideload / `adb install`); not Play Store release |
|
| 11 |
+
| **Converter** | `backend/app/converters/mobile/android.py` + `finalize.py` |
|
| 12 |
|
| 13 |
## Compatibility badges (UI)
|
| 14 |
|
| 15 |
+
- ✓ **project** — Capacitor + Gradle scaffold generated
|
| 16 |
+
- ✓ **APK included** — when `assembleDebug` succeeds inside SpaceForge
|
| 17 |
+
- ⚠ **APK not built** — fallback project zip only
|
| 18 |
- ✗ **GPU local impossible** — when Space needs GPU; inference stays on Hugging Face
|
| 19 |
|
| 20 |
## What the user installs
|
| 21 |
|
| 22 |
+
1. Analyze Space → select **Android (Capacitor)** → Build → **Download**.
|
| 23 |
+
2. If filename ends with `.apk`: transfer to a device and sideload (`adb install -r app.apk` or Files → install). Allow unknown sources if prompted.
|
| 24 |
+
3. If filename ends with `.zip` (fallback): unzip → `npm install` → `npx cap sync android` → Android Studio / `./scripts/build-android.sh`.
|
|
|
|
|
|
|
| 25 |
|
| 26 |
## Labeling rules
|
| 27 |
|
| 28 |
+
- Never call the Hosted Wrapper a “Local offline APK” of the model/GPU runtime.
|
| 29 |
+
- Correct: “Debug APK (Hosted Wrapper / WebView)” or “project zip fallback”.
|
| 30 |
+
- `binary_included` / `apk_included` are **true only** when a real `.apk` file is returned.
|
| 31 |
+
|
| 32 |
+
## Docker image
|
| 33 |
+
|
| 34 |
+
The Space Dockerfile bakes:
|
| 35 |
+
|
| 36 |
+
- OpenJDK 17, Node 20, Android cmdline-tools
|
| 37 |
+
- `platforms;android-34`, `build-tools;34.0.0`
|
| 38 |
+
- Optional Gradle warmup via `scripts/docker_warmup_android.sh`
|
| 39 |
+
|
| 40 |
+
Env: `ANDROID_HOME=/opt/android-sdk`, `SPACEFORGE_ANDROID_BUILD_TIMEOUT=900`.
|
|
|
|
|
|
|
|
|
|
|
|
Dockerfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# SpaceForge — Hugging Face Docker Space
|
| 2 |
FROM node:20-bookworm-slim AS frontend
|
| 3 |
WORKDIR /fe
|
| 4 |
COPY frontend/package.json frontend/package-lock.json* ./
|
|
@@ -7,18 +7,48 @@ COPY frontend/ ./
|
|
| 7 |
RUN npm run build
|
| 8 |
|
| 9 |
FROM python:3.11-slim-bookworm
|
|
|
|
| 10 |
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 11 |
PYTHONUNBUFFERED=1 \
|
| 12 |
SPACEFORGE_STATIC=/app/frontend/dist \
|
| 13 |
SPACEFORGE_TEMPLATES=/app/templates \
|
| 14 |
-
PORT=7860
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 19 |
-
ca-certificates curl \
|
|
|
|
| 20 |
&& rm -rf /var/lib/apt/lists/*
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
COPY requirements.txt .
|
| 23 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 24 |
|
|
@@ -27,7 +57,14 @@ COPY templates/ /app/templates/
|
|
| 27 |
COPY scripts/ /app/scripts/
|
| 28 |
COPY --from=frontend /fe/dist /app/frontend/dist
|
| 29 |
|
| 30 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
EXPOSE 7860
|
| 32 |
|
| 33 |
CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# SpaceForge — Hugging Face Docker Space (with Android SDK for debug APK builds)
|
| 2 |
FROM node:20-bookworm-slim AS frontend
|
| 3 |
WORKDIR /fe
|
| 4 |
COPY frontend/package.json frontend/package-lock.json* ./
|
|
|
|
| 7 |
RUN npm run build
|
| 8 |
|
| 9 |
FROM python:3.11-slim-bookworm
|
| 10 |
+
|
| 11 |
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 12 |
PYTHONUNBUFFERED=1 \
|
| 13 |
SPACEFORGE_STATIC=/app/frontend/dist \
|
| 14 |
SPACEFORGE_TEMPLATES=/app/templates \
|
| 15 |
+
PORT=7860 \
|
| 16 |
+
JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 \
|
| 17 |
+
ANDROID_HOME=/opt/android-sdk \
|
| 18 |
+
ANDROID_SDK_ROOT=/opt/android-sdk \
|
| 19 |
+
GRADLE_USER_HOME=/opt/gradle-cache \
|
| 20 |
+
SPACEFORGE_ANDROID_SDK=1 \
|
| 21 |
+
SPACEFORGE_BUILD_TIMEOUT=900 \
|
| 22 |
+
SPACEFORGE_MAX_DOWNLOAD=104857600
|
| 23 |
|
| 24 |
+
# Node (from official image) + JDK 17 + unzip/curl for SDK
|
| 25 |
+
COPY --from=node:20-bookworm-slim /usr/local/bin/node /usr/local/bin/node
|
| 26 |
+
COPY --from=node:20-bookworm-slim /usr/local/lib/node_modules /usr/local/lib/node_modules
|
| 27 |
+
RUN ln -sf /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
|
| 28 |
+
&& ln -sf /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
|
| 29 |
|
| 30 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 31 |
+
ca-certificates curl wget unzip git \
|
| 32 |
+
openjdk-17-jdk-headless \
|
| 33 |
&& rm -rf /var/lib/apt/lists/*
|
| 34 |
|
| 35 |
+
# Minimal Android SDK (cmdline-tools + platform 34 + build-tools)
|
| 36 |
+
ARG CMDLINE_TOOLS_URL=https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
|
| 37 |
+
RUN mkdir -p ${ANDROID_HOME}/cmdline-tools ${ANDROID_HOME}/licenses ${GRADLE_USER_HOME} \
|
| 38 |
+
&& printf '%s\n' '24333f8a63b6825ea9c5514f83c2829b004d1fee' > ${ANDROID_HOME}/licenses/android-sdk-license \
|
| 39 |
+
&& printf '%s\n' '84831b9409646c91810b61fec6b53890' > ${ANDROID_HOME}/licenses/android-sdk-preview-license \
|
| 40 |
+
&& wget -q -O /tmp/cmdtools.zip "${CMDLINE_TOOLS_URL}" \
|
| 41 |
+
&& unzip -q /tmp/cmdtools.zip -d ${ANDROID_HOME}/cmdline-tools \
|
| 42 |
+
&& mv ${ANDROID_HOME}/cmdline-tools/cmdline-tools ${ANDROID_HOME}/cmdline-tools/latest \
|
| 43 |
+
&& rm /tmp/cmdtools.zip \
|
| 44 |
+
&& ${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager --sdk_root=${ANDROID_HOME} \
|
| 45 |
+
"platform-tools" "platforms;android-34" "build-tools;34.0.0" \
|
| 46 |
+
&& rm -rf ${ANDROID_HOME}/emulator ${ANDROID_HOME}/system-images || true
|
| 47 |
+
|
| 48 |
+
ENV PATH="${JAVA_HOME}/bin:${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/build-tools/34.0.0:/usr/local/bin:${PATH}"
|
| 49 |
+
|
| 50 |
+
WORKDIR /app
|
| 51 |
+
|
| 52 |
COPY requirements.txt .
|
| 53 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 54 |
|
|
|
|
| 57 |
COPY scripts/ /app/scripts/
|
| 58 |
COPY --from=frontend /fe/dist /app/frontend/dist
|
| 59 |
|
| 60 |
+
# Warm Gradle + Capacitor Android deps so first user APK build is faster
|
| 61 |
+
COPY scripts/docker_warmup_android.sh /tmp/docker_warmup_android.sh
|
| 62 |
+
RUN chmod +x /tmp/docker_warmup_android.sh \
|
| 63 |
+
&& /tmp/docker_warmup_android.sh \
|
| 64 |
+
&& rm -f /tmp/docker_warmup_android.sh \
|
| 65 |
+
&& rm -rf /tmp/sf-android-warm /tmp/npm-cache \
|
| 66 |
+
&& npm cache clean --force 2>/dev/null || true
|
| 67 |
+
|
| 68 |
EXPOSE 7860
|
| 69 |
|
| 70 |
CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -29,7 +29,7 @@ Paste a Hugging Face Space URL → analyze runtime → choose packaging targets
|
|
| 29 |
- Firefox Extension (.xpi) — Hybrid
|
| 30 |
- Chromium Extension MV3 (zip) — Hybrid
|
| 31 |
- Tauri project generator (zip) — Local **project** (no binary claimed on HF)
|
| 32 |
-
- **Android Capacitor**
|
| 33 |
|
| 34 |
Stubs (clear message): Linux AppImage, Windows portable — binaries not buildable inside HF CPU.
|
| 35 |
|
|
|
|
| 29 |
- Firefox Extension (.xpi) — Hybrid
|
| 30 |
- Chromium Extension MV3 (zip) — Hybrid
|
| 31 |
- Tauri project generator (zip) — Local **project** (no binary claimed on HF)
|
| 32 |
+
- **Android Capacitor** — **Hosted Wrapper** **debug APK** when SDK build succeeds (unsigned); project zip **fallback** if APK build fails
|
| 33 |
|
| 34 |
Stubs (clear message): Linux AppImage, Windows portable — binaries not buildable inside HF CPU.
|
| 35 |
|
README_HF.md
CHANGED
|
@@ -29,7 +29,7 @@ Paste a Hugging Face Space URL → analyze runtime → choose packaging targets
|
|
| 29 |
- Firefox Extension (.xpi) — Hybrid
|
| 30 |
- Chromium Extension MV3 (zip) — Hybrid
|
| 31 |
- Tauri project generator (zip) — Local **project** (no binary claimed on HF)
|
| 32 |
-
- **Android Capacitor**
|
| 33 |
|
| 34 |
Stubs (clear message): Linux AppImage, Windows portable — binaries not buildable inside HF CPU.
|
| 35 |
|
|
|
|
| 29 |
- Firefox Extension (.xpi) — Hybrid
|
| 30 |
- Chromium Extension MV3 (zip) — Hybrid
|
| 31 |
- Tauri project generator (zip) — Local **project** (no binary claimed on HF)
|
| 32 |
+
- **Android Capacitor** — **Hosted Wrapper** **debug APK** when SDK build succeeds (unsigned); project zip **fallback** if APK build fails
|
| 33 |
|
| 34 |
Stubs (clear message): Linux AppImage, Windows portable — binaries not buildable inside HF CPU.
|
| 35 |
|
RESULT.md
CHANGED
|
@@ -7,55 +7,43 @@
|
|
| 7 |
| **App domain** | https://2btainment-spaceforge.hf.space |
|
| 8 |
| **Visibility** | **private** (owner: 2Btainment / Pro) |
|
| 9 |
| **SDK / HW** | Docker · `cpu-basic` |
|
| 10 |
-
| **
|
| 11 |
-
| **Runtime** |
|
| 12 |
|
| 13 |
Auth note: private Space — call API/UI with a logged-in HF session or `Authorization: Bearer …` (never log tokens; docs use `[ERSATZ_KEY]`).
|
| 14 |
|
| 15 |
## What works (MVP)
|
| 16 |
-
Live E2E against `gradio/hello_world` (prior) + Android converter:
|
| 17 |
|
| 18 |
| Target | Mode | Artifact | Status |
|
| 19 |
|--------|------|----------|--------|
|
| 20 |
-
| HTML Widget | **Hybrid** | `.zip` | ✅
|
| 21 |
-
| PWA | **Hybrid** | `.zip` | ✅
|
| 22 |
-
| Firefox Extension | **Hybrid** | `.xpi`
|
| 23 |
-
| Chromium Extension MV3 | **Hybrid** | `.zip` | ✅
|
| 24 |
-
| Tauri | **Local** (project) | `*-tauri-project.zip` | ✅ project
|
| 25 |
-
| **Android (Capacitor)** | **Hosted Wrapper** |
|
| 26 |
-
| Linux AppImage | Local stub | — | ✅
|
| 27 |
-
| Windows Portable | Local stub | — | ✅
|
| 28 |
-
|
| 29 |
-
Also:
|
| 30 |
-
- `POST /api/analyze` — Android selectable with compat chips: ✓ project / ⚠ APK not built in HF / ✗ GPU local impossible
|
| 31 |
-
- Modes never mislabel Hosted Wrapper as Local APK
|
| 32 |
-
- Zip-slip protection, path checks, download size limit, TTL build dirs
|
| 33 |
-
- Frontend (EN UI, i18n-ready) served by FastAPI static
|
| 34 |
-
- **29/29** pytest passed locally
|
| 35 |
-
|
| 36 |
-
## Android install (user)
|
| 37 |
-
1. Download Capacitor project zip from SpaceForge.
|
| 38 |
-
2. `npm install && npx cap sync android`
|
| 39 |
-
3. Open `android/` in **Android Studio** (or `./scripts/build-android.sh` with SDK + JDK 17).
|
| 40 |
-
4. Install the **locally built** debug APK.
|
| 41 |
-
|
| 42 |
-
See `ANDROID.md`.
|
| 43 |
|
| 44 |
-
##
|
| 45 |
-
|
| 46 |
-
-
|
| 47 |
-
-
|
| 48 |
-
-
|
| 49 |
-
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
- No privileged Docker / no untrusted code exec in main process.
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
-
invalid URL, missing space, public gradio, static SDK, external APIs flag, GPU warning, unknown SDK, firefox/widget/pwa/tauri/**android** generators, path traversal / zip-slip, large download → 413, stub messages, Android compat badges, API health/build/download/delete.
|
| 59 |
|
| 60 |
-
##
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
| **App domain** | https://2btainment-spaceforge.hf.space |
|
| 8 |
| **Visibility** | **private** (owner: 2Btainment / Pro) |
|
| 9 |
| **SDK / HW** | Docker · `cpu-basic` |
|
| 10 |
+
| **Android in image** | OpenJDK 17 + cmdline-tools + platform 34 + build-tools 34.0.0 |
|
| 11 |
+
| **Runtime** | Verify after push: `/api/health` → `android_sdk.ready: true` |
|
| 12 |
|
| 13 |
Auth note: private Space — call API/UI with a logged-in HF session or `Authorization: Bearer …` (never log tokens; docs use `[ERSATZ_KEY]`).
|
| 14 |
|
| 15 |
## What works (MVP)
|
|
|
|
| 16 |
|
| 17 |
| Target | Mode | Artifact | Status |
|
| 18 |
|--------|------|----------|--------|
|
| 19 |
+
| HTML Widget | **Hybrid** | `.zip` | ✅ |
|
| 20 |
+
| PWA | **Hybrid** | `.zip` | ✅ |
|
| 21 |
+
| Firefox Extension | **Hybrid** | `.xpi` | ✅ |
|
| 22 |
+
| Chromium Extension MV3 | **Hybrid** | `.zip` | ✅ |
|
| 23 |
+
| Tauri | **Local** (project) | `*-tauri-project.zip` | ✅ project only |
|
| 24 |
+
| **Android (Capacitor)** | **Hosted Wrapper** | **`.apk` debug** (preferred) or project zip fallback | ✅ APK when SDK build succeeds |
|
| 25 |
+
| Linux AppImage | Local stub | — | ✅ stub |
|
| 26 |
+
| Windows Portable | Local stub | — | ✅ stub |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
## Android download semantics
|
| 29 |
+
|
| 30 |
+
- `GET /api/build/{id}/download?target=android` returns:
|
| 31 |
+
- **`*-android-debug.apk`** when `gradle assembleDebug` succeeds (`binary_included: true`, `apk_included: true`)
|
| 32 |
+
- **`*-android-capacitor-project.zip`** only as **FALLBACK** (notes say FALLBACK; `binary_included: false`)
|
| 33 |
+
- APK is **unsigned debug**, Hosted Wrapper WebView → live Space URL — **not** a Local offline model/GPU package.
|
| 34 |
+
|
| 35 |
+
## Sideload
|
|
|
|
| 36 |
|
| 37 |
+
```bash
|
| 38 |
+
adb install -r hello_world-android-debug.apk
|
| 39 |
+
```
|
| 40 |
|
| 41 |
+
Or copy to device and open with a file manager (enable install unknown apps).
|
|
|
|
| 42 |
|
| 43 |
+
## Known limits
|
| 44 |
+
|
| 45 |
+
- First APK build in a cold container can take several minutes (Gradle deps); image warmup reduces this.
|
| 46 |
+
- Debug APK is not Play-signed.
|
| 47 |
+
- Hybrid/PWA/extensions/Android need network to the live Space.
|
| 48 |
+
- Private Space: visitors need access; subdomain returns Hub 404 HTML without auth.
|
| 49 |
+
- Build artifacts TTL ~1h.
|
SPEC.md
CHANGED
|
@@ -15,7 +15,7 @@ build downloadable artifacts. Clear distinction: **Local** / **Hybrid** / **Host
|
|
| 15 |
|------|---------|---------|
|
| 16 |
| **Local** | Runs offline / as installed app (or generated project you build locally) | Tauri project zip, AppImage/Windows stubs (project-only in HF) |
|
| 17 |
| **Hybrid** | Local shell + embedded remote Space (iframe / API proxy) | PWA, browser extensions, HTML widget |
|
| 18 |
-
| **Hosted Wrapper** | Thin client that always needs the live Space URL | **Android Capacitor** project zip
|
| 19 |
|
| 20 |
Extensions / PWA / HTML widget are **Hybrid** (or Hosted Wrapper if they only iframe).
|
| 21 |
Tauri generator is **Local project** — we ship source + scripts, **not** a claimed binary unless built.
|
|
@@ -31,7 +31,7 @@ Tauri generator is **Local project** — we ship source + scripts, **not** a cla
|
|
| 31 |
## Converters (`Converter` interface)
|
| 32 |
`html_widget`, `pwa`, `firefox_ext`, `chromium_ext`, `tauri`, **`android` (Capacitor project)** — full MVP.
|
| 33 |
Stubs: `linux_appimage`, `windows_portable` → clear "project-only / not in HF env".
|
| 34 |
-
Android
|
| 35 |
|
| 36 |
## Security
|
| 37 |
- Builds under `/tmp/spaceforge/{id}` or `/data/builds/{id}` with TTL cleanup
|
|
|
|
| 15 |
|------|---------|---------|
|
| 16 |
| **Local** | Runs offline / as installed app (or generated project you build locally) | Tauri project zip, AppImage/Windows stubs (project-only in HF) |
|
| 17 |
| **Hybrid** | Local shell + embedded remote Space (iframe / API proxy) | PWA, browser extensions, HTML widget |
|
| 18 |
+
| **Hosted Wrapper** | Thin client that always needs the live Space URL | **Android Capacitor** debug APK (or project zip fallback) |
|
| 19 |
|
| 20 |
Extensions / PWA / HTML widget are **Hybrid** (or Hosted Wrapper if they only iframe).
|
| 21 |
Tauri generator is **Local project** — we ship source + scripts, **not** a claimed binary unless built.
|
|
|
|
| 31 |
## Converters (`Converter` interface)
|
| 32 |
`html_widget`, `pwa`, `firefox_ext`, `chromium_ext`, `tauri`, **`android` (Capacitor project)** — full MVP.
|
| 33 |
Stubs: `linux_appimage`, `windows_portable` → clear "project-only / not in HF env".
|
| 34 |
+
Android prefers a **debug .apk** when SDK is in the Docker image; falls back to project zip. Never claims Local offline model APK.
|
| 35 |
|
| 36 |
## Security
|
| 37 |
- Builds under `/tmp/spaceforge/{id}` or `/data/builds/{id}` with TTL cleanup
|
backend/app/api/routes.py
CHANGED
|
@@ -40,8 +40,10 @@ class BuildRequest(BaseModel):
|
|
| 40 |
|
| 41 |
|
| 42 |
@router.get("/health")
|
| 43 |
-
async def health() -> dict[str,
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
@router.get("/targets")
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
@router.get("/health")
|
| 43 |
+
async def health() -> dict[str, object]:
|
| 44 |
+
from backend.app.converters.mobile.android_sdk import sdk_status
|
| 45 |
+
|
| 46 |
+
return {"status": "ok", "service": "spaceforge", "android_sdk": sdk_status()}
|
| 47 |
|
| 48 |
|
| 49 |
@router.get("/targets")
|
backend/app/config.py
CHANGED
|
@@ -9,9 +9,10 @@ BUILDS_ROOT = (_DATA / "builds") if _DATA.exists() and os.access(_DATA, os.W_OK)
|
|
| 9 |
BUILDS_ROOT.mkdir(parents=True, exist_ok=True)
|
| 10 |
|
| 11 |
BUILD_TTL_SECONDS = int(os.environ.get("SPACEFORGE_TTL", "3600"))
|
| 12 |
-
MAX_DOWNLOAD_BYTES = int(os.environ.get("SPACEFORGE_MAX_DOWNLOAD", str(
|
| 13 |
ANALYZE_TIMEOUT = float(os.environ.get("SPACEFORGE_ANALYZE_TIMEOUT", "30"))
|
| 14 |
BUILD_TIMEOUT = float(os.environ.get("SPACEFORGE_BUILD_TIMEOUT", "120"))
|
|
|
|
| 15 |
MAX_CONCURRENT_BUILDS = int(os.environ.get("SPACEFORGE_MAX_BUILDS", "4"))
|
| 16 |
|
| 17 |
STATIC_DIR = Path(os.environ.get("SPACEFORGE_STATIC", "/app/frontend/dist"))
|
|
|
|
| 9 |
BUILDS_ROOT.mkdir(parents=True, exist_ok=True)
|
| 10 |
|
| 11 |
BUILD_TTL_SECONDS = int(os.environ.get("SPACEFORGE_TTL", "3600"))
|
| 12 |
+
MAX_DOWNLOAD_BYTES = int(os.environ.get("SPACEFORGE_MAX_DOWNLOAD", str(100 * 1024 * 1024)))
|
| 13 |
ANALYZE_TIMEOUT = float(os.environ.get("SPACEFORGE_ANALYZE_TIMEOUT", "30"))
|
| 14 |
BUILD_TIMEOUT = float(os.environ.get("SPACEFORGE_BUILD_TIMEOUT", "120"))
|
| 15 |
+
ANDROID_BUILD_TIMEOUT = float(os.environ.get("SPACEFORGE_ANDROID_BUILD_TIMEOUT", "900"))
|
| 16 |
MAX_CONCURRENT_BUILDS = int(os.environ.get("SPACEFORGE_MAX_BUILDS", "4"))
|
| 17 |
|
| 18 |
STATIC_DIR = Path(os.environ.get("SPACEFORGE_STATIC", "/app/frontend/dist"))
|
backend/app/converters/base.py
CHANGED
|
@@ -27,6 +27,7 @@ class Artifact:
|
|
| 27 |
mode: str # local | hybrid | hosted_wrapper
|
| 28 |
media_type: str = "application/zip"
|
| 29 |
notes: str = ""
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
@dataclass
|
|
|
|
| 27 |
mode: str # local | hybrid | hosted_wrapper
|
| 28 |
media_type: str = "application/zip"
|
| 29 |
notes: str = ""
|
| 30 |
+
binary_included: bool = False
|
| 31 |
|
| 32 |
|
| 33 |
@dataclass
|
backend/app/converters/mobile/android.py
CHANGED
|
@@ -1,17 +1,25 @@
|
|
| 1 |
-
"""Android Capacitor converter — Hosted Wrapper
|
| 2 |
|
| 3 |
-
Generates a
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
"""
|
| 7 |
from __future__ import annotations
|
| 8 |
|
|
|
|
| 9 |
import json
|
|
|
|
| 10 |
import re
|
|
|
|
|
|
|
|
|
|
| 11 |
import zipfile
|
| 12 |
from pathlib import Path
|
| 13 |
|
| 14 |
from backend.app.converters.base import Artifact, BuildContext, Converter, ConverterResult
|
|
|
|
| 15 |
from backend.app.security.zipsafe import safe_add_tree
|
| 16 |
|
| 17 |
|
|
@@ -107,7 +115,6 @@ class AndroidConverter(Converter):
|
|
| 107 |
res / "layout",
|
| 108 |
res / "values",
|
| 109 |
res / "xml",
|
| 110 |
-
res / "mipmap-hdpi",
|
| 111 |
res / "drawable",
|
| 112 |
android_root / "gradle" / "wrapper",
|
| 113 |
):
|
|
@@ -556,7 +563,7 @@ public class MainActivity extends BridgeActivity {{}}
|
|
| 556 |
<item name="windowNoTitle">true</item>
|
| 557 |
<item name="android:background">@null</item>
|
| 558 |
</style>
|
| 559 |
-
<style name="AppTheme.NoActionBarLaunch" parent="Theme.
|
| 560 |
<item name="android:background">@drawable/splash</item>
|
| 561 |
</style>
|
| 562 |
</resources>
|
|
@@ -596,15 +603,7 @@ public class MainActivity extends BridgeActivity {{}}
|
|
| 596 |
""",
|
| 597 |
encoding="utf-8",
|
| 598 |
)
|
| 599 |
-
|
| 600 |
-
"""<?xml version="1.0" encoding="utf-8"?>
|
| 601 |
-
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
| 602 |
-
<background android:drawable="@color/ic_launcher_background"/>
|
| 603 |
-
<foreground android:drawable="@drawable/splash"/>
|
| 604 |
-
</adaptive-icon>
|
| 605 |
-
""",
|
| 606 |
-
encoding="utf-8",
|
| 607 |
-
)
|
| 608 |
# ic_launcher as drawable reference — also provide color + use @drawable for icon fallback
|
| 609 |
(res / "values" / "ic_launcher_background.xml").write_text(
|
| 610 |
"""<?xml version="1.0" encoding="utf-8"?>
|
|
@@ -814,52 +813,18 @@ the script guides you to Android Studio or system Gradle.
|
|
| 814 |
encoding="utf-8",
|
| 815 |
)
|
| 816 |
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
"compat": {
|
| 832 |
-
"project": "ok",
|
| 833 |
-
"apk": "warn",
|
| 834 |
-
"gpu_local": "no" if needs_gpu else "warn",
|
| 835 |
-
},
|
| 836 |
-
"labeling": {
|
| 837 |
-
"never_claim": "Local APK",
|
| 838 |
-
"shipped_as": "Hosted Wrapper project zip",
|
| 839 |
-
},
|
| 840 |
-
}
|
| 841 |
-
(out_dir / "spaceforge.json").write_text(
|
| 842 |
-
json.dumps(meta, indent=2) + "\n", encoding="utf-8"
|
| 843 |
-
)
|
| 844 |
-
|
| 845 |
-
zip_path = ctx.work_dir / f"{name}-android-capacitor-project.zip"
|
| 846 |
-
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
| 847 |
-
safe_add_tree(zf, out_dir.parent)
|
| 848 |
-
ctx.info(
|
| 849 |
-
f"Wrote {zip_path.name} (Capacitor Android project only — "
|
| 850 |
-
"APK not included; mode=hosted_wrapper)"
|
| 851 |
-
)
|
| 852 |
-
return ConverterResult(
|
| 853 |
-
ok=True,
|
| 854 |
-
project_only=True,
|
| 855 |
-
artifact=Artifact(
|
| 856 |
-
target_id=self.id,
|
| 857 |
-
path=zip_path,
|
| 858 |
-
filename=zip_path.name,
|
| 859 |
-
mode=self.mode,
|
| 860 |
-
notes=(
|
| 861 |
-
"Capacitor Android project zip (Hosted Wrapper). "
|
| 862 |
-
"APK not built on HF — use Android Studio or ./scripts/build-android.sh."
|
| 863 |
-
),
|
| 864 |
-
),
|
| 865 |
)
|
|
|
|
| 1 |
+
"""Android Capacitor converter — Hosted Wrapper with optional debug APK.
|
| 2 |
|
| 3 |
+
Generates a Capacitor Android WebView wrapper for the live Hugging Face Space URL.
|
| 4 |
+
When ANDROID_HOME + JDK are present (baked into the SpaceForge Docker image),
|
| 5 |
+
runs gradle assembleDebug and returns the .apk as the download artifact.
|
| 6 |
+
If the APK build fails, falls back to a Capacitor project zip (clearly labeled).
|
| 7 |
+
The APK is an unsigned debug Hosted Wrapper — never a Local offline model runtime.
|
| 8 |
"""
|
| 9 |
from __future__ import annotations
|
| 10 |
|
| 11 |
+
import asyncio
|
| 12 |
import json
|
| 13 |
+
import os
|
| 14 |
import re
|
| 15 |
+
import shutil
|
| 16 |
+
import subprocess
|
| 17 |
+
import urllib.request
|
| 18 |
import zipfile
|
| 19 |
from pathlib import Path
|
| 20 |
|
| 21 |
from backend.app.converters.base import Artifact, BuildContext, Converter, ConverterResult
|
| 22 |
+
from backend.app.converters.mobile.android_sdk import android_sdk_ready, android_sdk_root
|
| 23 |
from backend.app.security.zipsafe import safe_add_tree
|
| 24 |
|
| 25 |
|
|
|
|
| 115 |
res / "layout",
|
| 116 |
res / "values",
|
| 117 |
res / "xml",
|
|
|
|
| 118 |
res / "drawable",
|
| 119 |
android_root / "gradle" / "wrapper",
|
| 120 |
):
|
|
|
|
| 563 |
<item name="windowNoTitle">true</item>
|
| 564 |
<item name="android:background">@null</item>
|
| 565 |
</style>
|
| 566 |
+
<style name="AppTheme.NoActionBarLaunch" parent="Theme.AppCompat.DayNight.NoActionBar">
|
| 567 |
<item name="android:background">@drawable/splash</item>
|
| 568 |
</style>
|
| 569 |
</resources>
|
|
|
|
| 603 |
""",
|
| 604 |
encoding="utf-8",
|
| 605 |
)
|
| 606 |
+
# Skip density mipmap adaptive-icon XML (needs mipmap-anydpi-v26)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 607 |
# ic_launcher as drawable reference — also provide color + use @drawable for icon fallback
|
| 608 |
(res / "values" / "ic_launcher_background.xml").write_text(
|
| 609 |
"""<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
| 813 |
encoding="utf-8",
|
| 814 |
)
|
| 815 |
|
| 816 |
+
from backend.app.converters.mobile.finalize import finalize_android
|
| 817 |
+
|
| 818 |
+
return await finalize_android(
|
| 819 |
+
ctx=ctx,
|
| 820 |
+
out_dir=out_dir,
|
| 821 |
+
name=name,
|
| 822 |
+
app_id=app_id,
|
| 823 |
+
info=info,
|
| 824 |
+
embed=embed,
|
| 825 |
+
space_url=space_url,
|
| 826 |
+
hybrid_notes=hybrid_notes,
|
| 827 |
+
needs_gpu=needs_gpu,
|
| 828 |
+
target_id=self.id,
|
| 829 |
+
mode=self.mode,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 830 |
)
|
backend/app/converters/mobile/android_sdk.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Detect Android SDK / JDK availability for SpaceForge APK builds."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
import shutil
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def android_sdk_root() -> Path | None:
|
| 10 |
+
for key in ("ANDROID_HOME", "ANDROID_SDK_ROOT"):
|
| 11 |
+
raw = os.environ.get(key, "").strip()
|
| 12 |
+
if raw:
|
| 13 |
+
p = Path(raw)
|
| 14 |
+
if p.is_dir():
|
| 15 |
+
return p
|
| 16 |
+
return None
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def android_sdk_ready() -> bool:
|
| 20 |
+
"""True when we can realistically run assembleDebug."""
|
| 21 |
+
if os.environ.get("SPACEFORGE_ANDROID_SDK", "").strip() in {"0", "false", "no"}:
|
| 22 |
+
return False
|
| 23 |
+
root = android_sdk_root()
|
| 24 |
+
if not root:
|
| 25 |
+
return False
|
| 26 |
+
# platform + build-tools present
|
| 27 |
+
platforms = root / "platforms"
|
| 28 |
+
build_tools = root / "build-tools"
|
| 29 |
+
if not platforms.is_dir() or not any(platforms.iterdir()):
|
| 30 |
+
return False
|
| 31 |
+
if not build_tools.is_dir() or not any(build_tools.iterdir()):
|
| 32 |
+
return False
|
| 33 |
+
if not shutil.which("java"):
|
| 34 |
+
return False
|
| 35 |
+
if not shutil.which("npm") and not shutil.which("node"):
|
| 36 |
+
return False
|
| 37 |
+
return True
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def sdk_status() -> dict:
|
| 41 |
+
root = android_sdk_root()
|
| 42 |
+
return {
|
| 43 |
+
"ready": android_sdk_ready(),
|
| 44 |
+
"android_home": str(root) if root else None,
|
| 45 |
+
"java": bool(shutil.which("java")),
|
| 46 |
+
"npm": bool(shutil.which("npm")),
|
| 47 |
+
"forced_off": os.environ.get("SPACEFORGE_ANDROID_SDK", "").strip() in {"0", "false", "no"},
|
| 48 |
+
}
|
backend/app/converters/mobile/finalize.py
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Finalize Capacitor mobile packaging artifact."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import asyncio
|
| 5 |
+
import json
|
| 6 |
+
import os
|
| 7 |
+
import shutil
|
| 8 |
+
import subprocess
|
| 9 |
+
import urllib.request
|
| 10 |
+
import zipfile
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import Any, Optional
|
| 13 |
+
|
| 14 |
+
from backend.app.converters.base import Artifact, BuildContext, ConverterResult
|
| 15 |
+
from backend.app.converters.mobile.android_sdk import android_sdk_ready, android_sdk_root
|
| 16 |
+
from backend.app.security.zipsafe import safe_add_tree
|
| 17 |
+
|
| 18 |
+
TARGET_ID = "android"
|
| 19 |
+
MODE = "hosted_wrapper"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
import base64 as _b64
|
| 23 |
+
GRADLEW_SCRIPT = _b64.b64decode("IyEvYmluL3NoCnNldCAtZQpBUFBfSE9NRT0kKGNkICIkKGRpcm5hbWUgIiQwIikiICYmIHB3ZCkKQ0xBU1NQQVRIPSRBUFBfSE9NRS9ncmFkbGUvd3JhcHBlci9ncmFkbGUtd3JhcHBlci5qYXIKaWYgWyAtbiAiJEpBVkFfSE9NRSIgXSAmJiBbIC14ICIkSkFWQV9IT01FL2Jpbi9qYXZhIiBdOyB0aGVuCiAgSkFWQUNNRD0kSkFWQV9IT01FL2Jpbi9qYXZhCmVsc2UKICBKQVZBQ01EPWphdmEKZmkKZXhlYyAiJEpBVkFDTUQiIC1jbGFzc3BhdGggIiRDTEFTU1BBVEgiIG9yZy5ncmFkbGUud3JhcHBlci5HcmFkbGVXcmFwcGVyTWFpbiAiJEAiCg==").decode()
|
| 24 |
+
|
| 25 |
+
def ensure_gradle_wrapper(android_root: Path, log) -> None:
|
| 26 |
+
wrapper_dir = android_root / "gradle" / "wrapper"
|
| 27 |
+
wrapper_dir.mkdir(parents=True, exist_ok=True)
|
| 28 |
+
jar = wrapper_dir / "gradle-wrapper.jar"
|
| 29 |
+
props = wrapper_dir / "gradle-wrapper.properties"
|
| 30 |
+
if not props.exists():
|
| 31 |
+
props.write_text(
|
| 32 |
+
"distributionBase=GRADLE_USER_HOME\n"
|
| 33 |
+
"distributionPath=wrapper/dists\n"
|
| 34 |
+
"distributionUrl=https\\://services.gradle.org/distributions/gradle-8.2.1-all.zip\n"
|
| 35 |
+
"networkTimeout=10000\n"
|
| 36 |
+
"validateDistributionUrl=true\n"
|
| 37 |
+
"zipStoreBase=GRADLE_USER_HOME\n"
|
| 38 |
+
"zipStorePath=wrapper/dists\n",
|
| 39 |
+
encoding="utf-8",
|
| 40 |
+
)
|
| 41 |
+
if (not jar.exists()) or jar.stat().st_size < 10000:
|
| 42 |
+
urls = [
|
| 43 |
+
"https://github.com/gradle/gradle/raw/v8.2.1/gradle/wrapper/gradle-wrapper.jar",
|
| 44 |
+
"https://raw.githubusercontent.com/gradle/gradle/v8.2.1/gradle/wrapper/gradle-wrapper.jar",
|
| 45 |
+
]
|
| 46 |
+
last_err = None
|
| 47 |
+
for url in urls:
|
| 48 |
+
try:
|
| 49 |
+
log("Downloading gradle-wrapper.jar")
|
| 50 |
+
with urllib.request.urlopen(url, timeout=60) as resp:
|
| 51 |
+
data = resp.read()
|
| 52 |
+
if len(data) < 10000:
|
| 53 |
+
raise RuntimeError("wrapper jar too small (%s)" % len(data))
|
| 54 |
+
jar.write_bytes(data)
|
| 55 |
+
last_err = None
|
| 56 |
+
break
|
| 57 |
+
except Exception as e:
|
| 58 |
+
last_err = e
|
| 59 |
+
if last_err and ((not jar.exists()) or jar.stat().st_size < 10000):
|
| 60 |
+
raise RuntimeError("could not fetch gradle-wrapper.jar: %s" % last_err)
|
| 61 |
+
gradlew = android_root / "gradlew"
|
| 62 |
+
stub = gradlew.read_text(encoding="utf-8") if gradlew.exists() else ""
|
| 63 |
+
if "GradleWrapperMain" not in stub:
|
| 64 |
+
gradlew.write_text(GRADLEW_SCRIPT, encoding="utf-8")
|
| 65 |
+
gradlew.chmod(gradlew.stat().st_mode | 0o111)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def assemble_debug_apk(out_dir: Path, log) -> Optional[Path]:
|
| 69 |
+
sdk = android_sdk_root()
|
| 70 |
+
if not sdk:
|
| 71 |
+
log("assemble: no SDK root")
|
| 72 |
+
return None
|
| 73 |
+
android_root = out_dir / "android"
|
| 74 |
+
try:
|
| 75 |
+
(android_root / "local.properties").write_text(
|
| 76 |
+
"sdk.dir=%s\n" % str(sdk).replace(chr(92), "/"), encoding="utf-8"
|
| 77 |
+
)
|
| 78 |
+
ensure_gradle_wrapper(android_root, log)
|
| 79 |
+
for bad in android_root.glob("app/src/main/res/mipmap-*/ic_launcher.xml"):
|
| 80 |
+
try:
|
| 81 |
+
bad.unlink()
|
| 82 |
+
except OSError:
|
| 83 |
+
pass
|
| 84 |
+
styles = android_root / "app/src/main/res/values/styles.xml"
|
| 85 |
+
if styles.exists():
|
| 86 |
+
st = styles.read_text(encoding="utf-8")
|
| 87 |
+
if "Theme.SplashScreen" in st:
|
| 88 |
+
styles.write_text(
|
| 89 |
+
st.replace("Theme.SplashScreen", "Theme.AppCompat.DayNight.NoActionBar"),
|
| 90 |
+
encoding="utf-8",
|
| 91 |
+
)
|
| 92 |
+
env = os.environ.copy()
|
| 93 |
+
env["ANDROID_HOME"] = str(sdk)
|
| 94 |
+
env["ANDROID_SDK_ROOT"] = str(sdk)
|
| 95 |
+
env.setdefault("JAVA_HOME", os.environ.get("JAVA_HOME", ""))
|
| 96 |
+
|
| 97 |
+
def run(cmd, cwd, timeout):
|
| 98 |
+
log("$ %s (cwd=%s)" % (" ".join(cmd), cwd.name))
|
| 99 |
+
proc = subprocess.run(
|
| 100 |
+
cmd, cwd=str(cwd), env=env, capture_output=True, text=True, timeout=timeout
|
| 101 |
+
)
|
| 102 |
+
if proc.stdout:
|
| 103 |
+
for line in proc.stdout.splitlines()[-40:]:
|
| 104 |
+
log(line)
|
| 105 |
+
if proc.returncode != 0:
|
| 106 |
+
if proc.stderr:
|
| 107 |
+
for line in proc.stderr.splitlines()[-40:]:
|
| 108 |
+
log(line)
|
| 109 |
+
raise RuntimeError("command failed (%s): %s" % (proc.returncode, " ".join(cmd)))
|
| 110 |
+
|
| 111 |
+
run(["npm", "install", "--no-audit", "--no-fund"], out_dir, 300)
|
| 112 |
+
run(["npx", "--yes", "cap", "sync", "android"], out_dir, 300)
|
| 113 |
+
gradlew = android_root / "gradlew"
|
| 114 |
+
if not gradlew.exists():
|
| 115 |
+
log("gradlew missing after sync")
|
| 116 |
+
return None
|
| 117 |
+
gradlew.chmod(gradlew.stat().st_mode | 0o111)
|
| 118 |
+
run(["./gradlew", "assembleDebug", "--no-daemon", "--stacktrace"], android_root, 600)
|
| 119 |
+
out = android_root / "app" / "build" / "outputs" / "apk" / "debug"
|
| 120 |
+
apks = sorted(out.glob("*.apk")) if out.is_dir() else []
|
| 121 |
+
if not apks:
|
| 122 |
+
log("assembleDebug finished but no .apk under outputs/apk/debug")
|
| 123 |
+
return None
|
| 124 |
+
return apks[0]
|
| 125 |
+
except subprocess.TimeoutExpired as e:
|
| 126 |
+
log("assemble timeout: %s" % e)
|
| 127 |
+
return None
|
| 128 |
+
except Exception as e:
|
| 129 |
+
log("assemble error: %s: %s" % (type(e).__name__, e))
|
| 130 |
+
return None
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
async def finalize_android(
|
| 134 |
+
*,
|
| 135 |
+
ctx: BuildContext,
|
| 136 |
+
out_dir: Path,
|
| 137 |
+
name: str,
|
| 138 |
+
app_id: str,
|
| 139 |
+
info: dict[str, Any],
|
| 140 |
+
embed: str,
|
| 141 |
+
space_url: str,
|
| 142 |
+
hybrid_notes: list[str],
|
| 143 |
+
needs_gpu: bool,
|
| 144 |
+
target_id: str = TARGET_ID,
|
| 145 |
+
mode: str = MODE,
|
| 146 |
+
) -> ConverterResult:
|
| 147 |
+
apk_ready = android_sdk_ready()
|
| 148 |
+
meta = {
|
| 149 |
+
"product": "SpaceForge",
|
| 150 |
+
"target": target_id,
|
| 151 |
+
"mode": mode,
|
| 152 |
+
"artifact_kind": "apk" if apk_ready else "project-zip",
|
| 153 |
+
"binary_included": False,
|
| 154 |
+
"apk_included": False,
|
| 155 |
+
"framework": "capacitor",
|
| 156 |
+
"capacitor_major": 6,
|
| 157 |
+
"app_id": app_id,
|
| 158 |
+
"space": info["repo_id"],
|
| 159 |
+
"embed_url": embed,
|
| 160 |
+
"space_url": space_url,
|
| 161 |
+
"hybrid_notes": hybrid_notes,
|
| 162 |
+
"compat": {
|
| 163 |
+
"project": "ok",
|
| 164 |
+
"apk": "ok" if apk_ready else "warn",
|
| 165 |
+
"gpu_local": "no" if needs_gpu else "warn",
|
| 166 |
+
},
|
| 167 |
+
"labeling": {
|
| 168 |
+
"never_claim": "Local APK",
|
| 169 |
+
"shipped_as": "debug package (Hosted Wrapper)" if apk_ready else "Hosted Wrapper project zip",
|
| 170 |
+
},
|
| 171 |
+
}
|
| 172 |
+
(out_dir / "spaceforge.json").write_text(json.dumps(meta, indent=2) + "\n", encoding="utf-8")
|
| 173 |
+
|
| 174 |
+
if apk_ready:
|
| 175 |
+
ctx.info("Android SDK detected — running gradle assembleDebug (Hosted Wrapper debug; unsigned)")
|
| 176 |
+
apk_file = await asyncio.to_thread(assemble_debug_apk, out_dir, ctx.info)
|
| 177 |
+
if apk_file and apk_file.is_file() and apk_file.stat().st_size > 0:
|
| 178 |
+
dest = ctx.work_dir / ("%s-android-debug.apk" % name)
|
| 179 |
+
shutil.copy2(apk_file, dest)
|
| 180 |
+
meta["binary_included"] = True
|
| 181 |
+
meta["apk_included"] = True
|
| 182 |
+
meta["artifact_kind"] = "apk"
|
| 183 |
+
meta["labeling"]["shipped_as"] = "debug APK (Hosted Wrapper WebView)"
|
| 184 |
+
meta["apk_path"] = dest.name
|
| 185 |
+
meta["apk_size"] = dest.stat().st_size
|
| 186 |
+
(out_dir / "spaceforge.json").write_text(json.dumps(meta, indent=2) + "\n", encoding="utf-8")
|
| 187 |
+
ctx.info("OK: debug APK ready %s (%s bytes) package=%s" % (dest.name, dest.stat().st_size, app_id))
|
| 188 |
+
return ConverterResult(
|
| 189 |
+
ok=True,
|
| 190 |
+
project_only=False,
|
| 191 |
+
artifact=Artifact(
|
| 192 |
+
target_id=target_id,
|
| 193 |
+
path=dest,
|
| 194 |
+
filename=dest.name,
|
| 195 |
+
mode=mode,
|
| 196 |
+
media_type="application/vnd.android.package-archive",
|
| 197 |
+
notes=(
|
| 198 |
+
"Debug APK (unsigned) — Capacitor Hosted Wrapper WebView loads the live Space. "
|
| 199 |
+
"Not a Local offline package of the model/GPU runtime."
|
| 200 |
+
),
|
| 201 |
+
binary_included=True,
|
| 202 |
+
),
|
| 203 |
+
)
|
| 204 |
+
ctx.info("APK build failed or produced no file — falling back to Capacitor project zip")
|
| 205 |
+
else:
|
| 206 |
+
ctx.info("Android SDK not available in this environment — shipping project zip only")
|
| 207 |
+
|
| 208 |
+
zip_path = ctx.work_dir / ("%s-android-capacitor-project.zip" % name)
|
| 209 |
+
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
| 210 |
+
safe_add_tree(zf, out_dir.parent)
|
| 211 |
+
ctx.info("Wrote %s (project-zip FALLBACK — APK not included)" % zip_path.name)
|
| 212 |
+
return ConverterResult(
|
| 213 |
+
ok=True,
|
| 214 |
+
project_only=True,
|
| 215 |
+
artifact=Artifact(
|
| 216 |
+
target_id=target_id,
|
| 217 |
+
path=zip_path,
|
| 218 |
+
filename=zip_path.name,
|
| 219 |
+
mode=mode,
|
| 220 |
+
notes=(
|
| 221 |
+
"FALLBACK: Capacitor Android project zip (APK build unavailable or failed). "
|
| 222 |
+
"Use Android Studio or ./scripts/build-android.sh — or redeploy SpaceForge "
|
| 223 |
+
"with Android SDK in the Docker image."
|
| 224 |
+
),
|
| 225 |
+
binary_included=False,
|
| 226 |
+
),
|
| 227 |
+
)
|
backend/app/providers/huggingface.py
CHANGED
|
@@ -148,6 +148,9 @@ async def fetch_space_info(owner: str, name: str, token: Optional[str] = None) -
|
|
| 148 |
|
| 149 |
|
| 150 |
def classify_compatibility(info: dict[str, Any]) -> dict[str, Any]:
|
|
|
|
|
|
|
|
|
|
| 151 |
sdk = info.get("sdk", "unknown")
|
| 152 |
notes: list[str] = []
|
| 153 |
warnings: list[str] = []
|
|
@@ -239,19 +242,22 @@ def classify_compatibility(info: dict[str, Any]) -> dict[str, Any]:
|
|
| 239 |
"mode": "hosted_wrapper",
|
| 240 |
"available": True,
|
| 241 |
"stub": False,
|
| 242 |
-
"artifact": "project-zip",
|
| 243 |
"reason": (
|
| 244 |
-
|
| 245 |
-
|
|
|
|
|
|
|
|
|
|
| 246 |
+ (
|
| 247 |
"✗ GPU local impossible (Hosted Wrapper keeps inference on HF)"
|
| 248 |
if info.get("needs_gpu")
|
| 249 |
-
else "⚠ Hosted Wrapper WebView — not a Local offline
|
| 250 |
)
|
| 251 |
),
|
| 252 |
"compat": {
|
| 253 |
"project": "ok",
|
| 254 |
-
"apk": "warn",
|
| 255 |
"gpu_local": "no" if info.get("needs_gpu") else "warn",
|
| 256 |
},
|
| 257 |
},
|
|
|
|
| 148 |
|
| 149 |
|
| 150 |
def classify_compatibility(info: dict[str, Any]) -> dict[str, Any]:
|
| 151 |
+
from backend.app.converters.mobile.android_sdk import android_sdk_ready
|
| 152 |
+
|
| 153 |
+
_apk_env = android_sdk_ready()
|
| 154 |
sdk = info.get("sdk", "unknown")
|
| 155 |
notes: list[str] = []
|
| 156 |
warnings: list[str] = []
|
|
|
|
| 242 |
"mode": "hosted_wrapper",
|
| 243 |
"available": True,
|
| 244 |
"stub": False,
|
| 245 |
+
"artifact": "apk" if _apk_env else "project-zip",
|
| 246 |
"reason": (
|
| 247 |
+
(
|
| 248 |
+
"✓ Debug APK built in SpaceForge when SDK present · "
|
| 249 |
+
if _apk_env
|
| 250 |
+
else "✓ Capacitor Android project · ⚠ APK fallback if build fails · "
|
| 251 |
+
)
|
| 252 |
+ (
|
| 253 |
"✗ GPU local impossible (Hosted Wrapper keeps inference on HF)"
|
| 254 |
if info.get("needs_gpu")
|
| 255 |
+
else "⚠ Hosted Wrapper WebView — not a Local offline model package"
|
| 256 |
)
|
| 257 |
),
|
| 258 |
"compat": {
|
| 259 |
"project": "ok",
|
| 260 |
+
"apk": "ok" if _apk_env else "warn",
|
| 261 |
"gpu_local": "no" if info.get("needs_gpu") else "warn",
|
| 262 |
},
|
| 263 |
},
|
backend/app/services/builds.py
CHANGED
|
@@ -9,7 +9,13 @@ from dataclasses import dataclass, field
|
|
| 9 |
from pathlib import Path
|
| 10 |
from typing import Any, Optional
|
| 11 |
|
| 12 |
-
from backend.app.config import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
from backend.app.converters.base import BuildContext
|
| 14 |
from backend.app.converters.registry import get_registry
|
| 15 |
from backend.app.security.zipsafe import is_within_directory
|
|
@@ -131,8 +137,9 @@ class BuildManager:
|
|
| 131 |
job.errors[tid] = f"Unknown target: {tid}"
|
| 132 |
job.logs.append(job.errors[tid])
|
| 133 |
continue
|
|
|
|
| 134 |
try:
|
| 135 |
-
result = await asyncio.wait_for(conv.convert(ctx), timeout=
|
| 136 |
except asyncio.TimeoutError:
|
| 137 |
job.errors[tid] = "Converter timed out"
|
| 138 |
job.logs.append(f"{tid}: timeout")
|
|
@@ -143,6 +150,7 @@ class BuildManager:
|
|
| 143 |
continue
|
| 144 |
if result.ok and result.artifact:
|
| 145 |
art = result.artifact
|
|
|
|
| 146 |
job.artifacts[tid] = {
|
| 147 |
"filename": art.filename,
|
| 148 |
"mode": art.mode,
|
|
@@ -150,8 +158,15 @@ class BuildManager:
|
|
| 150 |
"notes": art.notes,
|
| 151 |
"size": art.path.stat().st_size if art.path.exists() else 0,
|
| 152 |
"path_name": art.path.name,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
}
|
| 154 |
-
job.logs.append(
|
|
|
|
|
|
|
|
|
|
| 155 |
else:
|
| 156 |
job.errors[tid] = result.error or "converter failed"
|
| 157 |
job.logs.append(f"{tid}: {job.errors[tid]}")
|
|
|
|
| 9 |
from pathlib import Path
|
| 10 |
from typing import Any, Optional
|
| 11 |
|
| 12 |
+
from backend.app.config import (
|
| 13 |
+
ANDROID_BUILD_TIMEOUT,
|
| 14 |
+
BUILD_TIMEOUT,
|
| 15 |
+
BUILD_TTL_SECONDS,
|
| 16 |
+
BUILDS_ROOT,
|
| 17 |
+
MAX_CONCURRENT_BUILDS,
|
| 18 |
+
)
|
| 19 |
from backend.app.converters.base import BuildContext
|
| 20 |
from backend.app.converters.registry import get_registry
|
| 21 |
from backend.app.security.zipsafe import is_within_directory
|
|
|
|
| 137 |
job.errors[tid] = f"Unknown target: {tid}"
|
| 138 |
job.logs.append(job.errors[tid])
|
| 139 |
continue
|
| 140 |
+
timeout = ANDROID_BUILD_TIMEOUT if tid == "android" else BUILD_TIMEOUT
|
| 141 |
try:
|
| 142 |
+
result = await asyncio.wait_for(conv.convert(ctx), timeout=timeout)
|
| 143 |
except asyncio.TimeoutError:
|
| 144 |
job.errors[tid] = "Converter timed out"
|
| 145 |
job.logs.append(f"{tid}: timeout")
|
|
|
|
| 150 |
continue
|
| 151 |
if result.ok and result.artifact:
|
| 152 |
art = result.artifact
|
| 153 |
+
is_apk = art.path.suffix.lower() == ".apk"
|
| 154 |
job.artifacts[tid] = {
|
| 155 |
"filename": art.filename,
|
| 156 |
"mode": art.mode,
|
|
|
|
| 158 |
"notes": art.notes,
|
| 159 |
"size": art.path.stat().st_size if art.path.exists() else 0,
|
| 160 |
"path_name": art.path.name,
|
| 161 |
+
"binary_included": is_apk,
|
| 162 |
+
"apk_included": is_apk,
|
| 163 |
+
"artifact_kind": "apk" if is_apk else ("project-zip" if art.filename.endswith(".zip") else "file"),
|
| 164 |
+
"project_only": bool(result.project_only),
|
| 165 |
}
|
| 166 |
+
job.logs.append(
|
| 167 |
+
f"{tid}: ok → {art.filename} ({art.mode}"
|
| 168 |
+
f"{', APK' if is_apk else ', project-zip-fallback' if result.project_only else ''})"
|
| 169 |
+
)
|
| 170 |
else:
|
| 171 |
job.errors[tid] = result.error or "converter failed"
|
| 172 |
job.logs.append(f"{tid}: {job.errors[tid]}")
|
backend/tests/test_converters.py
CHANGED
|
@@ -83,7 +83,11 @@ async def test_stub_appimage(tmp_path: Path):
|
|
| 83 |
|
| 84 |
|
| 85 |
@pytest.mark.asyncio
|
| 86 |
-
async def test_android_capacitor_project(tmp_path: Path):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
from backend.app.converters.mobile.android import AndroidConverter
|
| 88 |
|
| 89 |
r = await AndroidConverter().convert(_ctx(tmp_path))
|
|
@@ -91,8 +95,8 @@ async def test_android_capacitor_project(tmp_path: Path):
|
|
| 91 |
assert r.project_only
|
| 92 |
assert r.artifact.mode == "hosted_wrapper"
|
| 93 |
assert "project" in r.artifact.filename
|
| 94 |
-
assert
|
| 95 |
-
assert "
|
| 96 |
with zipfile.ZipFile(r.artifact.path) as zf:
|
| 97 |
names = zf.namelist()
|
| 98 |
assert any("capacitor.config.json" in n for n in names)
|
|
@@ -113,7 +117,10 @@ async def test_android_capacitor_project(tmp_path: Path):
|
|
| 113 |
|
| 114 |
|
| 115 |
@pytest.mark.asyncio
|
| 116 |
-
async def test_android_gpu_notes(tmp_path: Path):
|
|
|
|
|
|
|
|
|
|
| 117 |
from backend.app.converters.mobile.android import AndroidConverter
|
| 118 |
|
| 119 |
info = dict(SAMPLE)
|
|
|
|
| 83 |
|
| 84 |
|
| 85 |
@pytest.mark.asyncio
|
| 86 |
+
async def test_android_capacitor_project(tmp_path: Path, monkeypatch):
|
| 87 |
+
# Unit tests force project-zip path (no SDK assemble in CI)
|
| 88 |
+
monkeypatch.setenv("SPACEFORGE_ANDROID_SDK", "0")
|
| 89 |
+
monkeypatch.delenv("ANDROID_HOME", raising=False)
|
| 90 |
+
monkeypatch.delenv("ANDROID_SDK_ROOT", raising=False)
|
| 91 |
from backend.app.converters.mobile.android import AndroidConverter
|
| 92 |
|
| 93 |
r = await AndroidConverter().convert(_ctx(tmp_path))
|
|
|
|
| 95 |
assert r.project_only
|
| 96 |
assert r.artifact.mode == "hosted_wrapper"
|
| 97 |
assert "project" in r.artifact.filename
|
| 98 |
+
assert r.artifact.filename.endswith(".zip")
|
| 99 |
+
assert "FALLBACK" in (r.artifact.notes or "") or "project zip" in (r.artifact.notes or "").lower()
|
| 100 |
with zipfile.ZipFile(r.artifact.path) as zf:
|
| 101 |
names = zf.namelist()
|
| 102 |
assert any("capacitor.config.json" in n for n in names)
|
|
|
|
| 117 |
|
| 118 |
|
| 119 |
@pytest.mark.asyncio
|
| 120 |
+
async def test_android_gpu_notes(tmp_path: Path, monkeypatch):
|
| 121 |
+
monkeypatch.setenv("SPACEFORGE_ANDROID_SDK", "0")
|
| 122 |
+
monkeypatch.delenv("ANDROID_HOME", raising=False)
|
| 123 |
+
monkeypatch.delenv("ANDROID_SDK_ROOT", raising=False)
|
| 124 |
from backend.app.converters.mobile.android import AndroidConverter
|
| 125 |
|
| 126 |
info = dict(SAMPLE)
|
backend/tests/test_provider.py
CHANGED
|
@@ -47,7 +47,7 @@ def test_classify_gpu_and_unknown():
|
|
| 47 |
assert android["stub"] is False
|
| 48 |
assert android["mode"] == "hosted_wrapper"
|
| 49 |
assert android["compat"]["project"] == "ok"
|
| 50 |
-
assert android["compat"]["apk"]
|
| 51 |
assert android["compat"]["gpu_local"] == "no" # needs_gpu True in this test
|
| 52 |
|
| 53 |
|
|
@@ -93,4 +93,4 @@ def test_android_compat_no_gpu():
|
|
| 93 |
assert android["available"] is True
|
| 94 |
assert android["mode"] == "hosted_wrapper"
|
| 95 |
assert android["compat"]["gpu_local"] == "warn"
|
| 96 |
-
assert "
|
|
|
|
| 47 |
assert android["stub"] is False
|
| 48 |
assert android["mode"] == "hosted_wrapper"
|
| 49 |
assert android["compat"]["project"] == "ok"
|
| 50 |
+
assert android["compat"]["apk"] in {"ok", "warn"}
|
| 51 |
assert android["compat"]["gpu_local"] == "no" # needs_gpu True in this test
|
| 52 |
|
| 53 |
|
|
|
|
| 93 |
assert android["available"] is True
|
| 94 |
assert android["mode"] == "hosted_wrapper"
|
| 95 |
assert android["compat"]["gpu_local"] == "warn"
|
| 96 |
+
assert "Hosted Wrapper" in android["reason"] or "project" in android["reason"].lower() or "APK" in android["reason"]
|
frontend/src/i18n/en.ts
CHANGED
|
@@ -29,7 +29,7 @@ export const en = {
|
|
| 29 |
compatProjectOk: "project",
|
| 30 |
compatProjectNo: "no project",
|
| 31 |
compatApkOk: "APK included",
|
| 32 |
-
compatApkWarn: "APK
|
| 33 |
compatGpuNo: "GPU local impossible",
|
| 34 |
compatGpuWarn: "not Local offline APK",
|
| 35 |
} as const;
|
|
|
|
| 29 |
compatProjectOk: "project",
|
| 30 |
compatProjectNo: "no project",
|
| 31 |
compatApkOk: "APK included",
|
| 32 |
+
compatApkWarn: "APK fallback / build failed",
|
| 33 |
compatGpuNo: "GPU local impossible",
|
| 34 |
compatGpuWarn: "not Local offline APK",
|
| 35 |
} as const;
|
scripts/docker_warmup_android.sh
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Pre-warm Capacitor + Gradle caches inside the SpaceForge Docker image.
|
| 3 |
+
set -euo pipefail
|
| 4 |
+
echo "==> SpaceForge Android warmup"
|
| 5 |
+
: "${ANDROID_HOME:?ANDROID_HOME required}"
|
| 6 |
+
: "${JAVA_HOME:?JAVA_HOME required}"
|
| 7 |
+
export ANDROID_SDK_ROOT="${ANDROID_SDK_ROOT:-$ANDROID_HOME}"
|
| 8 |
+
WARM_DIR=/tmp/sf-android-warm
|
| 9 |
+
rm -rf "$WARM_DIR"
|
| 10 |
+
mkdir -p "$WARM_DIR/www"
|
| 11 |
+
cd "$WARM_DIR"
|
| 12 |
+
|
| 13 |
+
cat > package.json <<'JSON'
|
| 14 |
+
{
|
| 15 |
+
"name": "sf-warm",
|
| 16 |
+
"private": true,
|
| 17 |
+
"version": "0.0.1",
|
| 18 |
+
"dependencies": {
|
| 19 |
+
"@capacitor/android": "6.1.2",
|
| 20 |
+
"@capacitor/core": "6.1.2"
|
| 21 |
+
},
|
| 22 |
+
"devDependencies": {
|
| 23 |
+
"@capacitor/cli": "6.1.2"
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
JSON
|
| 27 |
+
|
| 28 |
+
cat > capacitor.config.json <<'JSON'
|
| 29 |
+
{
|
| 30 |
+
"appId": "com.spaceforge.warmup",
|
| 31 |
+
"appName": "SFWarm",
|
| 32 |
+
"webDir": "www",
|
| 33 |
+
"server": { "url": "https://huggingface.co", "cleartext": false }
|
| 34 |
+
}
|
| 35 |
+
JSON
|
| 36 |
+
|
| 37 |
+
cat > www/index.html <<'HTML'
|
| 38 |
+
<!DOCTYPE html><html><body><p>SpaceForge warmup</p></body></html>
|
| 39 |
+
HTML
|
| 40 |
+
|
| 41 |
+
npm install --no-audit --no-fund
|
| 42 |
+
npx cap add android
|
| 43 |
+
cd android
|
| 44 |
+
chmod +x gradlew || true
|
| 45 |
+
./gradlew assembleDebug --no-daemon --stacktrace
|
| 46 |
+
echo "==> Warmup APK build OK"
|
| 47 |
+
# Keep gradle caches; drop project sources
|
| 48 |
+
cd /
|
| 49 |
+
rm -rf "$WARM_DIR"
|
| 50 |
+
echo "==> Warmup complete"
|