Ionic "capacitor build" with no platform added in CI
ionic capacitor build wraps Capacitor sync and a native build. It needs the target platform folder to exist. On a clean runner with gitignored native folders, the command fails because the platform was never added.
What this error means
ionic capacitor build android (or ios) stops because Capacitor cannot find the platform, often surfacing the underlying "Could not find the android platform" message.
> capacitor sync android
[error] Could not find the android platform in: ./android
Try running: npx cap add androidCommon causes
The platform was never added on the runner
ionic capacitor build assumes ./android or ./ios exists. If those folders are gitignored and ionic capacitor add was not run, there is nothing to build.
Building a platform the runner cannot host
Attempting ionic capacitor build ios on a Linux runner cannot work because iOS requires macOS and Xcode.
How to fix it
Add the platform before building
- Run ionic capacitor add android (or ios) once dependencies are installed.
- Build the web app, then run ionic capacitor build.
- Use a macOS runner for ios.
- run: npm ci && ionic build
- run: ionic capacitor add android
- run: ionic capacitor build android --no-openCommit native folders instead
If you prefer to keep native folders in git, stop ignoring them so they are present on checkout and add is not needed.
How to prevent it
- Add each native platform before ionic capacitor build.
- Build iOS only on macOS runners.
- Be consistent about committing or regenerating native folders.