Cocos2d-x3.0 iOS 一键编译多个target并打包ipa。
1.编写app打包为ipa的 shell脚本。将以下代码保存为app2ipa.sh。
#!/bin/sh m_appPath=""
m_ipaPath=""
m_showMessage="NO" make_app_to_ipa()
{
app_path=$1
ipa_path=$2
if [ "$m_showMessage" == "YES" ]
then
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "$app_path" -o "$ipa_path"
else
/usr/bin/xcrun > /dev/null 2>&1 -sdk iphoneos PackageApplication -v "$app_path" -o "$ipa_path"
fi
echo " >>>> 打包ipa完毕:$ipa_path"
} showHelp()
{
echo "Convert app to ipa"
echo "optional arguments:"
echo " -h, help show this help message and exit"
echo " -a, app app file path "
echo " -i, ipa ipa file path "
echo " -m,msg display build message, {NO,YES}"
exit
} #// main--------------------------------
until [ $# -eq 0 ]
do
case $1 in
-a | app)
m_appPath=$2
shift
;;
-i | ipa)
m_ipaPath=$2
shift
;;
-m | msg)
m_showMessage=$2
shift
;;
-h | help)
showHelp
;;
*)
echo "error unknow args : $1"
;;
esac shift
done #開始构建
echo ">>>>>>>>>> Build Begin "
make_app_to_ipa $m_appPath $m_ipaPath
echo ">>>>>>>>>> Build Finished . "
2.改动cocos2d-x-3.0\tools\cocos2d-console\plugins\project_compile 下的project_compile.py的build_ios方法。build_ios终于代码例如以下。实际上就是遍历targets循环编译。注意事项:iOS的target
中必须包括 iOS keyword。Mac的target必须包括 Mac keyword.
def build_ios(self):
if not self._platforms.is_ios_active():
return if not cocos.os_is_mac():
raise cocos.CCPluginError("Please build on MacOSX") self.check_ios_mac_build_depends() project_dir = self._project.get_project_dir()
ios_project_dir = self._platforms.project_path()
build_mode = self._mode
if self._project._is_script_project():
if build_mode == 'debug':
output_dir = os.path.join(project_dir, CCPluginCompile.OUTPUT_DIR_SCRIPT_DEBUG, 'ios')
else:
output_dir = os.path.join(project_dir, CCPluginCompile.OUTPUT_DIR_SCRIPT_RELEASE, 'ios')
else:
output_dir = os.path.join(project_dir, CCPluginCompile.OUTPUT_DIR_NATIVE, build_mode, 'ios') projectPath = os.path.join(ios_project_dir, self.xcodeproj_name)
pbxprojectPath = os.path.join(projectPath, "project.pbxproj") f = file(pbxprojectPath)
contents = f.read() section = re.search(r"Begin PBXProject section.*End PBXProject section", contents, re.S) if section is None:
message = "Can't find iOS target"
raise cocos.CCPluginError(message) targets = re.search(r"targets = (.*);", section.group(), re.S)
if targets is None:
message = "Can't find iOS target"
raise cocos.CCPluginError(message) targetName = None
cfg_obj = self._platforms.get_current_config()
if cfg_obj.target_name is not None:
targetName = cfg_obj.target_name
else:
names = re.split("\*", targets.group())
for name in names:
if "iOS" in name:
targetName = str.strip(name)
cocos.Logging.info(" >>>>>>>> targetName = %s" % targetName)
if targetName is None:
message = "Can't find iOS target"
raise cocos.CCPluginError(message) if os.path.isdir(output_dir):
target_app_dir = os.path.join(output_dir, "%s.app" % targetName[:targetName.find(' ')])
if os.path.isdir(target_app_dir):
shutil.rmtree(target_app_dir) cocos.Logging.info("building") command = ' '.join([
"xcodebuild",
"-project",
"\"%s\"" % projectPath,
"-configuration",
"%s" % 'Debug' if self._mode is 'debug' else 'Release',
"-target",
"\"%s\"" % targetName,
"-sdk",
"iphonesimulator",
"-arch i386",
"CONFIGURATION_BUILD_DIR=%s" % (output_dir)
]) self._run_cmd(command)
# app 转 ipa
app_path = os.path.join(output_dir, "%s.app" % targetName[:targetName.find(' ')])
ipa_path = os.path.join(output_dir, "%s.ipa" % targetName[:targetName.find(' ')])
command = ' '.join([
"app2ipa.sh",
"-a",
"\"%s\"" % app_path,
"-i",
"\"%s\"" % ipa_path,
"-m"
])
cocos.Logging.info(" >>>>> run command %s" % command)
self._run_cmd(command) filelist = os.listdir(output_dir) for filename in filelist:
name, extention = os.path.splitext(filename)
if extention == '.a':
filename = os.path.join(output_dir, filename)
os.remove(filename)
if extention == '.app' and name == targetName:
filename = os.path.join(output_dir, filename)
newname = os.path.join(output_dir, name[:name.find(' ')]+extention)
os.rename(filename, newname)
self._iosapp_path = newname if self._no_res:
self._remove_res(self._iosapp_path) cocos.Logging.info("build succeeded.")
好了,我们能够使用例如以下命令编译了
python cocos.py
compile -s /projects/MyGame/proj.ios_mac -m debug -p ios
Cocos2d-x3.0 iOS 一键编译多个target并打包ipa。的更多相关文章
- cocos2d-js 3.0 ios平台编译打包
原帖在http://www.cocoachina.com/bbs/read.php?tid=209356 整理到github的https://github.com/faint2death/cocos2 ...
- ios学习之路:Xcode+swift+打包ipa一步一坑记录
咳咳,作为公司的Android开发(兼java接口开发,兼软件测试,兼运维……)由于公司ios开发小伙伴离我而去,ios的app出了问题,急需处理.于是领导决定由我来处理一下.就是用证书重新打包的事儿 ...
- iOS: FFMpeg编译和使用问题总结
iOS: FFmpeg编译和使用问题总结 折磨了我近一周多时间的FFmpeg库编译问题终于解决了,必须得把这一段时间来遇到过的坑全写出来.如果急着解决问题,编译最新版本的FFmpeg库请直接看第二部分 ...
- iOS: FFmpeg编译和使用 学习
ffmpeg是一个多平台多媒体处理工具,处理视频和音频的功能非常强大.目前在网上搜到的iOS上使用FFMPEG的资料都比较陈旧,而FFMPEG更新迭代比较快: 且网上的讲解不够详细,对于初次接触FFM ...
- JHChart 1.1.0 iOS图表工具库中文ReadMe
JHChart(最新版本1.1.0) 好吧,的确当前的github上已经存有不少的iOS图表工具库,然而,当公司的项目需要图表时,几乎没有哪个第三方能够完全满足我的项目需求.无奈之下,本人不得不花费一 ...
- iOS下编译ffmpeg
网络上搜索“ios ffmpeg 编译”,文章一大把,但我编译还是费了很大的功夫才编译成功.很多文章只是把步骤列了出来,但是每个人的系统环境,或者程序版本都不一样,结果出现各种的错误.我把自己编译过程 ...
- 如何在Cocos2D 1.0 中掩饰一个精灵(六)
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 掩饰一个精灵:实现代码 打开HelloWorldLayer.m并 ...
- vim添加一键编译
引用来自: http://blog.chinaunix.net/uid-21202106-id-2406761.html; 事先声明,我使用的VIM完全是基于终端的,而不是gvim或vim-x11.因 ...
- gVim/Vim 一键编译、连接、运行 C/C++ 单文件
用于Gvim 或 Vim 配置文件的一键编译与运行函数(注:需要机器上安装了GCC才行) 本代码只加入了对C/C++的编译与运行,如果要加入其语言的可以参考此代码加入即可 同时,本代码加入了对Wind ...
随机推荐
- max_binlog_cache_size
http://blog.mimvp.com/2017/07/mysql-yi-ge-can-shu-yin-qi-de-dang-ji-xue-an/ max_binlog_cache_size 表示 ...
- POJ 3041(最小点覆盖)
题意: 假如你如今正处在一个N*N的矩阵中,这个矩阵里面有K个障碍物,你拥有一把武器,一发弹药一次能消灭一行或一列的障碍物,求最小的弹药消灭所有障碍物 输入为: N K 接下来有K行,每行包括 ...
- springboot2.X集成HttpClient 发送HTTPS 请求
1)jar <!--httpclient 发送外部https/http 请求--> <dependency> <groupId>org.apache.httpcom ...
- java通过System.getProperty获取系统属性
getProperties public static Properties getProperties() 确定当前的系统属性. 首先,如果有安全管理器,则不带参数直接调用其 checkProper ...
- Mantis邮件服务器配置
1.在apache下的php.ini中修改(这里是以163的邮箱为例子):[mail function];For Win32 only.SMTP = smtp.163.com; //设置邮箱的发送地址 ...
- 深度学习阅读列表 Deep Learning Reading List
Reading List List of reading lists and survey papers: Books Deep Learning, Yoshua Bengio, Ian Goodfe ...
- Robots协议(爬虫协议、机器人协议)
Robots协议(也称为爬虫协议.机器人协议等)的全称是“网络爬虫排除标准”(Robots Exclusion Protocol),网站通过Robots协议告诉搜索引擎哪些页面可以抓取,哪些页面不能抓 ...
- Spark从HDFS上读取JSON数据
代码如下: import org.apache.spark.sql.Row; import org.apache.spark.SparkConf; import org.apache.spark.ap ...
- uva 10160 Servicing Stations(DFS+剪枝)
Servicing stations A company offers personal computers for sale in N towns (3 <= N <= 35). The ...
- Container With Most Water leetcode java
题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...