Gradle相关博文:
1. Groovy脚本基础全攻略:http://blog.youkuaiyun.com/yanbober/article/details/49047515
2. Gradle脚本基础全攻略:http://blog.youkuaiyun.com/yanbober/article/details/49314255
Module的gradle配置文件
// 声明是Android程序
apply plugin: 'com.android.application'
//预定义
def buildTime() {
def date = new Date()
def formattedDate = date.format('yyyyMMdd')
return formattedDate
}
def TYPE_STRING = "String"
def CONFIG_FILE = "CONFIG_FILE"
def SDK_FILE = "SDK_FILE"
def LOCALE = "LOCALE"
android {
// 编译SDK的版本
compileSdkVersion 21// build tools的版本
buildToolsVersion "21.1.1"
defaultConfig {
// 应用的包名
applicationId "me.storm.ninegag"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0.0"
}
// java版本
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
signingConfigs {
//签名信息
debug {
storeFile file("../android/debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
dexOptions {
//解决导入包过多产生的函数过多编译不通过问题
javaMaxHeapSize "1g"
}
packagingOptions { // 打包配置
exclude 'META-INF/LICENSE' // 排除一些文件
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
buildTypes {
debug{
debuggable false //调试信息是否开启调试模式
// 是否进行混淆
minifyEnabled false
signingConfig signingConfigs.debug //签名文件debug
}
release {
debuggable false //调试信息是否开启调试模式
// 是否进行混淆
minifyEnabled false// 混淆文件的位置
zipAlignEnabled true //是否zip对齐
shrinkResources true // 移除无用的resource文件
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
resValue("string", "website_host_name", "${production_website_host_name}") //R.String.website_host_name
//给生成的apk重新命名
applicationVariants.all {
variant ->
variant.outputs.each { output ->
if (output.outputFile != null && output.outputFile.name.endsWith('.apk')
&& 'release'.equals(variant.buildType.name)) {
def apkFile = new File(
output.outputFile.getParent(),
"mtp_v${variant.versionName}_${buildTime()}_${variant.productFlavors[0].name}.apk")
output.outputFile = apkFile
}
}
} }
}
//多渠道打包
productFlavors {
focusteach{}
productFlavors.all { flavor ->
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}
//jni目录
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
// 移除lint检查的error
lintOptions {
abortOnError false
}
}
dependencies {
// 编译libs目录下的所有jar包
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.0.2'
compile 'com.etsy.android.grid:library:1.0.5'
compile 'com.alexvasilkov:foldable-layout:1.0.1'// 编译extras目录下的ShimmerAndroid模块
compile project(':extras:ShimmerAndroid')
// 仅在debug包启用leakcanary进行内存监控和提示
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
alphaCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'} //发布版用空包编译