The problem arose because the hash policy for the download URL is different from gradle-wrapper.jar and the latest gradle-wrapper.jar .
gradle-wrapper.jar in my Android application directory (I assume it is copied from android-sdk-macosx/tools/templates/gradle/wrapper/gradle/wrapper/gradle-wrapper.jar ) uses the following method to calculate the hash for the URL download addresses.
// 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 the last gradle-wrapper.jar uses the following method. The radius varies from 32 to 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 line I found in the directory name is the md5 hash line of the download URL.
For version 2.10 there is a directory name
.gradle/wrapper/dists/gradle-2.10-all/a4w5fzrkeut1ox71xslb49gst
And a4w5fzrkeut1ox71xslb49gst hashed from the 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(); }
Using the same hash method (use the same gradle-wrapper.jar ) for the same download gradle/wrapper/gradle-wrapper.properties from gradle/wrapper/gradle-wrapper.properties , there will not be multiple downloads for the same version of gradle.
This problem exists only between android studio project and another gradle project.