gradle 统一配置

gradle 统一配置

当项目中要使用或者导入比较多的module的时候,为每一个module管理一些插件版本是很重复的一件事情
所以需要寻找一种能够对重复配置进行统一管理的方法

在project 根目录,新建 config.gradle文件

在这里配置你需要统一管理的元素

  1. # ext 是必须的,且只能用这个名字 
  2. ext { 
  3. // Version of compile sdk 
  4. COMPILE_SDK_VERSION = 23 
  5.  
  6. // Version of Android build tool 
  7. BUILD_TOOLS_VERSION = "23.0.3" 
  8.  
  9. // Min version of Android sdk 
  10. MIN_SDK_VERSION = 9 
  11.  
  12. // Version of target Android sdk 
  13. TARGET_SDK_VERSION = 23 
  14.  
  15. // Default version code and version name. 
  16. DEFAULT_VERSION_CODE = 1 
  17. DEFAULT_VERSION_NAME = '1.0.0' 
  18.  
  19. // Use progurad or not 
  20. MINIFY_ENABLED = true 
  21. MINIFY_DISABLED = false 
  22.  
  23. // Version of "com.android.support:appcompat-v7", refer it as folow: 
  24. // compile "com.android.support:appcompat-v7:${APPCOMPAT_VERSION}" 
  25. APPCOMPAT_VERSION = '23.2.0' 
  26.  
  27. // Version of "junit", refer it as folow: 
  28. // compile "junit:junit:${JUNIT_VERSION}" 
  29. JUNIT_VERSION = '4.12' 

在project build.gradle 中配置

  1. apply from:"config.gradle" 
  2. buildscript
  3. repositories
  4. jcenter() 

  5. dependencies
  6. classpath 'com.android.tools.build:gradle:2.0.0' 
  7.  
  8. // NOTE: Do not place your application dependencies here; they belong 
  9. // in the individual module build.gradle files 


在module build.gradle 中使用

  1. apply plugin: 'com.android.application' 
  2.  
  3. android { 
  4. compileSdkVersion COMPILE_SDK_VERSION 
  5. buildToolsVersion BUILD_TOOLS_VERSION 
  6.  
  7. defaultConfig { 
  8. applicationId "cn.m4399.x2223.devicedemo" 
  9. minSdkVersion MIN_SDK_VERSION 
  10. targetSdkVersion TARGET_SDK_VERSION 
  11. versionCode DEFAULT_VERSION_CODE 
  12. versionName DEFAULT_VERSION_NAME 

  13. buildTypes { 
  14. release { 
  15. minifyEnabled MINIFY_DISABLED 
  16. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 



  17.  
  18. dependencies
  19. compile fileTree(dir: 'libs', include: ['*.jar']) 
  20. # 这边一定要使用双引号,而不能使用单引号 
  21. testCompile "junit:junit:${JUNIT_VERSION}" 
  22. compile "com.android.support:appcompat-v7:${APPCOMPAT_VERSION}" 
  23. compile "com.android.support:design:${APPCOMPAT_VERSION}" 

转载于:https://www.cnblogs.com/onespieces/p/5403799.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值