android 打多渠道包快捷方式

2021-08-21 04:47:04 字數 1842 閱讀 2618

安卓打渠道包是個比較頭痛的問題,如在gradle裡面配置manifestplaceholders的方式,它雖然實現了打出多渠道包,代價也是相當大的。編譯耗時長,同時計算機基本也幹不了別的事了,不能忍受!

直接修改鏈結文章的指令碼實現~

指令碼:

import sys,os,shutil,zipfile,time,json 

srcfilename="source.apk"

apksdir="apks"

target_file="temp.apk"

file=open("channel.txt")

def writechanneltoapk(filename,channel):

z=zipfile.zipfile(filename,

'a',zipfile.zip_deflated)

empty_channel_file="meta-inf/channel.json"

if not os.path.exists(target_file):

open(target_file,

'a').close()

z.writestr(empty_channel_file,data=channel,compress_type=zipfile.zip_deflated)

print("path:"+filename+"

\n"+"content:"+channel)

z.close()

def cpfile(srcpath,filename):

destpath=os.path.abspath('.')+os.path.sep+filename

if os.path.exists(srcpath)and not os.path.exists(destpath):

shutil.copy(srcpath,destpath)

if not os.path.exists(srcfilename):

print("source file "+srcfilename+" not exists")

sys.exit(1)

start=time.clock()

if not os.path.exists(apksdir):

os.makedirs(apksdir)

for line in file:

channel=line.strip('

\n').strip()

data=json.loads(channel)

targetfilename=apksdir+"/"+data['channel_name']+data['channel_code']+".apk"

cpfile(srcfilename,targetfilename)

writechanneltoapk(targetfilename,channel)

end=time.clock()

print("the function run time is : %.03f seconds"%(end-start))

與原指令碼唯一不同就是固定了寫入檔名,然後將channel.txt的內容寫入到檔案裡。

channel.txt

執行指令碼就會生成對應的渠道包,剩下的就需要到**裡面去解析渠道資訊了。

;zipfile zipfile = null;

inputstream inputstream = null;

try catch (ioexception e) finally catch (ioexception e)

}初始化zipfile,可以根據檔案路徑獲取它的zipentry物件,然後再根據zipentry拿到檔案的流資訊,讀取就可以了。

Android多渠道打包

度娘能搜到很多種多渠道打包方式,我這裡簡單說下我們目前正在使用的打包方法。首先背景情況 我們不同渠道,除了渠道號 vendorid 不一樣外,還有功能上的稍許不同,所以還有幾個開關控制專案。方法原理 專案 中在res raw 下增加config.dat檔案,裡面有渠道號,和功能開關 apk包,其實是...

Android原始多渠道打包

原始多渠道打包就是個體力活,在較少渠道的時候可以使用,但是面對上千的渠道的時候,使用這種方式你會後悔當一名android開發工程師。它的原理是在應用 中設定渠道id,使用的時候將渠道id設定給資料分析介面,資料分析平台通過該渠道id分析之。其實後面多渠道方式的本質原理都是這樣的,但是具體擴充套件方式...

Android多渠道SDK開發心得

以前開發sdk都是在eclipse環境下進行,使用ant進行構建,提供jar so形式的sdk供第三方整合 隨著android studio的使用,公司sdk專案也轉向studio環境,使用gradle進行構建,根據第三方需求分別提供jar so及aar包形式的sdk。本系列文章記錄了整個sdk構建...