到gradle的官网https://gradle.org/gradle-download/下载gradle。选择Complete distribution这个下载,当前的版本为3.1,下载完毕后,解压到一个地方,将他的bin目录添加到path下。
查看下版本号:
[root@soft bin]# gradle -v
------------------------------------------------------------
Gradle 3.1
------------------------------------------------------------
Build time: 2016-09-19 10:53:53 UTC
Revision: 13f38ba699afd86d7cdc4ed8fd7dd3960c0b1f97
Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_102 (Oracle Corporation 25.102-b14)
OS: Linux 3.10.0-327.36.1.el7.x86_64 amd64
说明gradle安装成功。
在build.gradle最后加上
task showMeCache << {
configurations.compile.each { println it }
}
切换到Android Studio的Terminal标签,运行gradle -v,如果出现bash: gradle: command not found... 这样的提示,说明环境变量修改没生效,可以通过 source /etc/profile或者 . /etc/profile 来使修改的环境变量生效(修改了/etc/profile)。如果出现上面的版本信息,接着运行gradle showMeCache就可以看到本地相关的jar的信息。
[root@soft SwipeMenuDemo]# gradle showMeCache
Incremental java compilation is an incubating feature.
The TaskInputs.source(Object) method has been deprecated and is scheduled to be removed in Gradle 4.0. Please use TaskInputs.file(Object).skipWhenEmpty() instead.
:app:showMeCache
/soft/work/android/SwipeMenuDemo/app/libs/butterknife-7.0.1.jar
/soft/commondata/androidsdk/extras/android/m2repository/com/android/support/appcompat-v7/24.1.1/appcompat-v7-24.1.1.aar
/soft/work/android/SwipeMenuDemo/swipemenu/build/outputs/aar/swipemenu-release.aar
/soft/commondata/androidsdk/extras/android/m2repository/com/android/support/recyclerview-v7/24.1.1/recyclerview-v7-24.1.1.aar
/root/.gradle/caches/modules-2/files-2.1/com.google.zxing/core/3.3.0/73c49077166faa4c3c0059c5f583d1d7bd1475fe/core-3.3.0.jar
/soft/commondata/androidsdk/extras/android/m2repository/com/android/support/animated-vector-drawable/24.1.1/animated-vector-drawable-24.1.1.aar
/soft/commondata/androidsdk/extras/android/m2repository/com/android/support/support-v4/24.1.1/support-v4-24.1.1.aar
/soft/commondata/androidsdk/extras/android/m2repository/com/android/support/support-vector-drawable/24.1.1/support-vector-drawable-24.1.1.aar
/soft/commondata/androidsdk/extras/android/m2repository/com/android/support/support-annotations/24.1.1/support-annotations-24.1.1.jar
BUILD SUCCESSFUL
Total time: 0.62 secs
不要修改android studio本身的gradle。