[ERROR] Unable to find command: cap build android

I was using Cordova, and I am now migrating to Capacitor

I have followed the instructions, all OK, but when I type ionic cap build android, are showing the error bellow:

[ERROR] Unable to find command: cap build android

  ionic cap - Capacitor functionality

    These commands integrate with Capacitor, Ionic's new native layer project which provides an alternative to Cordova
    for native functionality in your app.

    Learn more about Capacitor:
    - Main documentation: https://ion.link/capacitor

  Usage:

    $ ionic cap <command> [<args>] [--help] [--verbose] [--quiet] [--no-interactive] [--no-color] [--confirm] [options]


    add ............................. Add a native platform to your Ionic project
    copy ............................ Copy web assets to native platforms
    open ............................ Open the IDE for a given native platform project
    run ............................. (beta) Run an Ionic project on a connected device
    sync ............................ Sync (copy + update) an Ionic project
    update .......................... Update Capacitor native platforms, install Capacitor/Cordova plugins

Please, someone know what can I do?

what command line are you using, works well on cmd but doesn’t work on windows powershell

other thing did you install capacitor

ionic cap build android

inside terminal of VSCode

Yeah, I think yes, I followed instructions from ionicframework page

you will first need to install Andriod into the app using
STEP 1: ionic cap add then select Andriod OR ionic cap add android
STEP 2: Build your app for the prod using ionic build
STEP 3: Finally use ionic build select Andriod OR ionic build android

Forgot to add Incase if ionic cap does not work replace ionic with npx

what’s your ionic CLI version?

Ionic CLI : 5.4.16 (C:\Users\moahr\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 5.8.2
@angular-devkit/build-angular : 12.1.4
@angular-devkit/schematics : 12.1.4
@angular/cli : 12.1.4
@ionic/angular-toolkit : 4.0.0

yep, that’s your problem, you are using an ancient version of Ionic CLI

run

npm uninstall -g ionic
npm uninstall -g @ionic/cli
npm install -g @ionic/cli

Worked… the build command was found…

But…

“ionic cordova build android”, build and done.

“ionic capacitor build android” need to open android studio to compile!!! Man, the android studio is very bad to my computer… I am not liked this, I think will back to cordova… Android studio I had installed only for the SDK’s

1 Like

If you don’t want to use Android Studio you can run with ionic cap run android command

I had installed the capacitor 3, was with 2… testing… thank you for the tip