欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android Studio import Project 的正确姿势

程序员文章站 2023-01-06 09:38:11
import project 网络下载的项目经常卡住,常见原因有三个: 1、project自带的gradle与as当前使用的gradle版本不一致 2、project生成的as与本机as版本差别大...

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 inpidual 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 "https://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一般需要网络*才得行,打开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
# https://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
# https://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