//load keystore.properties def keystorePropertiesFile = rootProject.file("keystore.properties") def keystoreProperties = new Properties() keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
读取keystore.properties文件
signingConfigs { release { storeFile file(keystoreProperties['testone_path']) storePassword keystoreProperties['testone_pwd'] keyAlias keystoreProperties['testone_key_alias'] keyPassword keystoreProperties['testone_key_pwd'] v1SigningEnabled true v2SigningEnabled true } anothersign { storeFile file(keystoreProperties['testtwo_path']) storePassword keystoreProperties['testtwo_pwd'] keyAlias keystoreProperties['testtwo_key_alias'] keyPassword keystoreProperties['testtwo_key_pwd'] v1SigningEnabled true //两个签名都选择 v2SigningEnabled true } }
signingConfigs进行签名 提供了2种签名
buildTypes { debug { versionNameSuffix "-Debug" } debugForProduction { initWith buildTypes.debug versionNameSuffix "-Debug-Production" } release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } staging { versionNameSuffix "-Staging" minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }
buildTypes声明项目中的几种编译类型
minifyEnabled :这个是用来开启删除无用代码,比如没有引用到的代码
shrinkResources:用来开启删除无用资源,也就是没有被引用的文件
flavorDimensions "production", "channel"
production :维度
channel:不同市场渠道
productFlavors { person { dimension "channel" matchingFallbacks = ["debug", "release", "staging", "debugForProduction"] } tencent { dimension "channel" matchingFallbacks = ["debug", "release", "staging", "debugForProduction"] } huawei { dimension "channel" matchingFallbacks = ["debug", "release", "staging", "debugForProduction"] } xiaomi { dimension "channel" matchingFallbacks = ["debug", "release", "staging", "debugForProduction"] } anzhi { dimension "channel" matchingFallbacks = ["debug", "release", "staging", "debugForProduction"] } uc { dimension "channel" matchingFallbacks = ["debug", "release", "staging", "debugForProduction"] } baidu { dimension "channel" matchingFallbacks = ["debug", "release", "staging", "debugForProduction"] } smartisan { dimension "channel" matchingFallbacks = ["debug", "release", "staging", "debugForProduction"] } flyme { dimension "channel" matchingFallbacks = ["debug", "release", "staging", "debugForProduction"] } productionone { dimension "production" matchingFallbacks = ["debug", "release", "staging", "debugForProduction"] signingConfig signingConfigs.release } productiontwo { dimension "production" matchingFallbacks = ["debug", "release", "staging", "debugForProduction"] signingConfig signingConfigs.release } }
这样一共生成了72个渠道 2*9*4=72
applicationVariants.all{ variant-> def name=variant.name.toLowerCase() println(name+"") if(name.contains("productionone")){ if(name.contains("release")){ println(" productionone release") }else{ println("productionone debug staging") } }else{ if(name.contains("productiontwo")){ println("productiontwo release") }else{ println("productiontwo debug staging") } } }
项目中用到的一些变量可以在这里声明 例如信鸽的ID ,key等