如何重用gradle-wrapper?

所有,我从eclipse迁移到android-studio一个月。 新的构建工具很烦人。

每次我git clone一个android-sample,需要几个小时来下载它的gradle-wrapper。

我发现有很多版本的gradle-wrapper

 ninja@ninja ~/.gradle/wrapper/dists $ du -h --max-depth=1 198M ./gradle-2.2.1-all 176M ./gradle-1.11-all 86M ./gradle-1.12-bin 85M ./gradle-2.0-bin 358M ./gradle-1.12-all 186M ./gradle-2.1-all 1.1G . ninja@ninja ~/.gradle/wrapper/dists/gradle-1.12-all $ du -h --max-depth=1 179M ./2apkk7d25miauqf1pdjp1bm0uo 179M ./4ff8jj5a73a7zgj5nnzv1ubq0 358M . 

有没有一种从github构建项目的简单方法?

为什么android-studio不使用我的gradle?

 ninja@ninja ~/.gradle/wrapper/dists/gradle-1.11-all $ gradle -v ------------------------------------------------------------ Gradle 2.1 ------------------------------------------------------------ Build time: 2014-09-08 10:40:39 UTC Build number: none Revision: e6cf70745ac11fa943e19294d19a2c527a669a53 Groovy: 2.3.6 Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013 JVM: 1.7.0_67 (Oracle Corporation 24.65-b04) OS: Linux 3.13.0-24-generic i386 

我试过android-studio的设置use local gradle distribution ,并遇到编译错误:

 ninja@ninja ~/src/goshawk/13_GeexFinanceSource/Geexfinance $ gradle installDebug FAILURE: Build failed with an exception. * Where: Build file '/home/ninja/src/goshawk/13_GeexFinanceSource/Geexfinance/SlidingMenuLibrary/build.gradle' line: 9 * What went wrong: A problem occurred evaluating project ':SlidingMenuLibrary'. > Failed to apply plugin [id 'android-library'] 

Gradle 2.2版是必需的。 目前的版本是2.1。 如果使用gradle包装器,请尝试将/home/ninja/src/goshawk/13_GeexFinanceSource/Geexfinance/gradle/wrapper/gradle-wrapper.properties中的distributionUrl编辑为gradle-2.2-all.zip

 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 1 mins 5.884 secs 

我需要你的帮助,任何想法?

从gradle-wrapper文档:

 If you don't want any download to happen when your project is build via gradlew, simply add the Gradle distribution zip to your version control at the location specified by your wrapper configuration. A relative URL is supported - you can specify a distribution file relative to the location of gradle-wrapper.properties file. 

基本上,一旦你有二进制文件gradle-2.1-bin.zip和包装jar gradle-wrapper.jar你可以使用正确的gradle-wrapper.propertiesgradlew可执行文件将它移动到任何你喜欢的gradle-wrapper.properties

项目的文件夹结构将是:

 Project1 -> gradlew or gradlew.bat (wrapper executable) gradle -> wrapper -> gradle-2.1-bin.zip gradle-wrapper.jar gradle-wrapper.properties 

gradlew可执行文件在./gradle/wrapper/查找gradle-wrapper.jar

以下是gradle-wrapper.properties的示例

 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists # copy the distribution to the gradle/wrapper directory manually for the first run # that way the distribution doesn't need to be checked into version control distributionUrl=gradle-2.1-bin.zip 

Project1运行./gradlew时,它将提取到~/.gradle/wrapper/dists/gradle-2.1-bin/

只需将Project1/gradle*复制到Project2/即可重用包装器。

我有同样的错误,刚才我修好了! 在root build.gradle类型中

 task wrapper(type: Wrapper) { gradleVersion = '2.2' } 

此外,在“修复Gradle设置”对话框中修改Gradle设置也很有用。 或者您可以手动下载gradle-2.2-all.zip ,将其放在{project_dir}-gradle-wrapper并在终端中运行gradlew.bat