Shortly afterwards, I noticed that each time I tried to create a new project, it ended with the following error message:
Cause: error in opening zip file. Consult IDE log for more details (Help | Show Log)
Hmmmm.. which error file exactly and what's wrong with it?
Let's open the log file - Help > Show Log in Explorer > idea.log or %USERPROFILE%\.AndroidStudioPreview\system\log\idea.log
Latest logs show the following messages:
INFO - ject.ProjectImportErrorHandler - Failed to import Gradle project at 'C:\Users\user\AndroidStudioProjects\MyApplicationProject2'
org.gradle.tooling.GradleConnectionException: Could not install Gradle distribution from 'http://services.gradle.org/distributions/gradle-1.8-bin.zip'.
WARN - nal.AbstractExternalSystemTask - Cause: error in opening zip file
com.intellij.openapi.externalSystem.model.ExternalSystemException: Cause: error in opening zip file
WARN - .project.GradleProjectImporter - com.intellij.openapi.externalSystem.model.ExternalSystemException: Cause: error in opening zip file
INFO - .project.GradleProjectImporter - Cause: error in opening zip file
Clearly something is wrong with Gradle plugin. Android Studio generally downloads Gradle archive in background and stores it under %USERPROFILE%\.gradle\wrapper\dists\gradle-1.x-bin\hash-code\gradle-1.x-bin.zip. While the archive usually weighs about 30 megabytes, my gradle-1.8-bin.zip archive was a 50 kb file.
I opened the file in text editor and found that it contained the html of my proxy server's error page. It seems that Android Studio issues a get command to download the Gradle archive, and without checking the received MIME type, just blindly writes the stream to the gradle-1.x-bin.zip file. Later on, the module that responsible for new project creation tries to extract the Gradle plugin and obviously fails.
To fix that issue you have two options:
- [Workaround] Manually download the appropriate zip file, replace the existing archive and restart Android Studio.
- Delete the existing archive and fix your proxy settings.
To fix your proxy settings, go to File > Settings. Click the HTTP Proxy option on the left pane.
Select the Use Proxy radio button, and enter your proxy server's Host name and Port number.
Initially I didn't checked the Proxy authentication and left Login and Password fields blank. I restarted the Android Studio and received another error message (at least this time much more informative):
Could not GET 'http://repo1.maven.org/maven2/com/android/tools/build/gradle/'. Received status code 401 from server: Unauthorized
Consult IDE log for more details (Help | Show Log)