本文最后更新于:2024年12月29日 下午
一般签名都是放在buildTypes里面:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| ... android { ... defaultConfig {...} signingConfigs { release { storeFile file("myreleasekey.keystore") storePassword "password" keyAlias "MyReleaseKey" keyPassword "password" } } buildTypes { release { ... signingConfig signingConfigs.release } } }
|
但是多渠道时,使用配置的优先级从高到低分别是buildTypes、productFlavor、defaultConfig,如果按上面配置的话,根本修改不了签名。所以修改成以下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| 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 } release{...} } 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会插入默认签名,替换掉渠道的签名。