Upgrading Gradle for Cordova mobile apps in Windows

Ocassionally, a new Cordova or plugin version will force you to upgrade your Gradle version. This process must be performed with caution, and this article shows how to chose a correct gradle version and install it on Windows.

1: Stop gradle daemon

Run this command to stop all gradle daemons, if any:

2. Delete gradle cache

Locate and delete the gradle cache folder:

To free up space, you may delete the other folders in the same level of the cache folder if you don’t plan to use the other versions anymore.

3. Download a new gradle version

Before jumping directly to latest gradle version, check compatibility with your Cordova environment. For safety reasons, I wont use anything newer than gradle 4.x on Cordova 7.1.0 alongside Visual Studio, otherwise some issues could be introduced.

Download the desired gradle version from the Gradle Distributions site. In this case I’m downloading gradle-4.1-bin.zip.

4. Unzip the downloaded file

Place the contents of the downloaded ZIP in any location such as C:\gradle\gradle-4.1

5. Add the bin path to environment variables

To edit environment variables in Windows I use Rapid Environment Editor but you can use the clumsy editor provided by Microsoft.

Set the  CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL  System variable to the URL of the downloaded gradle ZIP file:

Add to the location you used in step 4 to the Path  System variable:

Save the variables from the File > Save menu if using the Rapid Environment Editor tool.

6. Close existing command prompt and Visual Studio

Close any opened command prompts windows, otherwise your new environment variables won’t be updated. Also close Visual Studio to ensure it gets the new path later.

7. Check the new version

To check if the new version was installed correctly, run this command:

Gradle version check

Gradle version check

8. Done!

After the new gradle version has been installed, you should remove and re-add the android platform and clean your Cordova app as follows:

Remove the android platform from your app

Clean your project

Troubleshooting Cordova build errors

Check out this article if you get build errors after changing your gradle version: Common Apache Cordova build errors with Android

Also, switching gradle versions is another valid method to fix plugin-related errors.

All product names, logos, and brands in this website are property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.