Android Studio 自定义修改新建项目时的build.gradle模板,添加国内镜像源

这一生的挚爱 提交于 2020-03-18 11:31:36

某厂面试归来,发现自己落伍了!>>>

找下面路径的文件

D:\AndroidStudio\plugins\android\lib\templates\gradle-projects\NewAndroidProject\root\build.gradle.ftl

注意这里是以我本机安装的AndroidStudio为例,你需要将安装路径换成你本机的路径,另外我的系统是win10,Android Studio版本为3.5.2

修改如下:

// 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 'https://plugins.gradle.org/m2/' }
	maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
	maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
	maven { url 'http://maven.aliyun.com/nexus/content/repositories/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 'https://plugins.gradle.org/m2/' }
	maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
	maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
	maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'} 
        <#if includeKotlinEapRepo!false>maven { url '${kotlinEapRepoUrl}' }</#if>
    }
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!