1

Some times ago, I tried to build my ionic project on a macOS by:

  1. ionic cap build android
  2. ionic cap build ios

Similar to this question, when I run above commands I got:

[ERROR] Unable to find command: cap build android (or ios)

  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

I considered all the given answers and points for that question, e.g., I ensured:

  1. capacitor is installed
  2. android and ios platforms are added
  3. uninstalled and installed ionic and ionic/cli and ionic/core.

None of the above solved the problem. Then, I started to use ionic cap run android (or ios) and everything was working perfectly.

However, today, I tried to run/build an old code with this command on the macOS, and I got some errors related to sdk version.

Then, I build the same code on another system on which ionic cap build android works, and the error was gone.

To see what is the difference between the two systems, first, I checked all parameters, including min, compile, and target sdk, gradle version, gradle variables and so on, all were the same on both systems.

Then I got curious to see how is the file that shows the error on the other system, and I noticed that, this file is not even generated on the other system (the error is shown inInternalUtils in /node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/util). Thus, I think the problem is in ionic cap run android (Am I right?).

So I thought it is time to finally get ionic cap build android working on the macOS! Does any one have any idea how to get it working? Thanks in advance.

user6781
  • 25
  • 4

1 Answers1

0

Well, the solution was quite easy. As for this question @jcesarmobile mentioned, the cli was very old version. To update it, I was only running the given commands, i.e.,:

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

But as mentioned here, in macOS, you have to also remove the ionic directory (run ionic info to see where it is located). After upgrading ionic, ionic cap build android (or ios) is working.

user6781
  • 25
  • 4