def doPackWithOneChannelSymbol(self, channelId, tempRecompileApk, tempSignedApkName, outputDir, outputName, symbol, taskWorkDir): ''' @param channelId 渠道id,用于获取keystore @param tempRecompileApk 重打包后的未签名apk path @param tempSignedApkName 签名对齐后的包名称 @param outputDir 输出路径(非完整path) @param outputName 输出名称(非完整path) @param symbol 自定义渠道标记 @param taskWorkDir 工作目录 ''' log_utils.getLogger().info('doPackWithOneChannelSymbol ... ') #添加渠道标识 log_utils.getLogger().info('adding channel symbol to /assets/ ... ') channelSymbolFileName = ConfigParse.shareInstance( ).getChannelSymbolFileName() zip_utils.addChannelSymbolFile(tempRecompileApk, symbol, channelSymbolFileName, taskWorkDir) #apk签名 log_utils.getLogger().info('signing apk') keystoreInfo = ConfigParse.shareInstance().getKeystoreInfoByChannelId( channelId) ret = cmd_tools.signApk(tempRecompileApk, keystoreInfo['file'], keystoreInfo['storePassword'], keystoreInfo['keyAlias'], keystoreInfo['aliasPassword']) if ret: raise PackException(pack_exception.SIGN_APK_FAILED, 'sign apk failed') #apk优化 apkName = '%s/%s' % (outputDir, outputName) outputDir = os.path.dirname(apkName) if not os.path.exists(outputDir): os.makedirs(outputDir) log_utils.getLogger().debug(outputDir) log_utils.getLogger().info('zipaligning and renaming apk apkName == ' + apkName) ret = cmd_tools.alignAPK(tempRecompileApk, tempSignedApkName) if ret: raise PackException(pack_exception.ALIGN_APK_FAILED, 'align apk failed') os.rename(tempSignedApkName, apkName)
def doBatchPackWithChannelSymols(self, channelId, unsignedApk, tempSignedApkName, outputDir, outputName, symbolList, taskWorkDir): ''' @param channelId 渠道id,用于获取keystore @param unsignedApk 重打包后的未签名apk path @param tempSignedApkName 签名对齐后的包名称 @param outputDir 输出路径(非完整path) @param outputName 输出名称(非完整path) @param symbolList 自定义渠道标记列表 @param taskWorkDir 工作目录 ''' log_utils.getLogger().info('doBatchPackWithChannelSymols ... ') batchPackDir = os.path.join(taskWorkDir, 'batch') if not os.path.exists(batchPackDir): os.makedirs(batchPackDir) copiedUnsignedApk = os.path.join(os.path.dirname(unsignedApk), 'batchTmpApk.apk') log_utils.getLogger().info('start batch packing ... ') for symbol in symbolList: if not file_utils.copyFile(unsignedApk, copiedUnsignedApk): raise PackException( pack_exception.COPY_FILE_EXCEPTION, 'cannot copy apk during doBatchPackWithChannelSymols') #添加渠道标识 log_utils.getLogger().info( 'adding channel symbol to /assets/ ... ') channelSymbolFileName = ConfigParse.shareInstance( ).getChannelSymbolFileName() zip_utils.addChannelSymbolFile(copiedUnsignedApk, symbol, channelSymbolFileName, taskWorkDir) #apk签名 log_utils.getLogger().info('signing apk') keystoreInfo = ConfigParse.shareInstance( ).getKeystoreInfoByChannelId(channelId) ret = cmd_tools.signApk(copiedUnsignedApk, keystoreInfo['file'], keystoreInfo['storePassword'], keystoreInfo['keyAlias'], keystoreInfo['aliasPassword']) if ret: raise PackException(pack_exception.SIGN_APK_FAILED, 'sign apk failed') #apk优化 apkName = '%s/%s' % (batchPackDir, outputName) basename = os.path.splitext(os.path.basename(apkName))[0] apkOutputDir = os.path.dirname(apkName) if not os.path.exists(apkOutputDir): os.makedirs(apkOutputDir) apkName = os.path.join(apkOutputDir, basename + '(' + symbol + ').apk') log_utils.getLogger().debug(apkOutputDir) log_utils.getLogger().info( 'zipaligning and renaming apk apkName == ' + apkName) ret = cmd_tools.alignAPK(copiedUnsignedApk, tempSignedApkName) if ret: raise PackException(pack_exception.ALIGN_APK_FAILED, 'align apk failed') os.rename(tempSignedApkName, apkName) log_utils.getLogger().info('batch packing success... ') log_utils.getLogger().info('zip apk files ... ') zip_utils.zipApks(batchPackDir, '%s/%s' % (outputDir, outputName))