require 'FileUtils'
require 'pathname'
require 'digest/md5'
require 'rexml/document'
include REXML
#测试参数
rsyncServer = "keeper@192.168.1.4::" #rsync服务器地址
apkName = "keeper" #最终版本APK名字
ClientApkVer = 13851 #客户端APK版本
UIType = 0 #0 ldip, 1 hdpi UI分辨率类型
LdpiVer = 13935 #标清UI
HdpiVer = #高清UI
MusicVer = 13934 #音乐版本
GameVer = 1 #游戏版本号
cfglVer = 13847 #cfgl.db版本号
logicclVer = 13847 #logiccl.db版本号
CfgVer = 13847 #Cfg配置文件版本号
FightWorldVer = 13870 #fightWorld Assetbundle版本号
FightABVer = 13452 #Fight Assetbundle版本号
fightmlVer = 13775 #fightml.db版本号
fightulVer = 13775 #fightul.db版本号
#测试参数
filePath = Pathname.new(File.dirname(__FILE__)).realpath #一键打包APK.rb所在的文件夹
apkPath = ""
DecodingPath = filePath + "Decoding"
resPath = filePath + "Res"
cfgPath = filePath + "Cfg"
# ================================================== download ClientApk from version server ==================================================
clientApkPath = Dir.glob(filePath + "gamec_*.apk")[0]
if clientApkPath != nil
File.delete clientApkPath
end
SrcPath = rsyncServer + "develop/gamec/"
DesPath = filePath
system "rsync -vzrtopg --include=gamec_#{ClientApkVer}_*.apk --exclude=* --progress --password-file=#{filePath + "keeper.pwd"} #{SrcPath} #{DesPath}"
apkPath = Dir.glob(filePath + "gamec_#{ClientApkVer}_*.apk")[0]
# ================================================== download UI from version server ==================================================
if File.exist?(resPath) == true
Dir.foreach(resPath) do |file|
if file!="." and file!=".."
FileUtils.remove_file(resPath+file, true)
end
end
else
Dir.mkdir(resPath)
end
if UIType == 0
SrcPath = rsyncServer + "develop/ui_l/ldpi_#{LdpiVer}/"
elsif UIType == 1
SrcPath = rsyncServer + "develop/ui_h/hdpi_#{HdpiVer}/"
end
DesPath = resPath
system "rsync -vzrtopg --exclude=\"*.md5\" --exclude=\"*.meta\" --exclude=\"*.svn\" --progress --password-file=#{filePath + "keeper.pwd"} #{SrcPath} #{DesPath}"
# ================================================== download Music from version server ==================================================
SrcPath = rsyncServer + "develop/ui_music/music_#{MusicVer}/"
DesPath = resPath
system "rsync -vzrtopg --exclude=\"*.md5\" --exclude=\"*.meta\" --exclude=\"*.svn\" --progress --password-file=#{filePath + "keeper.pwd"} #{SrcPath} #{DesPath}"
# ================================================== download Fight from version server ==================================================
SrcPath = rsyncServer + "develop/fightUl/"
DesPath = resPath
system "rsync -vzrtopg --include=fightul_#{fightulVer}_*.db --exclude=* --progress --password-file=#{filePath + "keeper.pwd"} #{SrcPath} #{DesPath}"
SrcPath = rsyncServer + "develop/fightMl/"
DesPath = resPath
system "rsync -vzrtopg --include=fightml_#{fightmlVer}_*.db --exclude=* --progress --password-file=#{filePath + "keeper.pwd"} #{SrcPath} #{DesPath}"
SrcPath = rsyncServer + "develop/fightAB/fightAB_#{FightABVer}/"
DesPath = resPath
system "rsync -vzrtopg --exclude=\"*.md5\" --exclude=\"*.meta\" --exclude=\"*.svn\" --progress --password-file=#{filePath + "keeper.pwd"} #{SrcPath} #{DesPath}"
SrcPath = rsyncServer + "develop/fightWorld/fightWorld_#{FightWorldVer}/"
DesPath = resPath
system "rsync -vzrtopg --exclude=\"*.md5\" --exclude=\"*.meta\" --exclude=\"*.svn\" --progress --password-file=#{filePath + "keeper.pwd"} #{SrcPath} #{DesPath}"
# ================================================== download GameDataLayer from version server ==================================================
if File.exist?(cfgPath) == true
Dir.foreach(cfgPath) do |file|
if file!="." and file!=".."
FileUtils.remove_file(cfgPath+file, true)
end
end
else
Dir.mkdir(cfgPath)
end
SrcPath = rsyncServer + "develop/cfgl/"
DesPath = cfgPath
system "rsync -vzrtopg --include=cfgl_#{cfglVer}_*.db --exclude=* --progress --password-file=#{filePath + "keeper.pwd"} #{SrcPath} #{DesPath}"
SrcPath = rsyncServer + "develop/logiccl/"
DesPath = cfgPath
system "rsync -vzrtopg --include=logiccl_#{logicclVer}_*.db --exclude=* --progress --password-file=#{filePath + "keeper.pwd"} #{SrcPath} #{DesPath}"
SrcPath = rsyncServer + "develop/c_config/c_config_#{CfgVer}/"
DesPath = cfgPath
system "rsync -vzrtopg --exclude=\"*.md5\" --exclude=\"*.meta\" --exclude=\"*.svn\" --progress --password-file=#{filePath + "keeper.pwd"} #{SrcPath} #{DesPath}"
# ================================================== one key md5 for Cfg==================================================
CfgUpdateFilePath = cfgPath + "UpdateFile.xml"
if File.exist?(CfgUpdateFilePath) == true
FileUtils.remove_file(CfgUpdateFilePath, true)
end
xmlFile = File.new(CfgUpdateFilePath, "w+") #新建XML文件, 将以下内容写入
doc = Document.new #创建XML内容
xmldecl = XMLDecl.new("1.0", "UTF-8")
doc.add(xmldecl)
root = doc.add_element('updateFile')
e1 = root.add_element('updateFileList',
{'version' => "1.0.#{GameVer}",
'date' => Time.now})
Dir.foreach(cfgPath) do |file|
if file!="." and file!=".." and file !="UpdateFile.xml" and file != ".DS_Store"
str = file.to_str
index1 = str.rindex('_')
index2 = str.rindex('.')
md5 = str[(index1+1), (index2-index1-1)]
str = str.gsub('_' + md5, "")
index1 = str.rindex('_')
index2 = str.rindex('.')
filetype = str[index2+1, str.length]
if filetype == "unity3d"
elsif filetype == "db"
ver = str[(index1+1), (index2-index1-1)]
str = str.gsub('_' + ver, "")
end
File.rename(cfgPath+file, cfgPath+str)
e1.add_element('files', {
'fileName' => str,
'md5' => md5})
end
end
#doc.write
xmlFile.puts doc.write
checkPath = cfgPath + "check"
xmlMd5 = Digest::MD5.hexdigest(File.read(CfgUpdateFilePath))
checkFile = File.new(checkPath, "w+")
checkFile.puts xmlMd5
checkFile.close
# ================================================== one key md5 for Res==================================================
ResUpdateFilePath = resPath + "UpdateFile.xml"
if File.exist?(ResUpdateFilePath) == true
FileUtils.remove_file(ResUpdateFilePath, true)
end
xmlFile = File.new(ResUpdateFilePath, "w+") #新建XML文件, 将以下内容写入
doc = Document.new #创建XML内容
xmldecl = XMLDecl.new("1.0", "UTF-8")
doc.add(xmldecl)
root = doc.add_element('updateFile')
e1 = root.add_element('updateFileList',
{'version' => "1.0.#{GameVer}",
'date' => Time.now})
Dir.foreach(resPath) do |file|
if file!="." and file!=".." and file !="UpdateFile.xml" and file != ".DS_Store"
str = file.to_str
index1 = str.rindex('_')
index2 = str.rindex('.')
md5 = str[(index1+1), (index2-index1-1)]
p file
str = str.gsub('_' + md5, "")
index1 = str.rindex('_')
index2 = str.rindex('.')
filetype = str[index2+1, str.length]
if filetype == "unity3d"
elsif filetype == "db"
ver = str[(index1+1), (index2-index1-1)]
str = str.gsub('_' + ver, "")
end
File.rename(resPath+file, resPath+str)
e1.add_element('files', {
'fileName' => str,
'md5' => md5})
end
end
#doc.write
xmlFile.puts doc.write
checkPath = resPath + "check"
xmlMd5 = Digest::MD5.hexdigest(File.read(ResUpdateFilePath))
checkFile = File.new(checkPath, "w+")
checkFile.puts xmlMd5
checkFile.close
# ================================================== one key APK ==================================================
#decoding apk to folder "Decoding"
system "apktool d -f #{apkPath} #{DecodingPath}"
p "client: decoding apk successful!"
#remove folder to decoding folder
if File.exist?(DecodingPath + "assets/Cfg") == true
FileUtils.remove_dir(DecodingPath + "assets/Cfg", true)
p "client: delete Cfg folder from decoding folder successful!"
end
if File.exist?(DecodingPath + "assets/Res") == true
FileUtils.remove_dir(DecodingPath + "assets/Res", true)
p "client: delete Res folder from decoding folder successful!"
end
#copy folder to decoding folder
FileUtils.cp_r(filePath + "Cfg", DecodingPath + "assets/Cfg")
p "client: cope Cfg to decoding folder successful!"
FileUtils.cp_r(filePath + "Res", DecodingPath + "assets/Res")
p "client: cope Res to decoding folder successful!"
#build Decoding folder to apk
system "apktool b #{DecodingPath}"
p "client: build apk successful!"
#sign apk
keystorePath = filePath + "gate.keystore"
signApkPath = filePath + "apk/#{apkName}_#{GameVer}.apk"
unsignApkPath = DecodingPath + "dist/#{File.basename(apkPath)}"
system "/usr/libexec/java_home -v 1.6.0 --exec jarsigner -verbose -keystore #{keystorePath} -storepass 123456 -signedjar #{signApkPath} #{unsignApkPath} #{keystorePath}"
p "client: sign #{apkName}.apk successful!"
verFilePath = File.dirname(signApkPath) + "/#{apkName}_#{GameVer}.txt"
verFile = File.new(verFilePath, "w+")
verFile.puts "rsync服务器地址: #{rsyncServer}"
verFile.puts "最终版本APK名字: #{apkName}_#{GameVer}.apk"
verFile.puts "客户端APK版本: #{ClientApkVer}"
verFile.puts "UI分辨率类型: #{UIType}"
verFile.puts "标清UI版本: #{LdpiVer}"
verFile.puts "高清UI版本: #{HdpiVer}"
verFile.puts "音乐版本: #{MusicVer}"
verFile.puts "游戏版本号: #{GameVer}"
verFile.puts "cfgl.db版本号: #{cfglVer}"
verFile.puts "logiccl.db版本号: #{logicclVer}"
verFile.puts "Cfg配置文件版本号: #{CfgVer}"
verFile.puts "FightWorld Assetbundle版本号: #{FightWorldVer}"
verFile.puts "Fight Assetbundle版本号: #{FightABVer}"
verFile.puts "fightml.db版本号: #{fightmlVer}"
verFile.puts "fightul.db版本号: #{fightulVer}"
p "client: #{apkName}.apk rebuild successful!"
一键合成APK
最新推荐文章于 2023-02-17 17:19:19 发布