Android Studio import Project 的正確姿勢

 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





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章