Problem description

When compiling new projects on a daily basis, colleagues like me who are new or have no Android experience will encounter many times:

The local development environment has been set up, the project is not running down, automatically pull the brake, capital meng force! And an innocent “I didn’t move anything.”

Such as the following error (thanks wang for sponsoring this picture) :

The plot after

(If you are not interested in the plot, skip to the summary.)

Build. Gradle file in /app directory to “buildToolsVersion “25.0.0” and then click “OK” or sync Now. Sorry, wang uses VSCode.

Run gradlew. Bat in the Command line window of Windows (you can directly enter CMD in the address bar of file Explorer). Run gradlew clean to clean the file. Clean up unexpected interruptions, huh? The Plugin version is too old. Well, go and modify build.gradle in the root directory of your project.

classpath 'com. Android. Tools. Build: gradle: 2.2.3'
Copy the code

Why 2.2.3? After checking, Wang Ge did not open VPN. Gradle.properties is the root directory of your project.

systemProp.http.proxyHost=registry.npm.taobao.org
systemProp.http.proxyPort=80
Copy the code

C:\Users\{username}\. Gradle \wrapper\dists: C:\Users\{username}\.

Version matching relationship between Gradle, Android Plugin, and Build Tools

  • Gradle Version
  • gradlew-wapper.propertiesIn the filedistributionUrlThe version pointed to.
  • There are alsodistributionBase=GRADLE_USER_HOMEanddistributionPath=wrapper/dists, the configurationdistributionUrlaftergradleWill go to the localdistributionBaseUnder thedistributionBase(In generalC:\Users\{user name}\.gradle\wrapper\dists) find the file corresponding to the target version, if there is a direct load to use, not to godistributionUrlIf you don’t have a VPN, you are advised to set up a proxy. How to set up the proxy has been mentioned above.
  • Android Plugin

Build. gradle com.android.tools.build:

classpath 'com. Android. Tools. Build: gradle: 2.2.3'
Copy the code
  • Build Tools

BuildToolsVersion of build.gradle file in /app directory.

No, it’s like you need science to get in here. All right, just use a certain degree of search to find this blog post.

summary

In Android development, Gradle tools can help us develop efficiently. However, the download of gradle tool kits often causes long waits. Therefore, you need to make full use of local resources to avoid the download of Gradle tool kits.Copy the code
    1. Look at the localC:\Users\{user name}\.gradle\wrapper\distsTo learn which gradle tools are available locally.
    1. With reference toThis tableAnd adjust thePlugin versionwithGradle version. (includingPlugin versionIn the “bulid.gradle” file corresponding to the projectclasspath.Gradle versionIn “gradle-wrapper.properties” filedistributionUrl)

    1. If you do not have a gradle version available locally, you can download VPN directly, set up proxy directly, or go to the Internet to download gradle.