一键自动发布ipa(更新svn,拷贝资源,压缩资源,加密图片资源,加密数据文件,加密lua脚本,编译代码,ipa签名,上传ftp)...
一鍵自動發布ipa(更新svn,拷貝資源,壓縮資源,加密圖片資源,加密數據文件,加密lua腳本,編譯代碼,ipa簽名,上傳ftp)
程序員的生活要一切自動化,更要幸福^_^。
?
轉載請注明出處http://www.cnblogs.com/mrblue/p/3885043.html
感謝小波同學?
?
概述
平臺:mac
例子工程:基于cocos2dx引擎的項目
?事實:就是一組shell腳本和一些工具
?
我的 目錄結構
Work
|-----Project
|---------cocos2dx
|---------Game
|---------proj.ios
|---------Resoueces
|-----tool
|-----publish_package (這是我的打包工具存放目錄)
|-------package
|-----------ios(ipa最終輸出目錄)
|-----------android(apk最終輸出目錄,我還沒完成,請各路大神幫忙完善)
|-------script
|-------tool
|-------config.txt
|-------publish_ipa.sh
|-------upload_ftp.sh
?
?
一、配置文件 ?config.txt
說明:
1、這是所有配置,供其他腳本使用的一些常量,放這里統一管理
2、我們代碼和資源svn目錄是分開(這樣有好有壞)
#! /bin/sh#根目錄 CurrentDir=`dirname $0`#--------------------------------------SVN更新-------------------------------------- #SVN代碼目錄 SVN_Code=$CurrentDir/../..#SVN資源目錄 SVN_Resource=$CurrentDir/resource#要拷貝到的目標目錄 Destiny_Dir_Resource=$SVN_Code/project/Game/Resources/resource#--------------------------------------壓縮PNG-------------------------------------- CompressTool_Path=$CurrentDir/tool/ImageAlpha.app/Contents/Resources#--------------------------------------資源加密-------------------------------------- #加密工具目錄 EncryptTool_Path=$CurrentDir/tool#png加密key PngEncryptKey=xxxxxxxxxxxxxxxxxxxxx#data加密key DataEncryptKey=xxxxxxxxxxxxxxxxxxxxxxxx#加密長度 EncryptDataLen=128#--------------------------------------編譯ipa-------------------------------------- ProjectRoot_Path=$SVN_Code/project#xcodeproj所在目錄 XCodeProject_Path=$ProjectRoot_Path/Game/proj.ios#OutPut目錄 TargetOutput_Path=$ProjectRoot_Path/bin/release/Game#Export目錄 TargetExport_Path=$CurrentDir/package/ios#簽名 IPA_SignIdentiy="xxxxxxxxxxxxxxxxxxx" IPA_ProvisionIdentiy="xxxxxxxxxxxxxxxxxxxxx"#要生成的Target名字 ProjectTargets_Array=("Game_91" "Game_kuaiyong" "Game_pp" "Game_tongbu")?
二、發布腳本publish_ipa.sh
說明:
1、如果你只想打出ipa,不想上傳ftp,那就直接運行這個腳本,然后ipa自動生成在package/ios下
2、可以模塊化執行,比如本次你只執行更新svn,但不需要執行資源加密等過程(之前已經弄好過了),那就把一些函數用#注釋掉
#! /bin/sh#根目錄 RootDir=`dirname $0`#加載配置文件 . $RootDir/config.txt#加載自動更新SVN腳本 . $RootDir/script/update_svn.sh#加載拷貝資源腳本 . $RootDir/script/copy_resouce.sh#加載壓縮PNG腳本 . $RootDir/script/compress_png.sh#加載壓縮PNG腳本 . $RootDir/script/encrypt.sh#lua腳本編譯成字節碼 . $RootDir/script/compile_luajit.sh#加載編譯工程函數庫 . $RootDir/script/build_ipa.shfunction main() {updateSvncopyResourcecompressPNGencryptPNGencryptTableDatacomplieLuajitbuildProject }main?
3、更新svn ? ?script/update_svn.sh
4、拷貝資源 script/copy_resouce.sh
說明:把簽出的resource拷貝到Game/Resouece下
?
5、壓縮png script/compress_png.sh
說明:
1、使用的是pngquant,將全色png為256色的png8
2、工具所在目錄是tool/ImageAlpha.app
#!/bin/sh#壓縮紋理Compress_ProcessPath_Resource=$DestinyPath_Resource#工具目錄 Compress_ToolPath=$CompressTool_Path#壓縮png function compressPNG() {echo "-------Start Compress PNG : " $Compress_ProcessPath_Resource " ---------------"cd $Compress_ToolPathimageNumber=0tmpfilename=nillfor filename in `find $Compress_ProcessPath_Resource -name "*.png"`do./pngquant 256 --ext _tmp.png $filenamerm -rf $filenameimageNumber=$[imageNumber+1]doneecho "start to rename Procedure!"for filename in `find $Compress_ProcessPath_Resource -name "*.png"`dotmpfilename=`echo ${filename%*_tmp*}`mv $filename $tmpfilename.pngdoneecho "-------End Compress PNG with ImageNumber: " $imageNumber "Success Finished ! ---------------"cd $Script_RootDir }?
6、加密png和數據文件?script/encrypt.sh
說明:
1、加密方式是簡單的抑或加密
2、可執行文件目錄是 tool/EncryptPacker
3、png使用前EncryptDataLen(見config.txt)的長度字節加密,數據文件全部加密
4、如果你要給png加密,需要自己手動修改加載png的源文件代碼(cocos2dx的在bool initWithImageFile(const char * strPath, EImageFormat imageType = kFmtPng)等地方)
5、這里給出機密工具(?tool/EncryptPacker)的c++代碼文件(因為使用的抑或加密,所以加密和解密代碼一樣的)
?
// // main.cpp // EncryptPacker // // Created by Blue on 14-6-4. // Copyright (c) 2014年 Blue. All rights reserved. // #include <iostream> #include <string> #include <fstream>using namespace std;const char* g_pszDesc = "Usage:\n\t./EncryptPacker inputfile key limitlength\n\nDesc:\n\tinputfile\t\tthe soucre file which will be encrypted(it will be replaced after encrypting)\n\tkey\t\t\t\tthe secret key(at least one character)\n\tlimitlength\t\tthe length of this file'data will be encrypted(0 means full lenth of the file)\n\nExample:\n\t./EncryptPacker a.txt xxxxxxxx 100\n";int main(int argc, const char * argv[]) {if (argc<4){std::cout << g_pszDesc;return 0;}/*for (int i=1; i<argc; i++){cout<<argv[i]<<endl;}*/const string strInputFile = argv[1];FILE* fp = fopen(strInputFile.c_str(), "r");if (!fp){cout<<"read file ["<<strInputFile.c_str()<<"] failed"<<endl;return 0;}const string strKey = argv[2];size_t nKeyLen = strKey.length();if (strKey.empty()){cout<<"input key"<<endl;return 0;}int nLimitlength = atoi(argv[3]);if (nLimitlength<0){cout<<"limitlength must >= 0"<<endl;return 0;}fseek(fp,0,SEEK_END);long lLen = ftell(fp);fseek(fp,0,SEEK_SET);unsigned char* pBuffer = new unsigned char[lLen+1];pBuffer[lLen] = '\0';fread(pBuffer,sizeof(unsigned char), lLen,fp);fclose(fp);if (nLimitlength>0){for(int i=0; i<nLimitlength && i<lLen; i++){unsigned char cTemp = pBuffer[i];pBuffer[i] = cTemp^strKey.at(i%nKeyLen);}}else{for(int i=0; i<lLen; i++){unsigned char cTemp = pBuffer[i];pBuffer[i] = cTemp^strKey.at(i%nKeyLen);}}FILE* wfp = fopen(strInputFile.c_str(), "w");fwrite(pBuffer, lLen, 1, fp);fclose(wfp);delete[] pBuffer;std::cout << "Encrypt ["<<strInputFile.c_str()<<"] successfully!\n";return 1; }?
?
7、加密lua腳本?script/compile_luajit.sh
說明:使用tool/luajit/luajit把lua腳本編譯成字節碼(不要搞什么自己加密了,這樣做好處多多,自行百度)
?
8、生成ipa并簽名?script/build_ipa.sh
9、上傳ftp?upload_ftp.sh(我還會自動幫你把dYSM文件備份,以備后面查看崩潰堆棧用)
?
使用方式:
一、只打ipa包,不上傳ftp
1)那就打開命令行工具cd到publish_package,敲入sh?publish_ipa.sh,回車
2)漫長等待后會在package/ios下生成ipa
?
二、生成ipa并上傳ftp
1)那就打開命令行工具cd到publish_package,敲入sh?upload_ftp.sh,回車
2)漫長等待后會在ftp你指定的目錄下生成一個以今天日期命名的文件夾,里面躺著ipa,如20140804/Game_20140804.ipa和dSYM_20140804.tar(dSYM的壓縮包)
?
?最后附上工具套下載地址?publish_package
?
祝你們都幸福。
轉載于:https://www.cnblogs.com/mrblue/p/3885043.html
總結
以上是生活随笔為你收集整理的一键自动发布ipa(更新svn,拷贝资源,压缩资源,加密图片资源,加密数据文件,加密lua脚本,编译代码,ipa签名,上传ftp)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mahout推荐10-尝试GroupLe
- 下一篇: 在Windows下使用MinGW静态编译