一、在AndroidManifest中添加(渠道 例如友盟)
<-有时候name和value需要在一行 有利于脚本读取!->
<meta-data
android:name="UMENG_APPKEY"
android:value="55024ae3fd98c51ec8000b28" >
</meta-data>
<meta-data
android:name="UMENG_CHANNEL"
android:value="${UMENG_CHANNEL_VALUE}" />
二、在build.gradle中配置渠道信息(主要项目中有两个build.gradle,当前项目下的,不是主目录下的)
apply plugin: 'com.android.application'
def releaseTime() {
return new Date().format("yyyy-MM-dd-HH-mm", TimeZone.getTimeZone("GMT+8"))
}
dependencies {
compile project(':DanmakuFlameMaster')
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
versionCode 4040
versionName "4.0.4"
// dex突破65535的限制
// multiDexEnabled true
// 默认是umeng的渠道 AndroidManifest.xml里面的UMENG_CHANNEL的value${UMENG_CHANNEL_VALUE}
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "umeng"]
}
//执行lint检查,有任何问题或者警告提示,都会终止构建,我们可以将其关掉
lintOptions {
abortOnError false
}
//签名
signingConfigs {
//debug签名时不需要任何配置呢
debug {
// No debug config
}
//发行版本需要配置
release {
//签名文件
storeFile file("D:/ApkWork/addlib1.0")
storePassword "..."
keyAlias "..."
keyPassword "..."
}
}
buildTypes {
debug {
// 显示Log
buildConfigField "boolean", "LOG_DEBUG", "true"
versionNameSuffix "-debug"
minifyEnabled false
zipAlignEnabled false
shrinkResources false
signingConfig signingConfigs.debug
}
release {
// 不显示Log
buildConfigField "boolean", "LOG_DEBUG", "false"
//混淆
minifyEnabled true
//zipalign优化
zipAlignEnabled true
// 移除无用的resource文件
shrinkResources true
//加载默认混淆配置文件
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//签名
signingConfig signingConfigs.release
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
// 输出apk名称为boohee_v1.0_2015-01-15_wandoujia.apk
def fileName = "boohee_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
}
//渠道Flavors,我这里写了一些常用的
productFlavors {
xiaomi {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
}
_360 {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "_360"]
}
baidu {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"]
}
wandoujia {
manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
}
}
productFlavors.all { flavor ->
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}