有一种方法可以自动将库添加到每个新项目/模块。 Android Studio目录中有一个包含模板的文件夹。寻找:
..\Android Studio\plugins\android\lib\templates\gradle-projects\NewAndroidModule\root
在这个目录下有一个文件:
build.gradle.tfl
根据自己的需要进行修改。
例子:
dependencies {
<#if dependencyList?? >
<#list dependencyList as dependency>
compile '${dependency}'
</#list>
</#if>
compile fileTree(dir: 'libs', include: ['*.jar'])
<#if WearprojectName?has_content && NumberOfEnabledFormFactors?has_content && NumberOfEnabledFormFactors gt 1 && Wearincluded>
wearApp project(':${WearprojectName}')
compile 'com.google.android.gms:play-services:+'
</#if>
<#if unitTestsSupported>
testCompile 'junit:junit:${junitVersion}'
</#if>
compile 'com.github.bumptech.glide:glide:3.7.0'
}
正如你可以看到,滑翔库已经在末尾添加。
当此文件被修改时,每个新的Android Phone & Table module
都将包含此库。
当然,没有什么能够阻止您添加自己的模块或项目模板。
看一看Android Studio中的Live模板功能https://www.youtube.com/watch?v=4rI4tTd7-J8 – Luksprog
检查这个帖子http://stackoverflow.com/a/39116613/1770868 –
@ Luksprog,首先感谢您的阅读,这是一种重用代码的替代方式。 –