文章评分
次,平均分 :
由于Android studio和Android相关SDK和构建工具具有极快的更新速度。对相关版本的修改有时候是一件比较敏感的事情,尤其是在团队项目中,个人在本地修改了相关工具的版本并且不小心提交到远程代码库,别人更新下来往往出现各种问题。Android studio项目文件中版本字段十分分散,当SDK环境出现改变时,修改起来还是比较麻烦的。本文章利用配置文件对构建工具版本集中控制。
在项目根目录下gradle.properties文件定义版本信息并赋值
1 2 3 4 5 |
GradleBuildVersion=2.1.2 AndroidMinSDKVersion=16 AndroidTargetVersion=23 AndroidCompileSDKVersion=23 AndroidBuildToolsVersion=23.0.1 |
在使用版本信息的地方引用gradle变量
Dependencies
1 2 3 4 5 |
dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:'+project.AndroidBuildToolsVersion } |
build.gradle(project)
1 2 3 4 5 6 7 8 9 10 |
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:'+project.GradleBuildVersion // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } |
build.gradle(module)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Android { compileSdkVersion Integer.parseInt(project.AndroidCompileSDKVersion) buildToolsVersion project.AndroidBuildToolsVersion defaultConfig { applicationId "cn.wangbaiyuan.plugintest" minSdkVersion Integer.parseInt(project.AndroidMinSDKVersion) targetSdkVersion Integer.parseInt(project.AndroidTargetVersion) versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } |

关注我的微信,获取文章更新
如果你觉得这篇文章对你有用,可以点击下面的“赞助作者”打赏作者!
转载注明原文出处:王柏元的博客>>https://wangbaiyuan.cn/gradle-using-configuration-files-build-tools-version-under-centralized-control.html
暂无评论