一般签名都是放在buildTypes里面:
...
android {...defaultConfig {...}signingConfigs {release {storeFile file("myreleasekey.keystore")storePassword "password"keyAlias "MyReleaseKey"keyPassword "password"}}buildTypes {release {...signingConfig signingConfigs.release}}
}
但是多渠道时,使用配置的优先级从高到低分别是buildTypes、productFlavor、defaultConfig,如果按上面配置的话,根本修改不了签名。所以修改成以下:
android {...signingConfigs {release {storeFile file("myreleasekey.keystore")storePassword "password"keyAlias "MyReleaseKey"keyPassword "password"}demo {storeFile file("myreleasekey.keystore")storePassword "password"keyAlias "MyReleaseKey"keyPassword "password"}}defaultConfig {signingConfig signingConfigs.release //默认签名}buildTypes {debug{signingConfig null //这里一定要置null,否则gralde会插入默认签名}release{...}}// Specifies one flavor dimension.flavorDimensions "version"productFlavors {demo {dimension "version"applicationIdSuffix ".demo"versionNameSuffix "-demo"signingConfig signingConfigs.demo //渠道签名}full {dimension "version"applicationIdSuffix ".full"versionNameSuffix "-full"}}
}
按上面配置完后,渠道可以按照自己需求替换签名了。特别注意debug类型那里要置signingConfig null
,否则编译debug版本时签名会不生效,因为gradle会插入默认签名,替换掉渠道的签名。