Android 使用Python实现多渠道打包
来源:互联网 发布:手机淘宝怎么上传图片 编辑:程序博客网 时间:2024/06/04 09:04
使用前提
需要结合Umeng的多渠道统计,Umeng的集成可以自己去官网了解,参考地址。
环境配置
- Python2.x 可以再Python官网下载
- Android Studio
具体使用
1 . 首先在集成Umeng统计时 不要使用标签在Manifest配置Umeng的APPID和channel。必须在自己的Application实现类中使用如下方式配置:
private void initUmeng() { String appkey =SocializeConstants.APPKEY="58a2ae*************"; String channelId = ManifestUtils.getChannel(this); //这个方法会从META_INFO文件下读取渠道标志 MobclickAgent.UMAnalyticsConfig config = new MobclickAgent.UMAnalyticsConfig(this, appkey, channelId); //初始化友盟配置信息 LogUtil.e(config.mChannelId); MobclickAgent.startWithConfigure(config); //设置友盟配置信息 }
2 . 编写空的channel.apk
文件 可以直接新建一个空白txt文档,然后通过改后缀名实现。
3 . 新建channel.txt
文档,也就是渠道列表,如下图所示,每个列表隔行显示:
xiaomi360wandoujiaQQbaiduopposougouzhongyi
4 . 编写python执行文件 名字随意命名.
注意不要直接在新建的文本编辑器中编写,会出现乱码问题。文件内容如下:
import sys,os,shutil,zipfile,time #导入依赖库apkVersion="1.0" #版本号srcFileName="test.apk" #需要多渠道打包apk的名字outputFileName="test_V" #生成apk的前缀名destDir=os.path.abspath('.')file=open("channel.txt") #打开包含渠道名称的文件def writeChannelToApk(filename,channel): z=zipfile.ZipFile(filename,'a',zipfile.ZIP_DEFLATED) empty_channel_file="META-INF/channel_{channe}".format(channe=channel) target_file="channel.apk" z.write(target_file,empty_channel_file) z.close() print ("writeChannelToApkchannel"+channel+","+filename+"\n")def cpFile(srcPath,fileName): destPath = destDir + os.path.sep + fileName if os.path.exists(srcPath) and not os.path.exists(destPath): shutil.copy(srcPath,destPath)def getTime(): return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))if not os.path.exists(srcFileName): print ("sourcefile"+srcFileName+"notexists") sys.exit(1)start = time.clock()for line in file: channel=line.strip('\n').strip() targetFileName="_"+outputFileName+apkVersion+"_"+channel+".apk" #在这里调整渠道包的名称 print ("copyfile:"+targetFileName) cpFile(srcFileName,targetFileName) writeChannelToApk(targetFileName,channel)end = time.clock()print("The function run time is : %.03f seconds" %(end-start))
5 . 利用Android Studio打包apk(Eclipse的也可以)
需要注意的是 ,在Android Studio不要配置productFlavors
信息,配置好签名信息后,直接在Terminal
输入gradlew assembleRelease
进行签名打包编译。打包后的apk文件放在与上面文件同名目录下。
6 . 在命令控制台中输入python channel.py
命令执行打包操作,1~2s即可完成30个包。实在是太方便了。
7 . 不放心的同学可以再app内键入以下代码查看channel是否正确了
String channelId = AnalyticsConfig.getChannel(getApplicationContext()); //获取友盟的渠道配置信息
8 . ManifestUtils
工具类中用到的方法如下:
/**
* 获取META-INFO下面的渠道
* @param context
* @return
*/
public static String getChannel(Context context) {
if (!TextUtils.isEmpty(channel)) {
return channel;
}
ApplicationInfo appinfo = context.getApplicationInfo();
String sourceDir = appinfo.sourceDir;
ZipFile zipfile = null;
final String start_flag = "META-INF/channel_";
try {
zipfile = new ZipFile(sourceDir);
Enumeration<? extends ZipEntry> entries = zipfile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = ((ZipEntry) entries.nextElement());
String entryName = entry.getName();
if (entryName.contains(start_flag)) {
channel = entryName.replaceAll(start_flag, "");
return channel;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (zipfile != null) {
try {
zipfile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return "";
}
上面用到的文件可以到这个地址下载
- Android 使用Python实现多渠道打包实践
- Android 使用Python实现多渠道打包
- 使用python实现多渠道打包
- 使用python实现多渠道打包
- android 多渠道打包---使用python 3.3.2
- Android快速使用Gradle实现多渠道打包
- Android使用Gradle实现多渠道打包
- python: android批量多渠道打包
- python: android批量多渠道打包
- Android QA专用,Python实现不一样的多渠道打包工具
- Python实现Android Apk 加固及多渠道打包
- 使用Python脚本语言实现自动多渠道打包心得
- Android Stuido 实现多渠道打包
- 使用AndroidStudio实现多渠道打包
- Android多渠道打包之Python打包
- Android 使用 Gradle 多渠道打包
- Android 使用 Gradle 多渠道打包
- Android使用脚本多渠道打包
- 程序猿们_你们对男人消费能力不如狗怎么看
- srsENB + srsUE + Amarisoft MME 测试
- 【Java】4种线程池
- mysql查询当天、本周、本月、上月的数据
- Android界面绘制流程
- Android 使用Python实现多渠道打包
- my.cnf文件参数详解
- label标签的使用
- Pro Git
- mac_不显示任何来源选项
- MNIST数据集分析
- laravel前端内容编译:小白的惨痛经历
- Java关键字—static(静态变量、静态方法、静态类)
- linux drm 架构