編輯:關於Android編程
Android Studio之Gradle多渠道打包
由於國內Android市場眾多渠道,為了統計每個渠道的下載及其它數據統計,就需要我們針對每個渠道單獨打包,如果讓你打幾十個市場的包豈不煩死了,不過有了Gradle,這事就簡單了。
第二步 在 build.gradle 設置 ProductFlavors
android {
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]
}
}
}
或者批量修改
android {
productFlavors {
xiaomi {}
_360 {}
baidu {}
wandoujia {}
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}
很簡單,直接執行 ./gradlew assembleRelease , 然後就可以靜靜的等待打包完成。
最後來一份我在項目中使用的完整的gradle文件配置:
apply plugin: 'com.android.application'
def releaseTime() {
return new Date().format(yyyy-MM-dd, TimeZone.getTimeZone(UTC))
}
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId com.boohee.*
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName 1.0
// dex突破65535的限制
multiDexEnabled true
// 默認是umeng的渠道
manifestPlaceholders = [UMENG_CHANNEL_VALUE: umeng]
}
lintOptions {
abortOnError false
}
signingConfigs {
debug {
// No debug config
}
release {
storeFile file(../yourapp.keystore)
storePassword your password
keyAlias your alias
keyPassword your password
}
}
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
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)
}
}
}
}
}
// 友盟多渠道打包
productFlavors {
wandoujia {}
_360 {}
baidu {}
xiaomi {}
tencent {}
taobao {}
...
}
productFlavors.all { flavor ->
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.0.3'
compile 'com.jakewharton:butterknife:6.0.0'
...
}
Android Animation 動畫Demo
本文主要介紹Android中的Animation動畫。 Android提供了2中動畫:Tween動畫和Frame動畫。 本文中主要講解Tween動畫,下篇文章中會講到Fr
華為麥芒5和小米5哪個好 華為麥芒5和小米5對比評測
華為麥芒5和小米5哪個好?它們之間有什麼區別?下面小編將帶來華為麥芒5和小米5對比評測,大家一起來看看吧!華為麥芒5和小米5對比評測: 華為麥芒5介紹:
手機QQ語音轉化文字方法
QQ語音聊天時候,如果自己這邊不方便接聽怎麼辦,有一個辦法就是把語音給轉換成文字。首先下載最新版的手機QQ,我們以安卓為例。這個必須升級的,舊版本無法操作。
Android應用APP自動更新功能的代碼實現
由於Android項目開源所致,市面上出現了N多安卓軟件市場。為了讓我們開發的軟件有更多的用戶使用,我們需要向N多市場發布,軟件升級後,我們也必須到安卓市場上進行更新,給