claude/skills/scaffold-new-android-project/SKILL.md
Neil Bantoc 59fc08fa5f Add android-project-full-audit and local-worker-handoff skills; sync scaffold skill
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 16:26:33 -08:00

56 lines
4.2 KiB
Markdown

---
name: scaffold-new-android-project
description: Scaffold a new Android project from scratch. Use when the user wants to start/create/bootstrap a new Android app, set up an Android project skeleton, or verify their Android dev environment (SDK, JDK, Gradle) before building. Verifies tooling, picks compatible AGP/Gradle/Kotlin versions, and produces a minimal Kotlin+Compose skeleton that `./gradlew build` passes before any feature work begins.
---
# Scaffold a New Android Project
Goal: hand back a skeleton where **`./gradlew build` exits 0** before any feature code is written. A green build is the contract — everything below serves it. Never write feature code on top of a skeleton that has not built.
## Step 1 — Check the environment (never install silently)
Run the doctor and read its report:
```bash
bash "$SKILL_DIR/scripts/doctor.sh"
```
It checks JDK (needs 17+), the Android SDK (ANDROID_HOME / ANDROID_SDK_ROOT / common locations), the cmdline-tools (adb/sdkmanager/avdmanager), installed platforms & build-tools, and a Gradle binary to bootstrap the wrapper.
- **Do not download or install anything.** If something is missing, the doctor already prints copy-pasteable commands. Surface those to the user and stop — let them run installs (suggest they use the `! <command>` prompt prefix so output lands in the session).
- If the doctor exits non-zero, **flag the blocker to the user and wait** — do not scaffold blind.
## Step 2 — Pick compatible versions
The single most common failure is an incompatible **AGP ↔ Gradle ↔ Kotlin** triple. Before scaffolding:
1. Note what's actually available: the doctor lists installed `platforms` (→ `compileSdk`) and any cached Gradle distributions.
2. If the user specified versions, use them. Otherwise pick a known-good triple and confirm against the AGP release notes (AGP's "Compatible Gradle/Kotlin" table) — **check, don't guess from memory.**
3. The default `scaffold.sh` template targets **AGP 9** with Kotlin built in (no `kotlin-android` plugin needed). If the user explicitly asks for AGP 8.x instead, adjust accordingly: apply `org.jetbrains.kotlin.android`, use `kotlinOptions`, and downgrade Gradle to ≥8.10.
4. Compose needs the Compose compiler plugin (`org.jetbrains.kotlin.plugin.compose`) for Kotlin 2.0+; the template already wires it.
## Step 3 — Generate the skeleton
```bash
bash "$SKILL_DIR/scripts/scaffold.sh" \
--dir <project-dir> --package com.example.app --name "My App" \
--compile-sdk 34 --min-sdk 24 \
--gradle-version <ver> --agp <ver> --kotlin <ver>
```
The script writes Kotlin-DSL Gradle files with a `libs.versions.toml` version catalog, a single `MainActivity` Compose screen, a theme, `res/`, `gradle.properties`, `.gitignore` (ignoring `local.properties`, `build/`, `.gradle/`, `.kotlin/`), and a `local.properties` pointing at the SDK. It then bootstraps the wrapper with a real gradle binary and runs `./gradlew build`.
The skeleton is deliberately minimal — **no Hilt, Room, Retrofit, or networking.** Those are project-specific; add them incrementally *after* this baseline builds, re-running `./gradlew build` after each addition.
## Step 4 — Confirm the contract
`scaffold.sh` runs `./gradlew build` for you. If it fails, fix the skeleton until it passes — do not proceed. If it passes, the baseline is real; report the versions used and hand off.
## Guardrails (these are why the skill exists)
- **Every claim of "it builds" must come from actually running `./gradlew build`** and seeing exit 0 — never from eyeballing the files.
- **One Gradle dialect: Kotlin DSL.** Do not mix Groovy `.gradle` files or write Kotlin syntax (`val`, `isMinifyEnabled =`) into a Groovy file.
- **Used ⇒ declared.** Every non-stdlib import must map to a declared dependency in the catalog.
- **Declared ⇒ used.** Don't add dependencies or classes the skeleton doesn't reference.
- **A referenced resource must exist** — themes, launcher icons, drawables named in the manifest. Missing resources fail resource linking, not compilation, so a Kotlin-only check won't catch them; `./gradlew build` will.
- **Secrets in `local.properties`**, never committed; read into `BuildConfig` via `buildConfigField` when needed (add `buildConfig = true`).