由于項(xiàng)目需求需要在手機(jī)上安裝不同服務(wù)器環(huán)境的APP岂贩,所以想到通過改變applicationIdSuffix后綴徒蟆,因?yàn)橛玫搅烁叩碌貓D所以同時(shí)申請(qǐng)了兩個(gè)key
源碼如下:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def APPLICATION_ID = "***.******.**";
android {
signingConfigs {
config {
keyAlias '******'
keyPassword '******'
storeFile file('**.jks')
storePassword '1******'
v2SigningEnabled false
}
config_test {
keyAlias '******_test'
keyPassword '******'
storeFile file('**_test.jks')
storePassword '******'
v2SigningEnabled false
}
}
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId APPLICATION_ID
minSdkVersion 19
targetSdkVersion 26
versionCode 7
versionName "1.3.0"
ndk {
// 設(shè)置支持的SO庫架構(gòu)
abiFilters 'armeabi', 'arm64-v8a', "x86"
}
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
checkReleaseBuilds false
abortOnError false
ignoreWarnings true
}
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
packagingOptions {
exclude 'META-INF/*'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
resValue "string", "API_SERVER", "https://ebike.uma.com/"
manifestPlaceholders = [APP_NAME: "******", AMAP_APPKEY: "*************************"]
}
debug {
signingConfig signingConfigs.config_test
applicationIdSuffix "test"
resValue "string", "API_SERVER", "https://xaas-test.uma.com/"
manifestPlaceholders = [APP_NAME: "******_dev", AMAP_APPKEY: "*************************"]
}
}
//配置不同渠道
productFlavors {
main {
}
}
//打包輸出
applicationVariants.all { variant ->
def fileName
def buildName
variant.outputs.each { output ->
def outputFile = output.outputFile
variant.productFlavors.each { product ->
buildName = product.name //獲取渠道名字
}
if (outputFile != null && outputFile.name.endsWith('.apk')) {
fileName = "******_V${defaultConfig.versionName}" + buildName + "_" + variant.buildType.name + "_" + createDate() + ".apk"
output.packageApplication.outputFile = new File("apk" + '/', fileName)
}
}
}
}
def createDate() {
return new Date().format("MMdd_HH", TimeZone.getTimeZone("GMT+8"))
}