zipalign配合Android多渠道打包

zipalign配合Android多渠道打包

环境准备

下载AndroidSdk,因为我们需要tools下面的zipalign可执行文件,其作用在于对包文件进行优化。

描述

接下来说明的多渠道打包是基于现有存在一个已打好的包的基础上,再往包内META-INF/目录下创建以渠道命名文件的方式进行对渠道包的标识。

上脚本

#coding=utf-8

import os
import sys
import zipfile
import shutil

if __name__ == '__main__':
    apkFile = sys.argv[1]#传进来包文件的路径及文件
    channel = sys.argv[2]#需要打的渠道
    version = sys.argv[3]#版本,目的仅在于区分打包的版本
    apk = 'YYYY'#APK名字前缀
    emptyFile = '/data/package_shell/ZZZ.txt'
    f = open(emptyFile, 'w')
    f.close()
    if (os.path.exists("/data/package_shell/release")):
        print "/data/package_shell/release exists"
    else:
        os.mkdir('/data/package_shell/release')
    channelDir = '/data/package_shell/release/%s' % (channel)
    if (os.path.exists(channelDir)):
        print "channelDir exists"
    else:
        os.mkdir(channelDir)
    destfile = '/data/package_shell/release/%s/%s.apk' % (channel, apk)
    shutil.copy(apkFile, destfile)
    zipped = zipfile.ZipFile(destfile, 'a')
    channelFileName = 'channel_' + channel
    channelFile = "META-INF/{channelname}".format(channelname=channelFileName)
    zipped.write(emptyFile, channelFile)
    zipped.close()
    zipalignFile = '/data/package_shell/release/%s/%s_%s_%s.apk' %(channel, apk, channel, version)
    if (os.path.exists(zipalignFile)):
        os.remove(zipalignFile)
    os.system('/root/android-sdk-linux/tools/zipalign -v 4 %s /data/package_shell/release/%s/%s_%s_%s.apk' %(destfile, channel, apk, channel, version)
    os.remove('/data/package_shell/ZZZ.txt')


如果在运行zipalign命令时出现以下问题,则代表需要的某些so库不存在,需要咱们自己进行安装,如下:
1./lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
2.error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
需要安装如下库:
yum -y install glibc.i686
yum install libstdc++.i686
yum install zlib.i686

如果仍然报so库找不到的错误,请使用命令ldd ./zipalign查看哪些so库找不到,直接安装就好!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值