Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova build changes distributionUrl in gradle-wrapper.properties file

I keep getting the following build exception when I run

 cordova run android --verbose 
  • What went wrong: A problem occurred evaluating root project 'android'.

    Failed to apply plugin [id 'android'] Gradle version 2.10 is required. Current version is 2.2.1. If using the gradle wrapper, try editing the distributionUrl in C:\Users\Project\gradle\wrapper\gradle-wrapper.properties to gradle-2.10-all.zip

The reason for this is the line being changed when I run the cordova build command from;

distributionUrl=http\://services.gradle.org/distributions/gradle-2.1.0-all.zip 

to

distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip 

Any way to prevent this ?

like image 778
shamaleyte Avatar asked May 09 '16 21:05

shamaleyte


People also ask

What is gradle wrapper properties file?

The Gradle wrapper is a script you add to your Gradle project and use to execute your build. The advantages are: you don't need to have Gradle installed on your machine to build the project. the wrapper guarantees you'll be using the version of Gradle required by the project.

Where do gradle wrapper properties go?

The Wrapper shell script and batch file reside in the root directory of a single or multi-project Gradle build. You will need to reference the correct path to those files in case you want to execute the build from a subproject directory e.g. ../../gradlew tasks .


2 Answers

As could be guessed, there is a script that is being run behind the scene when you issue the "Cordova build android" command. This script needs to be found in order to see the config specified for Gradle version.

You must go and check the following js file:

$PROJECT_ROOT/platforms/android/cordova/lib/builders/GradleBuilder.js

Then find the line including the following variable in the file:

GradleBuilder.prototype.prepEnv 

And check the distributionUrl variable:

var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'http\\://services.gradle.org/distributions/gradle-2.2.1-all.zip'; 

That's what you are looking for and what you need to change to gradle-2.10-all.zip URL;

Now you can run the build command, and there you go!

inspired from the following SO; install gradle for using in cordova build android

like image 83
shamaleyte Avatar answered Sep 17 '22 19:09

shamaleyte


I think is better to export the variable CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL

Example:

export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=http\\://services.gradle.org/distributions/gradle-2.14.1-all.zip 

If you are using a Mac, for example, add the export command in to the .bash_profile

nano ~/.bash_profile 
like image 42
jordenysp Avatar answered Sep 16 '22 19:09

jordenysp