Impossibile to add android platform with cordova-plugin-ionic


#1

HI, I’m trying to add the android platform on my app on Osx (but on linux I’ve got the same issue). I’ve try with

ionic cordova platform add android

but I’ve got this error:

✖ Running command - failed!
[ERROR] Exception: Using cordova-fetch for cordova-android@^6.2.3

        Error: Failed to fetch platform cordova-android@^6.2.3
        Probably this is either a connection problem, or platform spec is incorrect.
        Check your connection and platform name/version/URL.

Then I try with

cordova platform add android

and I’ve got this error:

Installing "cordova-plugin-ionic" for android
Failed to install 'cordova-plugin-ionic':Error: Variable(s) missing: APP_ID, CHANNEL_NAME
    at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:362:

this is my ionic info:

% ionic info

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.13.0
    ionic (Ionic CLI) : 3.13.0

global packages:

    cordova (Cordova CLI) : 7.1.0

local packages:

    @ionic/app-scripts : 2.1.4
    Cordova Platforms  : android 6.1.2 ios 4.3.1
    Ionic Framework    : ionic-angular 3.6.0

System:

    Android SDK Tools : 26.1.1
    ios-deploy        : 1.9.0
    ios-sim           : 5.0.10
    Node              : v7.7.4
    npm               : 2.15.12
    OS                : macOS Sierra
    Xcode             : Xcode 9.0 Build version 9A235

Misc:

    backend : legacy

And if I try to update to ionic 3.13.1 the CLI told me that everythings is ok but after I run the command again it ask me to install the 3.13.1 version again.

Someone could help me please?


#2

Can we please try a few things?

Run ionic cordova platform add android --verbose and post the output.
Run cordova platform add android --debug and post the output.

Did you manually install the cordova-plugin-ionic plugin before? Use it on another platform?


#3

This is the output of ionic cordova platform add android --verbose

-> % ionic cordova platform add android --verbose
[DEBUG] CLI flags: { interactive: true, confirm: false }
[DEBUG] { cwd: ‘/Users/rex/Lavoro/Arredissima/fullApp’, local: false, binPath:
’/usr/local/lib/node_modules/ionic/bin/ionic’, libPath: ‘/usr/local/lib/node_modules/ionic/dist/index.js’ }

cordova platform add android --save
:heavy_multiplication_x: Running command - failed!
[ERROR] Exception: Using cordova-fetch for cordova-android@^6.2.3

    Error: Failed to fetch platform cordova-android@^6.2.3
    Probably this is either a connection problem, or platform spec is incorrect.

Cordova platform add android tell’s me that is already installed but it is not due to the failure of the previous command and yes, I’ve installed before the plugin for iOS but it happens also when I checkout the repository into another pc and then I’ve try to add android platform.


#4

Run cordova platform remove android first.

You might want to remove plugin, then install the platform, then add the plugin again.

Make sure to also create an issue for the plugin, something seems broken here.


#5

It seems to me there is a problem with the script that adds the plug-in to the platforms.

If the plug-in is installed before adding a new platform, the script for adding platforms checks package.json or config.xml and adds all installed plug-in to the new platform… but it doesn’t care about JSON object parameters.

If you add platforms before plug-in that need additional parameters, the error isn’t shown.

So, and excuse me for the length of my answer:

  1. Remove all platforms (correcte me if I’m wrong, maybe you’ll need to delete platforms folder)
  2. Remove plug-in’s that need additional parameters (cordova-plugin-android, cordova-plugin-facebookXXX, …)
  3. cordova platform add [your_platform] --save
  4. Install again your plug-in’s that need additional parameters.

I don’t have enough knowledge to dive into the deeps of plug-in’s, but this worked for me.

Cheers!