4

Is there a way to setup gradle version for cordova project in visual studio?

build.gradle file contains the following string:

classpath 'com.android.tools.build:gradle:1.5.0'

But I need:

classpath 'com.android.tools.build:gradle:2.1.0'
0

3 Answers 3

10

For anyone else interested in updating the Gradle version used by Cordova, create this system environment variable:

CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL
https://services.gradle.org/distributions/gradle-3.5-all.zip 

To use a different version, get the proper link from here.

For complete guide see Upgrading Gradle for Cordova mobile apps in Windows

4

No. We do not directly expose this setting in our tools. However, you can manually configure the platform to use a different version of Gradle. Please see the Apache documentation, here:

https://cordova.apache.org/docs/en/latest/guide/platforms/android/

(Disclosure: I work on the tools for apache Cordova in visual studio at Microsoft)

1
  • Too bad! in this docs does not exposed neither name for system variable nor example of it(( How I can change gradle version?
    – Konstantin
    Commented Jun 27, 2023 at 12:00
1

An alternative to andreszs solution is to modify platforms\android\cordova\lib\builders\GradleBuilder.js:

var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || http\\://services.gradle.org/distributions/gradle-5.4.1-all.zip
2
  • 1
    And remember to do it again each time you remove and add the android platform..
    – andreszs
    Commented Sep 2, 2020 at 20:10
  • This solution is identical to editing files inside node_modules. Definitely a NO-NO. Commented May 14, 2023 at 4:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.