Android Studio在新建项目时会根据模板生成初始文件,我们可以修改文件模板。
项目模板
模板所在目录:Android Studio\plugins\android\lib\templates
下面我将修改两个文件,分别是build.gradle.ftl和project_ignore。
build.gradle.ftl
模板所在目录:templates\gradle-projects\NewAndroidProject\root
对应build.gradle(Project)文件,利用阿里云镜像解决build速度慢的问题。
模板如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
<#if includeKotlinSupport!false>ext.kotlin_version = '${kotlinVersion}'</#if>
repositories {
<#-- google()
jcenter() -->
// maven库
def cn = "http://maven.aliyun.com/nexus/content/groups/public/"
def abroad = "http://central.maven.org/maven2/"
// 先从url中下载jar若没有找到,则在artifactUrls中寻找
maven {
url cn
artifactUrls abroad
}
maven { url "http://maven.aliyun.com/nexus/content/repositories/jcenter"}
google()
}
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 {
repositories {
<#-- google()
jcenter() -->
// maven库
def cn = "http://maven.aliyun.com/nexus/content/groups/public/"
def abroad = "http://central.maven.org/maven2/"
// 先从url中下载jar若没有找到,则在artifactUrls中寻找
maven {
url cn
artifactUrls abroad
}
maven { url "http://maven.aliyun.com/nexus/content/repositories/jcenter"}
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
project_ignore
文件目录:templates\gradle-projects\NewAndroidProject\root
对应.gitignore文件,表示Git版本管理忽略提交规则。
模板如下:
#built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
# Windows thumbnail db
Thumbs.db
# OSX files
.DS_Store
# Android Studio
*.iml
.idea
#.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
.gradle
build/
.navigation
captures/
output.json
#NDK
obj/
.externalNativeBuild