import Project 网络下载的项目经常卡住,常见原因有三个:
1、Project自带的gradle与AS当前使用的gradle版本不一致
2、Project生成的AS与本机AS版本差别大
3、Project所引用的第三方库下载不下来
一、针对问题1,修改Project使用本机的gradle版本:
1-1、build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules. //apply from: 'config/config.gradle' apply from: rootProject.file('dependencies.gradle') buildscript { repositories { jcenter() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' // classpath 'com.android.tools.build:gradle:2.4.0-alpha3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' // Lambda表达式 classpath 'me.tatarka:gradle-retrolambda:3.5.0'//retrolambda //热修复tinker--------------- classpath ('com.tencent.tinker:tinker-patch-gradle-plugin:1.9.2') //热修复tinker--------------- // classpath 'com.mcxiaoke.gradle:packer-ng:1.0.7' } } allprojects { } task clean(type: Delete) { delete rootProject.buildDir }
1-2、gradle-wrapper.properties
#Tue Nov 07 09:09:35 CST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
二、针对第二个问题,AS每次升级导致的差异不一,需要区别对待。比如从2到3的build如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules. //apply from: 'config/config.gradle' apply from: rootProject.file('dependencies.gradle') buildscript { } allprojects { repositories { maven { url "https://jitpack.io" } google() jcenter() mavenCentral() maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } maven { url "http://mvn.gt.igexin.com/nexus/content/repositories/releases/" } // maven { url '/Users/Felix/Library/Android/sdk/extras/android/m2repository' } flatDir{ dirs 'libs' } maven{ url 'https://dl.bintray.com/tinker/maven'} } } task clean(type: Delete) { delete rootProject.buildDir }
处理完以上两步,就可以愉快滴打开AS来import Project了,一般情况下能够进入到AS工作区。如果10min还是进不去,可能就是问题3了,需要继续第三部处理。
三、问题3一般需要网络fanqiang才得行,打开gradle.properties设置网络代理,然后再打开AS来import Project
# Project-wide Gradle settings. # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-Xmx4608M #org.gradle.jvmargs=-Xmx4608M -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true systemProp.http.proxyPort=1234 systemProp.http.proxyUser=xxxx systemProp.http.proxyPassword=xxxx systemProp.https.proxyPassword=xxxx systemProp.https.proxyHost=111.111.111.111 systemProp.http.proxyHost=11.111.11.11 systemProp.https.proxyPort=1111 systemProp.https.proxyUser=xxxx