# Rebuild from scratch when a build acts strangely

> In a cloud Team, ask an Agent for one build without the cache, and clear the project's cache if that fixes it.

Source: https://air.build/docs/build/start-a-build-from-scratch/

In a cloud Team, each build keeps a cache for the next one, so only what changed is compiled again. For apps built with Xcode, the cache is the project's DerivedData, Xcode's build folder. For the Android version (beta), it's Gradle's build cache and compiled build scripts. A project's build script can keep other files between builds too, such as downloaded packages.

When a build goes wrong and no change explains it, one build without the cache tells you whether the cache is the cause.

> [!NOTE]
> This is for cloud Teams. AirBuild has no button for it: you ask an Agent in the project's chat, and it uses `runbuild --no-cache` (see [runbuild](https://air.build/docs/cli/runbuild/#caches)) and `airbuild-cache` (see [airbuild-cache](https://air.build/docs/cli/airbuild-cache/)). For a local Team, see [Questions](https://air.build/docs/build/start-a-build-from-scratch/#questions).

## When to try it

- A build fails with an error that the Agents can't trace to a change in the project.
- The app in Preview doesn't show a change the Agent says it built. First tap **Reinstall** (on iPhone, the app's icon), which installs the project's latest build again. See [Run your app in Preview](https://air.build/docs/build/preview-your-app/#use-the-device). If the change still isn't there, try a build without the cache.

Signed builds for TestFlight and the App Store, and device builds such as app packages, archive the app. The help says an archive gets no DerivedData back, so for those builds DerivedData isn't the cause. Files the build script keeps can still come back.

## Build once without the cache

Ask in the project's chat, for example:

```text
The last build failed for no clear reason. Build again without the cache.
```

1. The Agent starts the build with `--no-cache`. That build starts from empty caches and saves nothing. It's for this one build only.
2. Everything is compiled again, so the build takes longer than usual.
3. The Agent tells you how it went. If it worked, open the app in Preview with **Reinstall** (on iPhone, the app's icon).

Test runs take the same option. Ask, for example, "Run the tests again without the cache." See [Have your Agents run your app's tests](https://air.build/docs/build/run-your-apps-tests/).

## If that fixed it, clear the project's cache

A build without the cache saves nothing, so the next ordinary build gets the old cache back. To get rid of it, ask:

```text
That worked. Clear this project's build cache.
```

1. The Agent can list what the Team has stored with `airbuild-cache list`, most recently used first, with each entry's size and when it was last used.
2. It deletes this project's entries with `airbuild-cache delete` and tells you how many entries it deleted and their size.
3. The next build finds no cache, so it compiles everything and takes longer. It saves a new cache, which the builds after it use.

Deleting removes only the stored cache, not the project's files. Other projects in the Team keep theirs. `airbuild-cache delete` can also remove every entry of the Team, other projects' included. Ask for that only when every project needs it: then every project's next build takes longer.

## If it fails without the cache too

Then the cache isn't the cause. Ask the Agent for the full error and a fix, for example:

```text
It still fails without the cache. What's the error, and can you fix it?
```

The messages `runbuild` itself can show are listed under Errors in [runbuild](https://air.build/docs/cli/runbuild/#errors).

## Questions

**Can I do this in a local Team?**

A local Team builds on its Mac. The help describes these caches for cloud builds, and doesn't say what a build without the cache does on the Mac. In a local Team, listing or clearing the cache stops with "no Builder cache here: list and delete work in cloud Build scripts and in a cloud Team's Environment."

**The Agent says the Team has no Builder cache.**

The message is "this Team has no Builder cache." Nothing is stored yet, so there's nothing to clear.

**Do I need to clear the cache after every strange build?**

No. The cache is saved again after every build, and only the newest copy is kept. Clear it when a build without the cache worked and the ordinary build didn't.

**Does restarting my cloud Team clear the cache?**

Neither the app nor the help says. To rule the cache out, ask for a build without it.

**How do I start an Xcode Cloud build from scratch?**

Xcode Cloud has its own switch: turn on **Clean Build** when you start the build. See [Build with Xcode Cloud](https://air.build/docs/app-store/build-with-xcode-cloud/#start-a-build).
