# iOS and Android builds

Projects whose `repobot.deploy.json` declares `IOS` or `ANDROID` build
installable apps for real devices: TestFlight for iOS, a signed APK for
Android. The starter contains the native apps (`ios/`, SwiftUI; `android/`,
Jetpack Compose), which use the same GraphQL API as the web app.

```bash
spaceboy build ios --project prj_... --json          # TestFlight; waits (default 45 min)
spaceboy build android --project prj_... --json      # signed APK
spaceboy builds ios --project prj_... --json
spaceboy build-cancel ios --project prj_...
```

- Builds target the caller's **development** environment; if it has not
  been deployed yet, a development deploy starts first.
- Builds draw on prepaid credits by the minute (`spaceboy topup`), never on
  the monthly project price. A failed build is charged for the minutes it
  ran.
- Android builds return a direct-install APK link; installed apps offer
  later builds as in-app updates. No credentials are needed: the platform
  keeps one signing key per project.
- Statuses: `QUEUED`, `RUNNING` (stages `PREPARING_ENVIRONMENT`,
  `DISPATCHING`, `BUILDING`, `PUBLISHING`), `SUCCEEDED`, `FAILED`,
  `CANCELED`. A build with no progress for 45 minutes is failed.
- Builds run on GitHub-hosted runners (macOS for iOS).

## Connect the Apple account (iOS, once per organization)

iOS builds sign and upload under **your person's** Apple developer account,
with an App Store Connect API key. Your person creates the key once (only
the Account Holder or an Admin can): App Store Connect → Users and Access →
Integrations → App Store Connect API → Team Keys → +, role **Admin**.
Apple lets them download the `AuthKey_<KEYID>.p8` file once; they give you
the file, the Issuer ID shown above the keys table and the Team ID
(developer.apple.com → Account → Membership details).

```bash
spaceboy integrations apple connect \
  --issuer-id 57246542-96fe-1a63-e053-0824d011072a \
  --team-id ABCDE12345 \
  --key-file AuthKey_2X9R4HXF34.p8 --json        # or --key-file - < AuthKey_....p8
spaceboy integrations apple status --verify --json
spaceboy integrations apple disconnect --yes
```

- The Key ID is read from the file name (`--key-id` to override; a
  mismatch is refused before anything is sent). The key is never accepted
  as an argument, never printed, and never returned by the API.
- The key is checked with Apple before it is stored. With `--json`,
  `error.code` says why it was refused: `INVALID_KEY` (Issuer ID or Key ID
  do not belong to this file, or the key was revoked), `INSUFFICIENT_ACCESS`
  (the key's role cannot read apps or certificates; create an Admin key),
  `UNREADABLE_KEY`, or `UNAVAILABLE` (Apple could not be reached; retry).
  Apple does not reveal a key's role, so a Developer-role key passes the
  check and can still fail the first build.
- Connecting a new key makes it the one builds use; the previous one is
  kept until you `disconnect --connection <id> --yes`.
- Connecting needs an organization owner or admin, and a published project
  (exit 4 otherwise, with the command that publishes).

The first build of an app may stop because the app record does not exist:
Apple does not let an API create apps. Your person then creates it in App
Store Connect → Apps → + → New App with the bundle identifier named in the
build's `failureReason`, and you build again. The first TestFlight build
also waits for Apple's one-time beta review.

## Push notification credentials

Apps with the push capability need two more keys to reach phones; connect
them the same way:

```bash
spaceboy integrations apple-push connect --team-id ABCDE12345 --key-file AuthKey_9ABC8DEF7G.p8
spaceboy integrations firebase-push connect --service-account-file service-account.json
```

The APNs key comes from developer.apple.com → Certificates, Identifiers &
Profiles → Keys (Apple Push Notifications service enabled); the Firebase
file from the Firebase console → Project settings → Service accounts →
Generate new private key. Both take effect on the next deploy. `status`
and `disconnect` work as for `apple`.

## App Store and Google Play

Store listings are prepared as files in `store/` and validated with
`spaceboy store check`; see
[App Store and Google Play](https://spaceboy.ai/docs/agents/app-stores.md).

## Not available

- Submitting to the App Store or Google Play (a person submits, using the
  listing files and `store check`).
- Production builds (`--target production`): builds always use the
  development environment's API.
- Android App Bundles (`.aab`) for Google Play (builds are APKs).
- Simulator or emulator streaming.
