Solution to the slow import of Android studio projects

preface

As we all know, Android studio has been updated to 2.0 preview 6. As a development tool highly praised by Google, it has incomparable advantages over eclipse ADT. However, in practical use, there are still many unpleasant places. Android studio natively supports the use of gradle to build projects. It is a good idea to use the dynamic language groovy to define the project construction process and avoid building XML file. However, the binary package of gradle is large, and users may have different versions of gradle, so various problems may occur during construction. Therefore, the gradle wrapper is proposed to solve the previous problems. The gradle wrapper is bound to a specified gradle version. When the user imports the project, the gradle package will be automatically downloaded from the remote server. This solves the problem of inconsistent client versions, but it also brings a new problem: the speed of connecting to the remote server to download the gradle package in China is very slow! Therefore, whenever a new project is imported into Android studio, it will be stuck in this interface:

You don't know whether the as is dead or what it really does in the background... Either be patient or turn off the as directly, and it must be forced to turn off. This is very unfriendly. In fact, the reason why it is stuck here is because the gradle package is downloaded from the server in the background. The gradle package often has tens of megabytes. In the case of poor network environment, it may take a long time to complete. Obviously, we don't have so much time to spend here. We need to find a way to solve it.

The solution has been searched on the network. The usual way is to modify the gradle version in the gradle wrapper configuration file, but it is not complete. Finally, we see the solution of the complete point here. The following steps are mainly Simplified:

1. First obtain the relevant parameters of the machine, including the following (the parameters of my machine are in parentheses):

Android Plugin Version:(1.5.0)

Gradle Version:(2.8)

Compile SDK Version:(23)

Build Tools Version:(23.0.2)

GradleHome:(/Applications/Android Studio.app/Contents/gradle/gradle-2.8)

The acquisition method is very simple. Create a new project in Android studio, right-click the project name and select "open module settings". You can see the following in the pop-up dialog box:

2. When the parameters are ready, you can start to modify the parameters of the target project. Which files are the parameters to be modified in?

xxx-project/. idea/gradle. XML file: add or modify < option name = "gradlehome" value = "previous gradlehome parameter" / >

xxx-project/gradle/wrapper/gradle-wrapper. Properties file: distributionurl = HTTPS \: / / services gradle. Org / distributions / gradle - gradversion all zip

xxx-project/build. Gradle file: classpath 'com android. tools. Build: gradle: Android plugin version '(this is the configuration of the whole project)

xxx-project/build. Gradle file: modify the compile SDK version and build tools version parameters. (this is the configuration of a single module, and each module in the project needs to be modified)

3. After parameter modification, start to formally import the project. Generally, it can be imported into Android studio smoothly at this time. If you are still stuck in the import interface, you can only wait

summary

The above is the whole content of this article. I hope it will help you when you use Android studio. If you have any questions, you can leave a message.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>