In the process of integrating wechat functions, I encountered the following problems when opening WeChatOpenSdkSample:

ERROR: Failed to open zip file.
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
Copy the code

Gradle: Gradle: gradle: Gradle: Gradle: Gradle: Gradle: Gradle: Gradle: Gradle: Gradle: Gradle: Gradle

If you’ve ever been cheated by Gradle, you will know that many of the errors reported by Gradle are not related to real errors.

Delete gradle cached files and download again

Error:Failed to open zip file. Gradle’s dependency cache may be corrupt, The solution was to delete all the files in the ~/.gradle/wrapper/dists directory and then reopen the IDE, at which point the IDE would re-download the Gradle dependencies.

After trying this method, it doesn’t work for me, which means that my local Gradle cache is correct and the root of the problem lies somewhere else.

Compare gradle configurations

Since there is no way, we have to play a big trick, find a normal project to compare with the error project. Gradle /wrapper/gradle-wrapper.properties: gradle/wrapper/gradle-wrapper.properties: gradle/wrapper/gradle-wrapper.properties: gradle/wrapper/gradle-wrapper.properties: gradle/wrapper/gradle-wrapper.properties:

Error items reported:

#Wed Apr 12 10:05:56 CST 2017distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME ZipStorePath = wrapper/dists distributionUrl=http://android.oa.com/gradle/gradle-4.7-all.zipCopy the code

The right project:

#Thu Oct 17 10:01:43 CST 2019distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME ZipStorePath = wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zipCopy the code

After comparison, we find that the distributionUrl is inconsistent and the error project is not configured with the path provided by the AS project. Therefore, we change the path to a consistent one and keep the original version number 4.7. The result is as follows:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
Copy the code

The project is then synchronized and found to be successful. Note that distributionUrl is used to download gradle compressed packages, which can be changed to a proxy address or local cache file address. The error indicates that the distributionUrl of the project has clearly been modified to be their own proxy, which is why I failed to synchronize.

reference

Error:Failed to open zip file. Gradle’s dependency cache may be corrupt