Upgrade Cordova CLI and platform in your app

Whenever you upgrade from a previous cordova-android or cordova-ios version, your app’s build process could introduce several unexpected errors. This guide shows how to troubleshoot your build after upgrading the Cordova platform from your app.

Apache Cordova logo phonegap

Upgrade your global Cordova CLI version

To upgrade to Cordova CLI 8.1.2, open a command prompt and type:

npm install -g [email protected]

Notice that 8.1.2 is the last CLI version that works with Visual Studio (with certain fixes). To install the latest cordova version use this command instead:

npm install -g cordova

Upgrade the cordova-android version from your app

To upgrade your cordova-android version, follow these steps:

  1. Create a ZIP backup of your app to avoid loosing important files when removing the platform, or just to keep a backup of your app with the old Cordova.
  2. Open a command prompt in your project’s root
  3. Run cordova platform rm android
    • Optional and recommended: Remove Firebase-related plugins such as phonegap-plugin-push and cordova-support-google-services.
    • Visual Studio developers better use the command prompt to manage plugins.
    • Ensure the corresponding folder is deleted from the plugins folder
    • Also make sure no references to the plugin are left in either:
      • plugins/android.json
      • plugins/fetch.json
  4. Run cordova platform add android to add a compatible cordova-android platform

    • If you get critical errors when adding the platform, return to step 3 and remove problematic plugins.
    • Side note: Dependant plugins such as cordova-support-google-services will be auto fetched when adding the platform.
  5. Run cordova platforms to check which version was installed (probably [email protected])
  6. Run cordova clean to resolve any plugin-related dependencies
  7. If your clean result is BUILD FAILED:
    1. Inspect the shown error messages to detect problematic plugin(s)
    2. Restart from step 3 and remove / update problematic plugin(s)
    3. DO NOT CONTINUE BELOW until you get a successfull clean output.
  8. Now that your clean result is BUILD SUCCESSFUL:
    • Add your google-services.json file into platforms/android/app if required.
    • Visual Studio developers: Jump to the Prevent error DEP10402 instructions below and continue with next step.
  9. Run cordova build android and check the output:
    • If the build result is BUILD FAILED:
      1. Check if your error is something like a missing google-services.json file and address this by copying the file to the proper folder.
      2. Inspect the console output to isolate problematic plugins, and restart from step 3 to remove or update them with newer versions until the error is gone.
      3. SKIPPING TO NEXT STEP IS USELESS until you get a successful build.
  10. Now that your build result is BUILD SUCCESSFUL:
    • Add the uninstalled plugins required, if any. Do not accept anything other than successful build outputs.
    • This is a great time to upgrade your plugins individually to get newest versions.
    • Visual Studio developers:
      1. Go to Tools > Options > Tools for Apache Cordova > Cordova Tools > Clear Cordova Cache. This task could take a few seconds.
      2. You can now open the solution file and compile + deploy normally.

Notice for Visual Studio fellow developers: Starting with Cordova CLI 7.1.0, whenever you deploy to emulator or device the status bar might incorrectly show Deploy failed. You should disregard this label and instead look for the INSTALL SUCCESS and LAUNCH SUCCESS messages in the console output.

Visual Studio status bar

Visual Studio 2015 status bar shows a wrong Deploy failed message with CLI 7.1.0+.

The generated APK files now will be android-debug.apk or android-release.apk, and will be present in the platforms/android/build/outputs/apk folder where Visual Studio expects to find it.

Android API levels supported by cordova-android

The supported Android API Levels and Android Versions for the past few cordova-android releases can be found in the following table. Taken from Cordova’s Requirements and Support page.

Cordova Android API levels supported

Cordova Android API levels supported

Disclaimer

The content in this post is for general information purposes only. The information is provided by the author and/or external sources and while we endeavour to keep the information up to date and correct, we make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the website or the information, products, services, or related graphics contained on the post for any purpose. Some of the content and images used in this post may be copyrighted by their respective owners. The use of such materials is intended to be for educational and informational purposes only, and is not intended to infringe on the copyrights of any individuals or entities. If you believe that any content or images used here violate your copyright, please contact us and we will take appropriate measures to remove or attribute the material in question.