a plugin which helps you generate greate amount of channel apks in few seconds. 基于gradle的快速打包插件,监听了app:assembleRelease任务,执行该任务后将自动打渠道包。 ##打包方案:
- app:asssembleRelease 生成一个签名的正式包。
- 解压apk包,在META-INF目录下新建一个文件,写入渠道信息
- 重新压缩并用渠道命名。 ##用法:
classpath 'com.github.vinci.quick-channels:plugin:1.0.2'
apply plugin: 'com.github.vinci.quick-channels'
channelExt{
desPath = "E:\\androidWorkspace\\QuickChannels\\outputapks"
apkPath = "E:\\androidWorkspace\\QuickChannels\\app\\build\\outputs\\apk\\app-release.apk"
nameFormat = "QuickChannel-channel-{channel}.apk"dfdsfsdfsd
channelFile = "singleChannel.properties"
}
以上为示例,请自行对照替换相应的值。 其中闭包channelExt为配置参数,
-
desPath 为渠道包输出目录,
-
apkPath为签名包生成路径,这个一般是在app\build\outputs\apk\下,
-
nameFormat为生成的渠道包的命名规则,其中‘{channel}’将被替换为对应的渠道名,
-
channelFile为渠道列表文件,一般放在根目录下。渠道列表文件内填写规则如下
channel_baidushoujizhushou = baidushoujizhushou
channel_xiaomiyingyongshangdian = xiaomiyingyongshangdian
channel_official = official
channel_jifengshichang = jifengshichang
release{
storeFile file(keyProperties['store'])
storePassword keyProperties['storePass']
keyAlias keyProperties['alias']
keyPassword keyProperties['pass']
}
签名信息请在signingConfigs中配置好。
最后通过代码获取渠道信息
public static String getChannel(Context context) {
ApplicationInfo appinfo = context.getApplicationInfo();
String sourceDir = appinfo.sourceDir;
String ret = "";
ZipFile zipfile = null;
try {
zipfile = new ZipFile(sourceDir);
Enumeration<?> entries = zipfile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = ((ZipEntry) entries.nextElement());
String entryName = entry.getName();
if (entryName.startsWith("META-INF/pwchannel")) {
ret = entryName;
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (zipfile != null) {
try {
zipfile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
String[] split = ret.split("-");
if (split != null && split.length == 3) {
String channel = split[2];
return channel;
} else {
return "";
}
}
- 1.0.0
- 发布第一版,基本实现快速打包功能
- 1.0.1
- 1.0.2
- 支持指定渠道列表文件
- 1.0.3
- 修复了上一版本的一个bug,该bug由
TextUtils.java
的ClassNotFound
引起,在org.gradle
的包下,将引起任务失败。
- 修复了上一版本的一个bug,该bug由