> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quiesco.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up an Expo app

> What quiesco init sets up in an Expo app, and how to build and run the e2e app.

In an Expo app (SDK 55 or later) `quiesco init` does the setup and `quiesco build` makes the e2e build; the
[quick start](https://docs.quiesco.dev/quickstart.md) goes through both, from a new app to a passing test. This page says what is set
up, so that you can check a project or do a step by hand. For an app without Expo, see
[Set up a bare React Native app](https://docs.quiesco.dev/react-native.md).

```sh theme={null}
npx quiesco init
```

`init` asks which test runner to use (Vitest, Jest or Cucumber), never overwrites a file and lists what it
left to you ([CLI](https://docs.quiesco.dev/cli.md#quiesco-init)).

## What is set up

**1. Packages**

```sh theme={null}
npx expo install expo-dev-client
npm install @quiesco/agent @quiesco/native
npm install --save-dev quiesco @quiesco/core @quiesco/expo-plugin @quiesco/vitest vitest
```

`expo-dev-client` makes the e2e build a development build, which loads its JS from Metro.
`@quiesco/vitest` is the Vitest integration; [Jest and Cucumber](https://docs.quiesco.dev/runners.md) work the same way.

**2. The config plugin and the app IDs**

```json app.json theme={null}
{
  "expo": {
    "scheme": "myapp",
    "ios": { "bundleIdentifier": "com.example.myapp" },
    "android": { "package": "com.example.myapp" },
    "plugins": ["expo-router", "expo-dev-client", "@quiesco/expo-plugin"]
  }
}
```

`@quiesco/expo-plugin` lets an e2e build connect to the test run on `localhost`; it changes nothing in
other builds. `scheme`, `ios.bundleIdentifier` and `android.package` are named so that the build and
`quiesco.config.mts` mean the same app. With an `app.config.js` or `app.config.ts`, add them yourself.

**3. Metro**

```js metro.config.js theme={null}
const { getDefaultConfig } = require('expo/metro-config');
const { withQuiesco } = require('@quiesco/agent/metro');

module.exports = withQuiesco(getDefaultConfig(__dirname));
```

`withQuiesco()` puts the agent into bundles made with `EXPO_PUBLIC_QUIESCO=1` and a no-op stub into
every other bundle.

**4. The entry file**

```ts index.ts theme={null}
import '@quiesco/agent'; // must stay the first import
import 'expo-router/entry';
```

The agent must be the first import of the app. An Expo Router app gets this entry file, and
`"main": "index.ts"` in `package.json`.

**5. The root component**

```tsx src/app/_layout.tsx theme={null}
import { QuiescoRoot } from '@quiesco/agent';
import { Stack } from 'expo-router';

export default function RootLayout() {
  return (
    <QuiescoRoot>
      <Stack />
    </QuiescoRoot>
  );
}
```

`init` leaves this one to you in an Expo Router app: wrap the root layout (`src/app/_layout.tsx`) in
`<QuiescoRoot>`.

**6. The config**

```ts quiesco.config.mts theme={null}
import { defineConfig } from '@quiesco/core';

export default defineConfig({
  apps: {
    ios: {
      bundleId: 'com.example.myapp',
      binaryPath: 'ios/build/Build/Products/Debug-iphonesimulator/myapp.app',
      // A development build loads its JS from Metro.
      devClient: { metroUrl: 'http://localhost:8081' },
    },
    android: {
      package: 'com.example.myapp',
      binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk',
      devClient: { scheme: 'myapp', metroUrl: 'http://localhost:8081' },
    },
    web: { distDir: 'dist' },
  },
});
```

`devClient` says that the app is a development build: `quiesco test` starts Metro when it is not
running. Every option is in [configuration](https://docs.quiesco.dev/config.md); the runner's own config and a first test are in
[test runners](https://docs.quiesco.dev/runners.md).

## Build and run

> [tab] iOS
>
> ```sh theme={null}
> npx quiesco build ios
> npx quiesco test --platform ios
> ```

> [tab] Android
>
> ```sh theme={null}
> npx quiesco build android
> npx quiesco test --platform android
> ```

> [tab] Web
>
> ```sh theme={null}
> EXPO_PUBLIC_QUIESCO=1 npx expo export --platform web
> npx quiesco test --platform web
> ```

`quiesco build` runs `expo prebuild` with `EXPO_PUBLIC_QUIESCO=1` and then the native build
([CLI](https://docs.quiesco.dev/cli.md#quiesco-build)); autolinking takes `@quiesco/native` only with that variable. To build on EAS
instead, see [EAS Build](https://docs.quiesco.dev/eas.md).

## Builds that are not e2e builds

Without `EXPO_PUBLIC_QUIESCO=1` Metro bundles a stub in place of the agent, autolinking leaves
`@quiesco/native` out and the config plugin writes nothing, so a release contains nothing of Quiesco and
needs no setting for that. The native directories are made for one kind of build: after an e2e build, run
`npx expo prebuild --clean` without the variable before you build a release from the same checkout.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.