// 目标版本
TARGET_SDK_VERSION = 23
// 设置是否使用混淆
MINIFY_ENABLED = true
MINIFY_DISABLED = false
// 应用程序包名
APPLICATION_ID = ‘com.mainiway.eworkpal’
// Version of “com.android.support:appcompat-v7”, refer it as folow:
// compile “com.android.support:appcompat-v7:${APPCOMPAT_VERSION}”
APPCOMPAT_VERSION = ‘23.2.1’
}
**4.**在app目录下的build.gradle中使用
dependencies {
compile fileTree(include: [‘*.jar’], dir: ‘libs’)
compile “com.android.support:cardview-v7:${APPCOMPAT_VERSION}”
compile “com.android.support:appcompat-v7:${APPCOMPAT_VERSION}”
compile “com.android.support:design:${APPCOMPAT_VERSION}”
compile ‘com.github.bumptech.glide:glide:3.7.0’
}
方式二(推荐)
**1.**在根目录下的build.gradle文件下添加 ext{ … } 中的内容
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath ‘com.android.tools.build:gradle:2.2.3’
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url “https://jitpack.io” }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
// Define versions in a single place
ext {
// SDK And Tools
minSdkVersion = 14
targetSdkVersion = 23
compileSdkVersion = 23
buildToolsVersion = ‘24.0.2’
//Dependencies
supportLibraryVersion = ‘23.2.1’
}
**2.**在app目录下build.gradle中使用 $rootProject.supportLibraryVersion
apply plugin: ‘com.android.application’
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId ‘com.mainiway.demo’
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName “1.0.0”
}
}
dependencies {
compile fileTree(include: [‘*.jar’], dir: ‘libs’)
compile “com.android.support:cardview-v7:$rootProject.supportLibraryVersion”
compile “com.android.support:appcompat-v7:$rootProject.supportLibraryVersion”
compile “com.android.support:design:$rootProject.supportLibraryVersion”
}
方式三(推荐)
也可以在根目录下的 build.gradle 文件中声明 ext{ … } 时, 加上一个变量 var ,如:
ext {
var = [
// SDK And Tools
minSdkVersion : 14,
targetSdkVersion : 25,
compileSdkVersion : 25,
buildToolsVersion : “25.0.2”,
versionName : “1.0.0”,
//Dependencies
supportLibraryVersion: “25.2.0”
]
}
对应的引用方式:
android {
compileSdkVersion var.compileSdkVersion
buildToolsVersion var.buildToolsVersion
defaultConfig {
applicationId “com.xxx.xxx”
minSdkVersion var.minSdkVersion
targetSd
kVersion var.targetSdkVersion
versionCode 1
versionName var.version
}
…
}
dependencies {
compile “com.android.support:appcompat-v7:$var.supportLibraryVersion”
compile “com.android.support:recyclerview-v7:$var.supportLibraryVersion”
compile “com.android.support:cardview-v7:$var.supportLibraryVersion”
}
或者像这样:
ext {
minSdkVersion: 14,
targetSdkVersion: 25,
compileSdkVersion: 25,
buildToolsVersion: “25.0.2”,
versionName: “1.0.0”,
//Dependencies
supportLibraryVersion: “25.2.0”