gradle 统一配置
Android
当项目中要使用或者导入比较多的module的时候,为每一个module管理一些插件版本是很重复的一件事情
所以需要寻找一种能够对重复配置进行统一管理的方法
在project 根目录,新建 config.gradle文件
在这里配置你需要统一管理的元素
- # ext 是必须的,且只能用这个名字
- ext {
- // Version of compile sdk
- COMPILE_SDK_VERSION = 23
-
- // Version of Android build tool
- BUILD_TOOLS_VERSION = "23.0.3"
-
- // Min version of Android sdk
- MIN_SDK_VERSION = 9
-
- // Version of target Android sdk
- TARGET_SDK_VERSION = 23
-
- // Default version code and version name.
- DEFAULT_VERSION_CODE = 1
- DEFAULT_VERSION_NAME = ‘1.0.0‘
-
- // Use progurad or not
- MINIFY_ENABLED = true
- MINIFY_DISABLED = false
-
- // Version of "com.android.support:appcompat-v7", refer it as folow:
- // compile "com.android.support:appcompat-v7:${APPCOMPAT_VERSION}"
- APPCOMPAT_VERSION = ‘23.2.0‘
-
- // Version of "junit", refer it as folow:
- // compile "junit:junit:${JUNIT_VERSION}"
- JUNIT_VERSION = ‘4.12‘
- }
在project build.gradle 中配置
- apply from:"config.gradle"
- buildscript {
- repositories {
- jcenter()
- }
- dependencies {
- classpath ‘com.android.tools.build:gradle:2.0.0‘
-
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
- }
在module build.gradle 中使用
- apply plugin: ‘com.android.application‘
-
- android {
- compileSdkVersion COMPILE_SDK_VERSION
- buildToolsVersion BUILD_TOOLS_VERSION
-
- defaultConfig {
- applicationId "cn.m4399.x2223.devicedemo"
- minSdkVersion MIN_SDK_VERSION
- targetSdkVersion TARGET_SDK_VERSION
- versionCode DEFAULT_VERSION_CODE
- versionName DEFAULT_VERSION_NAME
- }
- buildTypes {
- release {
- minifyEnabled MINIFY_DISABLED
- proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘
- }
- }
- }
-
- dependencies {
- compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])
- # 这边一定要使用双引号,而不能使用单引号
- testCompile "junit:junit:${JUNIT_VERSION}"
- compile "com.android.support:appcompat-v7:${APPCOMPAT_VERSION}"
- compile "com.android.support:design:${APPCOMPAT_VERSION}"
- }
时间: 2024-10-13 19:27:43