码迷,mamicode.com
首页 > 其他好文 > 详细

gradle 统一配置

时间:2016-04-18 13:28:27      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

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‘ 
  30. } 

在project build.gradle 中配置

  1. apply from:"config.gradle" 
  2. buildscript { 
  3. repositories { 
  4. jcenter() 
  5. } 
  6. dependencies { 
  7. classpath ‘com.android.tools.build:gradle:2.0.0‘ 
  8.  
  9. // NOTE: Do not place your application dependencies here; they belong 
  10. // in the individual module build.gradle files 
  11. } 
  12. } 

在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. } 
  14. buildTypes { 
  15. release { 
  16. minifyEnabled MINIFY_DISABLED 
  17. proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘ 
  18. } 
  19. } 
  20. } 
  21.  
  22. dependencies { 
  23. compile fileTree(dir: ‘libs‘, include: [‘*.jar‘]) 
  24. # 这边一定要使用双引号,而不能使用单引号 
  25. testCompile "junit:junit:${JUNIT_VERSION}" 
  26. compile "com.android.support:appcompat-v7:${APPCOMPAT_VERSION}" 
  27. compile "com.android.support:design:${APPCOMPAT_VERSION}" 
  28. } 

gradle 统一配置

标签:

原文地址:http://www.cnblogs.com/onespieces/p/5403799.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!