Install gradle for using in cordova build android

2019-01-17 08:09发布

问题:

I have installed cordova and android sdk on linux mint 17, and downloaded gradle 2.4 (bin) and extracted it and set path to it, now I can get gradle -v from terminal, its ok, but when i want to build cordova :

cordova build

it starts to download gradle 2.2....

how i can set it to use current gradle 2.4 insteed downloading older version?

gradle -v

------------------------------------------------------------
Gradle 2.4
------------------------------------------------------------

Build time:   2015-05-05 08:09:24 UTC
Build number: none
Revision:     5c9c3bc20ca1c281ac7972643f1e2d190f2c943c

Groovy:       2.3.10
Ant:          Apache Ant(TM) version 1.9.4 compiled on April 29 2014
JVM:          1.7.0_79 (Oracle Corporation 24.79-b02)
OS:           Linux 3.13.0-24-generic i386

回答1:

I had figured out the reason:
See the code GradleBuilder.prototype.prepEnv in $PROJECT_ROOT/platforms/android/cordova/lib/builders/GradleBuilder.js。

A quick fix :

export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=file:///local/path/to/gradle-2.4-all.zip
cordova run android

Notice:

  1. This will unzip to $USER_HOME/.gradle/wrapper/dists/gradle-2.4-all/5i28vc5j9c3ssbtreg4518ujvp/gradle-2.4 .
  2. export command must always be executed before run cordova.

If the network is slow, you download gradle-2.2.1-all.zip manually, then use this method once.

Also, you can change GradleBuilder.js's code or request a enhancement/issue.



回答2:

Window, Linux & MacOS users - Install Gradle manually


Step 1. Download the latest Gradle distribution

Step 2. Unpack the distribution Create a new directory C:\Gradle with File Explorer.

Open a second File Explorer window and go to the directory where the Gradle distribution was downloaded. Double-click the ZIP archive to expose the content. Drag the content folder gradle-[VERSION] to your newly created C:\Gradle folder.

Alternatively you can unpack the Gradle distribution ZIP into C:\Gradle using an archiver tool of your choice.

Step 3. Configure your system environment

  • Linux & MacOS users

Configure your PATH environment variable to include the bin directory of the unzipped distribution, e.g.:

 $ export PATH=$PATH:/opt/gradle/gradle-4.1/bin

  • Microsoft Windows users

In File Explorer right-click on the This PC (or Computer) icon, then click Properties -> Advanced System Settings -> Environmental Variables.

Under System Variables select Path, then click Edit. Add an entry for C:\Gradle\gradle-4.1\bin. Click OK to save.

Step 4. Verify your installation

Open a console (or a Windows command prompt) and run below command to run Gradle and display the version, e.g.:

gradle -v

OutPut

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\rupesh.a.yadav>gradle -v

------------------------------------------------------------
Gradle 4.1
------------------------------------------------------------

Build time:   2017-08-07 14:38:48 UTC
Revision:     941559e020f6c357ebb08d5c67acdb858a3defc2

Groovy:       2.4.11
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_144 (Oracle Corporation 25.144-b01)
OS:           Windows 10 10.0 amd64

C:\Users\rupesh.a.yadav>

Read - For More

Hope this will be a help for all! :)