Gradle緩存目錄文件命名規則
在打開Android Studio項目的時候,會下載項目對應版本的gradle,該版本是在項目根目錄下\gradle\wrapper\gradle-wrapper.properties文件中指定的:
下載的gradle文件在Windows電腦上會緩存在C:\Users\xxx(用戶名)\.gradle\wrapper\dists\gradle-3.3-all\55gk2rcmfc6p2dg9u9ohc3hw9目錄下
那這個目錄名55gk2rcmfc6p2dg9u9ohc3hw9是根據什麽規則生成的呢?看似沒有規律,研究了一下,發現也是按照一定規則生成的,如下:
1.從gradle/wrapper/gradle-wrapper.properties中得到distributionUrl,即https://services.gradle.org/distributions/gradle-3.3-all.zip,註意文件中的\不算
2.對distributionUrl進行MD5運算
3.根據MD5值構造一個uint 128位整數
4.將整數利用base36得到base36的值(取小寫)
java代碼如下:
public static String getFileName(String distributionUrl) { MessageDigest messageDigest = null; try { messageDigest = MessageDigest.getInstance("MD5"); messageDigest.update(distributionUrl.getBytes()); String str= new BigInteger(1, messageDigest.digest()).toString(36); return str; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; }
distributionUrl |
base36 |
https://services.gradle.org/distributions/gradle-3.3-all.zip |
55gk2rcmfc6p2dg9u9ohc3hw9 |
https://services.gradle.org/distributions/gradle-3.2-all.zip |
97ld1dyml0oep92x4lyn4g235 |
https://services.gradle.org/distributions/gradle-3.1-all.zip |
ejgglywf033yp6s4x8ahmgm74 |
https://services.gradle.org/distributions/gradle-3.0-all.zip |
6v8c6qg2jpi8twyfv2a5s9mii |
https://services.gradle.org/distributions/gradle-2.14.1-all.zip |
8bnwg5hd3w55iofp58khbp6yv |
https://services.gradle.org/distributions/gradle-2.14-all.zip |
t7wfomcrmv8dmyii9c9waem8 |
https://services.gradle.org/distributions/gradle-2.13-all.zip |
1b9wlm73elu4cqnbc0rk7r7qn |
https://services.gradle.org/distributions/gradle-2.12-all.zip |
8ywkdai6puj5z81fume4e7njw |
https://services.gradle.org/distributions/gradle-2.11-all.zip |
ace7yl0a7udokebb27mt9s3qr |
https://services.gradle.org/distributions/gradle-2.10-all.zip |
a4w5fzrkeut1ox71xslb49gst
|
Gradle緩存目錄文件命名規則