簡體   English   中英

如何重用gradle-wrapper?

[英]How to reuse 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可執行文件將其移動到任何地方。

項目的文件夾結構將是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM