修改Android Studio默认的gradle配置文件

每次用Android Studio 新建项目时,默认的依赖库都是google()、jcenter(),在国内速度非常慢,有时候慢得不能忍受。多次百度、谷歌后,终于找到一个办法,贴出来和大家共享:

1.找到Android Studio的安装目录下的 build.gradle.ftl 文件 我的是这个:C:\Program Files\Android\Android Studio\plugins\android\lib\templates\gradle-projects\NewAndroidProject\root\build.gradle.ftl

2.修改文件中的仓库地址,把aliyun的仓库放在第1位,记得要修改2处:

repositories {
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        google()
        jcenter()
}
复制代码
allprojects {
    repositories {
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        google()
        jcenter()
    }
}
复制代码

修改后的文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
<#macro loadProperties>
<#if useOfflineRepo!false>
    Properties properties = new Properties()
    properties.load(project.rootProject.file("local.properties").newDataInputStream())
</#if>
</#macro>
<#macro useProperties>
<#if useOfflineRepo!false>
        properties.getProperty("offline.repo").split(",").each { repo ->
            maven { url repo }
        }
</#if>
</#macro>

buildscript {<#if includeKotlinSupport!false>
    ext.kotlin_version = '${kotlinVersion}'</#if>
    <@loadProperties/>
    repositories {
        <@useProperties/>
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        google()
        jcenter()
        <#if includeKotlinEapRepo!false>maven { url '${kotlinEapRepoUrl}' }</#if>
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:${gradlePluginVersion}'
        <#if includeKotlinSupport!false>classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"</#if>
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    <@loadProperties/>
    repositories {
        <@useProperties/>
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        google()
        jcenter()
        <#if includeKotlinEapRepo!false>maven { url '${kotlinEapRepoUrl}' }</#if>
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

复制代码

3.保存后,重新启动Android Studio

这时新建项目后就默认从Aliyun上下载依赖,新测速度非常快,很节约每次新建项目的时间。

转载于:https://juejin.im/post/5cbaa9f8518825401f79ad97

  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值