Android apps must target a minimum required API level for the app to be published in the Google Play Store. As of November 2021, updates to apps already on the Play Store will need to target API level 30 or above and adjust for behavioral changes in Android 11. This article provides additional information about this requirement.
Therefore, Cordova apps that use cordova-android 9.1.0 or below will need to be upgraded to use at least cordova-android 10.0.0 to meet this requirement. Below are the steps to check a project’s cordova-android version, upgrade to the latest cordova-android version, and audit Cordova plugins for compatibility with the latest cordova-android version.
Check the cordova-android Plugin Version Used in the Project
Method 1: Check the package.json
- Open the project’s root package.json file
- Find the cordova-android version in the “dependencies” object.
Method 2: Check through CLI
- Create a new terminal or command prompt session
- Navigate to the project directory
- Run the following command:
cordova info
- Find the cordova-android version next to the “android” key in the “Project Installed Platforms” section of the resulting output
Upgrade to Latest cordova-android Version
Upgrading between major versions of cordova-android will require the android platform to be removed and re-added to the project.
The version of the Cordova CLI used to add the android platform to a Cordova project will determine the cordova-android version used for the project if the cordova-android version is not specified. Therefore, we would recommend upgrading the Cordova CLI when upgrading between major versions of the cordova-android plugin. Otherwise, the cordova-android version will need to be specified when adding the android platform back into the project.
Remove the android platform from the project
- Create a new terminal or command prompt session
- Navigate to the project directory
- Run the following command:
cordova platform rm android
Update the Cordova CLI (Optional)
- In the terminal or command prompt session, verify that there is a newer version of the Cordova CLI available by running:
npm -g outdated cordova
- If a newer version of the CLI is available run
npm -g uninstall cordova
- Then run
npm install -g cordova
ornpm -g install cordova@X.X.X
for a specific version of the CLI you wish to upgrade to. The Cordova CLI version installed during this process will appear at the bottom of the logs.
Add the Android Platform back into the Project
After removing the android platform and updating the Cordova CLI, run cordova platform add android
if the Cordova CLI has been updated to the latest version.
Otherwise, run cordova platform add android@X.X.X
for the cordova-android version you wish to upgrade to.
Audit Cordova Plugins for Compatibility with the Latest cordova-android Version
Adding the android platform back into the project will generate logs which can indicate if there are plugins that are not compatible with the upgraded cordova-android version.
However, plugins can be manually audited with the following method:
- In the plugins directory, open the package.json file for a plugin you wish to audit
- Under the engines element, find the "cordovaDependencies" object
- Look for any keys that reference cordova-android for the version of the cordova plugin used in the project. If the cordova-android version needed by the plugin does not match the cordova-android version after the project has been upgraded, then the plugin will also need to be upgraded or replaced
Cordova also provides documentation on the upgrade process for each cordova-android version along with additional notes such as breaking changes for each version. For example, cordova-android 10.0.0 has a breaking change as a result of using the WebViewAssetLoader API to load web content using https instead of http. So it is recommended to review these changes and plugin compatibility before upgrading a project.
Comments
0 comments
Article is closed for comments.