# Launch your Android game

A fixed route from "my web game is playable" to "my game is on Google Play". For a game in HTML and
JavaScript (for example with vite) that becomes an Android app with Capacitor. Every step is a
command or an action in the Play Console. Skip none.

## How to use this

This guide is written for you and for your agent (Claude Code, Codex or another).

1. Put this file in the folder of your game, for example as `docs/ANDROID-LAUNCH.md`.
2. Tell your agent: *"Read docs/ANDROID-LAUNCH.md and prepare this game for Android, up to the
   development build on my phone."*
3. The steps in the Play Console you take yourself, in your browser. The agent can talk you through
   them.

**You type the password of your upload key yourself.** Let the agent prepare the command. It then
asks for the password itself, and the agent does not see it. Keep it in a password manager.

## What you need

- Node.js, and your game as a web project that builds with one command (for example `vite build`
  into `dist/`).
- Android Studio, or the Android SDK and a JDK (21) on their own, with `adb` and `keytool`.
- An Android phone with developer options and USB debugging on, or wireless debugging.
- A Google Play developer account (a one-time registration).
- A privacy policy at an address of your own, also when your game collects nothing.

## 1. Preparing the project (once per game)

1. **Add Capacitor:**
   ```bash
   npm i @capacitor/core @capacitor/android @capacitor/app
   npm i -D @capacitor/cli
   npx cap init "<Name>" <package-name> --web-dir dist
   npx cap add android
   ```
   The package name (for example `com.yourstudio.name`) stays the same forever. Choose it well.
2. **Two versions side by side.** Give `android/app/build.gradle` two kinds of builds:
   - a development build (debug) with `applicationIdSuffix ".dev"` and the name "<Name> Dev", which
     sits next to the store version on your phone;
   - a public build (release), signed with your upload key.

   Set the label through `manifestPlaceholders`, and in `AndroidManifest.xml`
   `android:label="${appLabel}"` on the application and the activity. Read the version from
   `package.json`: `versionName` is the version, `versionCode` a number that must go up with every
   upload.
3. **A build script** (`tools/android.mjs`) with two commands, and in `package.json`:
   ```json
   "apk": "node tools/android.mjs apk",
   "aab": "node tools/android.mjs aab",
   "bump": "npm version patch --no-git-tag-version"
   ```
   `apk` does: web build, `npx cap sync android`, `gradlew assembleDebug`, `adb install -r`.
   `aab` does: web build, `npx cap sync android`, `gradlew bundleRelease`. Always build through these
   two, never with gradle on its own (see "Learned").
4. **The dev server leaves Android alone.** Set
   `server.watch.ignored: ['**/android/**', '**/dist/**', '**/release/**']` in `vite.config.js`.
   Otherwise the dev server crashes (`EBUSY`) as soon as gradle builds.
5. **The upload key**, in a folder outside the project:
   ```bash
   keytool -genkeypair -v -keystore "<keys-folder>/<name>-upload.jks" -alias <name> -keyalg RSA -keysize 2048 -validity 10000 -dname "CN=<Studio>, O=<Studio>, C=<country>"
   ```
   `keytool` asks for the password itself. Then write `android/keystore.properties`:
   ```
   storeFile=<path to>/<name>-upload.jks
   storePassword=<password>
   keyAlias=<name>
   keyPassword=<password>
   ```
   Put `android/keystore.properties` and `*.jks` in `.gitignore`, and **back up the keys folder**.
   Lost is lost.
6. **`android/local.properties`** with `sdk.dir=` the path to your Android SDK (in `.gitignore`
   too).
7. **Icons:** an adaptive icon (foreground, background, monochrome) per density in
   `android/app/src/main/res/mipmap-*`, and a 512×512 PNG for the store.
8. **Full screen and portrait:** immersive full screen in `MainActivity.java`, and
   `android:screenOrientation="portrait"` in the manifest.
9. **No dark band at the top.** In `capacitor.config.json`:
   ```json
   "plugins": { "SystemBars": { "insetsHandling": "disable", "hidden": true } }
   ```
   Otherwise Capacitor 8 on Android 15 and newer pads the WebView with a band for the status bar.
10. **Game Mode off.** Put `android:appCategory="game"` on `<application>`, with this meta-data:
    ```xml
    <meta-data android:name="android.game_mode_config" android:resource="@xml/game_mode_config" />
    ```
    and in `res/xml/game_mode_config.xml`:
    ```xml
    <game-mode-config xmlns:android="http://schemas.android.com/apk/res/android"
        android:allowGameDownscaling="false" />
    ```
    Otherwise Samsung Game Booster renders the store version at 75 % on phones with a WQHD+ screen,
    and the WebView zooms out as soon as something slides out of view: everything small, top left.
    See "Learned".
11. **A changelog** in `docs/CHANGELOG.md`: per version a block `## <version>` with the changes in
    every language of the store, in whole sentences.
12. **A release kit** (`tools/release-kit.py` or `.mjs`) that makes a folder `release/<version>/`
    per version with the `.aab`, the store texts, the screenshots, and `release-notes.txt` in the
    format of the Console:
    ```
    <en-US>
    ...
    </en-US>
    <nl-NL>
    ...
    </nl-NL>
    ```
    Let the kit refuse when the block for the version is missing from the changelog.

## 2. The development build (daily)

```bash
npm run apk
```

Builds, syncs and installs "<Name> Dev" on the phone, next to the store version. `adb devices` must
show the device. Testing without a phone: `npx vite --host`, and on the phone
`http://<ip-of-the-pc>:<port>/`.

## 3. The public build

```bash
npm run bump      # version +1: Play requires a higher versionCode with every upload
                  # now write the block ## <version> in docs/CHANGELOG.md
npm run aab       # signed .aab
python tools/release-kit.py   # release/<version>/ with .aab, release-notes.txt, texts, screenshots
```

Only start in the Console once the folder `release/<version>/` really exists.

## 4. The Play Console (once per game)

1. **Create the app:** name, default language (English reaches the most people), game, free or
   paid, the declarations.
2. **Accept Play App Signing.** Google keeps the real key; you upload with the upload key. The first
   upload records the upload key.
3. **The tasks on the dashboard:**
   - **Store listing:** short description (80 characters), full description, icon 512×512, feature
     graphic 1024×500, at least two phone screenshots (9:16, 1080×1920 or larger), tablet ones if
     you like. Then add translations, with screenshots in that language.
   - **Made with AI?** On upload the Console asks per item whether it was made or edited with AI.
     Real recordings of your game are not labelled; an icon or illustration made with an AI image
     tool is. Labelling is a statement, not a rejection.
   - **Privacy policy:** its address, also when the app collects nothing.
   - App access, ads, content rating (the questionnaire), target audience (13+ is the simplest;
     younger brings extra requirements), data safety, category, contact address.
4. **Internal test:** testers (a list of e-mail addresses), new release, upload the `.aab`, paste
   the contents of `release-notes.txt`, save, review, roll out. Testers get a link to join; usually
   they can install within minutes.
5. **The pre-launch report,** after about an hour: real devices, crashes, screenshots,
   accessibility. No crashes, then on to a closed test or production. According to Google, a
   personal developer account first has to run a closed test with a minimum number of testers for a
   while before production opens: look in the Console at what applies to your account.
6. **Every next version:** the steps of chapter 3, then in the Console a new release, the `.aab`
   from `release/<version>/`, paste the release notes, roll out.
7. **Then also send it for review.** The publishing overview has a button to send the changes for
   review. Without that click the release stays where it is. Every update is reviewed too, usually
   within hours.
8. **"Version code has already been used":** that code was already in the app's library (a
   discarded draft counts too). Do not look for why: `npm run bump`, rename the changelog block,
   `aab` and the kit again.
9. The release notes of a live release cannot be changed, only with a new release.
10. When you are on the list of testers yourself, the store page tells you that you are a tester,
    also when production is live. That is not a mistake.

**Rhythm:** not every small change to production. The development build daily, testers through the
internal test, production gets releases that bundle changes. Only a crash fix goes at once.

## 5. Material for the store

- **Screenshots in the language of the listing.** Set the game to that language and take them on
  the phone (`adb exec-out screencap -p > shot.png`), or let a script take them.
- **Feature graphic 1024×500:** your logo or game heading on a field of colour; no text needed.
- **Description:** two or three sentences on what the game is, three bullet points, no promises
  about prices or performance.
- **Video:** see the guide *Promo videos of your game*.

## 6. In the game itself

- Put a button in the About screen to your developer page on Google Play
  (`https://play.google.com/store/apps/dev?id=<your-id>`), so that players find your other games.
- Check on a tablet or a wide screen that buttons such as close really are where they belong.

## 7. Checklist before every public build

- [ ] tests green, the development build played on at least one phone
- [ ] `android:appCategory="game"` and `game_mode_config.xml` in the manifest
- [ ] version raised, and the About screen shows that version
- [ ] `npm run aab` without a warning about signing
- [ ] release notes in every language in `docs/CHANGELOG.md`, and `release/<version>/release-notes.txt`
      exists
- [ ] the pre-launch report read: no crashes, small screens fine
- [ ] `git tag v<version>`
- [ ] in the Console, after rolling out, also sent for review
- [ ] **after going live, the store version itself tested,** not the development build: cold start,
      play, settings, the win screen, the About screen

## 8. Learned in production

- **The store version behaves differently from the development build.** Only an install from Google
  Play counts as a game for Android. Samsung Game Booster then renders games at 75 % on phones with
  a WQHD+ screen and stretches the picture; the WebView then zooms out the whole page as soon as
  something sticks out of view for one frame, such as a panel that slides in. A development build
  through adb is not affected and so proves nothing. The fix: step 10 of chapter 1, and the rule
  below. You can reproduce it with `adb shell cmd game`.
- **An element centred with `transform: translateX(-50%)`** gets an animation of its own that
  repeats that translate. An animation with only `translateY` or `scale` overrides the centring and
  makes the element stick out to the right for one frame.
- **The sound crackles when going to the home screen and when closing.** In the Capacitor WebView,
  `visibilitychange` does not fire when the app goes to the background, so Web Audio plays on until
  Android cuts it off hard. The fix: one master bus for effects and music; on `pause` of
  `@capacitor/app` fade that bus out in 80 ms and `ctx.suspend()`, on `resume` `resume()` and fade
  in again. A close button fades first and only then calls `App.exitApp()`.
- **A fix was in the source, but in no app.** Gradle run on its own without `cap sync` takes the web
  files of the previous sync along. Always build with `npm run apk` or `npm run aab`; after gradle on
  its own, first `npx cap sync android`. Check it with
  `unzip -p <apk> 'assets/public/assets/*.css' | grep -c <something from your fix>`. A fix is only
  done when the new version is in the Console; read the version on the phone with
  `adb shell dumpsys package <package-name> | grep versionName`.
