i have android studio project, file gradle/wrapper/gradle-wrapper.properties
configured following.
#wed apr 10 15:27:10 pdt 2013 distributionbase=gradle_user_home distributionpath=wrapper/dists zipstorebase=gradle_user_home zipstorepath=wrapper/dists distributionurl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
and have 2.2.1-all
version installed in home directory.
.gradle/wrapper/dists/gradle-2.2.1-all/c64ydeuardnfqctvr1gm30w53/gradle-2.2.1-all.zip
when invoke ./gradlew
command build project. should use gradle-2.2.1-all.zip
build.
but doesn't, download gradle same version instead. so, there 2 gradles version 2.2.1-all
. because internet connection slow, takes long.
.gradle/wrapper/dists/gradle-2.2.1-all/c64ydeuardnfqctvr1gm30w53/gradle-2.2.1-all.zip .gradle/wrapper/dists/gradle-2.2.1-all/6dibv5rcnnqlfbq9klf8imrndn/gradle-2.2.1-all.zip
it's annoying since has download new 1 same version time invoke command build project.
why gradle build system couldn't pick installed one?
the problem occurred because hash policy download url different between studio's gradle-wrapper.jar
, latest gradle-wrapper.jar
.
the gradle-wrapper.jar
under android app directory (i guess it's copied android-sdk-macosx/tools/templates/gradle/wrapper/gradle/wrapper/gradle-wrapper.jar
) use following method calculate hash download url.
// pathassembler.java private string getmd5hash(string string) { try { messagedigest e = messagedigest.getinstance("md5"); byte[] bytes = string.getbytes(); e.update(bytes); return (new biginteger(1, e.digest())).tostring(32); } catch (exception var4) { throw new runtimeexception("could not hash input string.", var4); } }
but latest gradle-wrapper.jar
use following method do. radix change 32
36
.
private string gethash(string string) { try { messagedigest messagedigest = messagedigest.getinstance("md5"); byte[] bytes = string.getbytes(); messagedigest.update(bytes); return new biginteger(1, messagedigest.digest()).tostring(36); } catch (exception e) { throw new runtimeexception("could not hash input string.", e); } }
the magic string found in directory name md5 hash string of download url.
for version 2.10, there directory name
.gradle/wrapper/dists/gradle-2.10-all/a4w5fzrkeut1ox71xslb49gst
and a4w5fzrkeut1ox71xslb49gst
hashed download url.
try { messagedigest messagedigest = messagedigest.getinstance("md5"); messagedigest.update("https://services.gradle.org/distributions/gradle-2.10-all.zip".getbytes()); system.out.println(new biginteger(1, messagedigest.digest()).tostring(36)); } catch (nosuchalgorithmexception e) { e.printstacktrace(); }
by using same hash method (use same gradle-wrapper.jar
) same download url gradle/wrapper/gradle-wrapper.properties
, there won't multiple downloads same version of gradle.
this issue exist between android studio project , other gradle project.
Comments
Post a Comment