Search code examples
javacordovanpmcordova-cli

Unable to add cordova plugin after cordova cli update


I have been using Cordova CLI v 6.5.0 to create my hybrid Android app which uses a custom plugin of my own making. The full toolchain is

  • Java 1.8 SDK
  • Cordova CLI 6.5.0
  • NPM 4.1.2

This has always worked without an issue. I had not upgraded to Cordova CLI 7.0.1 till today since I still supported Android 4.4 and the base version with 7.0.1 is 5.0. Having made the decision to drop support Android v 4.4 support today I decided to upgrade Cordova CLI and immediately ran into some unpleasant surprises

  • Creating a build-extras.gradle file that specifies using JavaVersion.VERSION_1_8 threw up errors that claimed that some of my source code files were not compatible. This in itself poses a problem since I make extensive use of some Java 8 features such as try_with_resources.
  • I decided to temporarily drop back to VERSION_1_7 and got the app to complile.
  • I then thought I would add my plugin to the project (expecting fully well that the system would frown at my use of Java 8 syntaxes) and ran into another unpleasant surprise which I reproduce below

    16 error Windows_NT 10.0.15063 17 error argv "H:\nodejs\node.exe" "H:\nodejs\node_modules\npm\bin\npm-cli.js" "install" "path:\to\my-plugin" "--save" 18 error node v7.5.0 19 error npm v4.1.2 20 error Invalid version: "1.0"

I do not understand these errors - perhaps someone here will be able to shed some light.


Solution

  • Try using --nofetch to install without using the new npm install mechanism:

    cordova plugin add path:\to\my-plugin --nofetch
    

    See https://cordova.apache.org/news/2017/05/04/cordova-7.html