Skip to content

Instantly share code, notes, and snippets.

@yang-chao
Last active August 29, 2015 14:12
Show Gist options
  • Save yang-chao/75d518dbfe659bdf2279 to your computer and use it in GitHub Desktop.
Save yang-chao/75d518dbfe659bdf2279 to your computer and use it in GitHub Desktop.
Package apks for multiple channels
打包步骤:
1. 运行python gen_flavors.py,生成channel.gradle文件(与build.gradle在同一目录下)
2. 运行Gradle tasks中的assembleRelease或者./gradlew aR
#coding=utf-8
import sys
import os
# 创建channel.gradle
output = open('../channel.gradle', 'w')
output.write('apply plugin: \'android\'')
output.write('\n')
output.write('android {')
output.write('\n')
output.write('productFlavors {')
output.write('\n')
# 读取渠道名列表
f = open('qudao.cfg', 'r')
for channel in f:
name = channel.strip()
if name in ('91', '163', '360'):
# meta-data value中直接使用纯数字会返回null,需要在给它赋值的时候加入特殊处理:
# 1. gradle flavor name不能用数字,在前面加下划线"_"
# 2. 占位符的值填入"\\ xxx"", 例:"\\ 360"
flavor = '_' + name + '{manifestPlaceholders = [channelId:\"\\\ ' + name + '\"]}' + '\n'
else:
flavor = name + '{manifestPlaceholders = [channelId:\"' + name + '\"]}' + '\n'
output.write(flavor)
output.write('}')
output.write('\n')
output.write('}')
f.close
output.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment