npx cap add <platform> generates a native project from the template inside the platform package, so install that package first. The web build must exist too, because cap add ends with a sync.
npm install @capacitor/android
npm run build
npx cap add androidOutput
✔ Adding native android project in android in 103.75ms ✔ add in 104.75ms ✔ Copying web assets from dist to android/app/src/main/assets/public in 7.99ms ... ✔ Syncing Gradle in 396.47μs [success] android platform added!
The new android/ folder is a complete Gradle 19,597 project with its own gradlew. Run cap add once per platform and commit the result. For iOS (not run here), npm 2,036 install @capacitor/ios and npx cap add ios write ios/App; Capacitor 8 243,123 uses Swift Package Manager 25,184 by default, and --packagemanager CocoaPods 66,002 selects the older layout if a plugin still needs it.