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-sdkiphoneosPackageApplication-v"$app_path"-o"$ipa_path"
- else
- /usr/bin/xcrun>/dev/null2>&1-sdkiphoneosPackageApplication-v"$app_path"-o"$ipa_path"
- fi
- echo">>>>打包ipa完成:$ipa_path"
- }
- showHelp()
- {
- echo"Convertapptoipa"
- echo"optionalarguments:"
- echo"-h,helpshowthishelpmessageandexit"
- echo"-a,appappfilepath"
- echo"-i,ipaipafilepath"
- echo"-m,msgdisplaybuildmessage,{NO,YES}"
- exit
- }
- #//main--------------------------------
- until[$#-eq0]
- do
- case$1in
- -a|app)
- m_appPath=$2
- shift
- ;;
- -i|ipa)
- m_ipaPath=$2
- shift
- ;;
- -m|msg)
- m_showMessage=$2
- shift
- ;;
- -h|help)
- showHelp
- ;;
- *)
- echo"errorunknowargs:$1"
- ;;
- esac
- shift
- done
- #开始构建
- echo">>>>>>>>>>BuildBegin"
- make_app_to_ipa$m_appPath$m_ipaPath
- echo">>>>>>>>>>BuildFinished."
- defbuild_ios(self):
- ifnotself._platforms.is_ios_active():
- return
- ifnotcocos.os_is_mac():
- raisecocos.CCPluginError("PleasebuildonMacOSX")
- self.check_ios_mac_build_depends()
- project_dir=self._project.get_project_dir()
- ios_project_dir=self._platforms.project_path()
- build_mode=self._mode
- ifself._project._is_script_project():
- ifbuild_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,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"BeginPBXProjectsection.*EndPBXProjectsection",contents,re.S)
- ifsectionisNone:
- message="Can'tfindioStarget"
- raisecocos.CCPluginError(message)
- targets=re.search(r"targets=(.*);",section.group(),re.S)
- iftargetsisNone:
- message="Can'tfindioStarget"
- raisecocos.CCPluginError(message)
- targetName=None
- cfg_obj=self._platforms.get_current_config()
- ifcfg_obj.target_nameisnotNone:
- targetName=cfg_obj.target_name
- else:
- names=re.split("\*",targets.group())
- fornameinnames:
- if"iOS"inname:
- targetName=str.strip(name)
- cocos.Logging.info(">>>>>>>>targetName=%s"%targetName)
- iftargetNameisNone:
- message="Can'tfindioStarget"
- raisecocos.CCPluginError(message)
- ifos.path.isdir(output_dir):
- target_app_dir=os.path.join(output_dir,"%s.app"%targetName[:targetName.find('')])
- ifos.path.isdir(target_app_dir):
- shutil.rmtree(target_app_dir)
- cocos.Logging.info("building")
- command=''.join([
- "xcodebuild",
- "-project",
- "\"%s\""%projectPath,
- "-configuration",
- "%s"%'Debug'ifself._modeis'debug'else'Release',
- "-target",
- "\"%s\""%targetName,
- "-sdk",
- "iphonesimulator",
- "-archi386",
- "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(">>>>>runcommand%s"%command)
- self._run_cmd(command)
- filelist=os.listdir(output_dir)
- forfilenameinfilelist:
- name,extention=os.path.splitext(filename)
- ifextention=='.a':
- filename=os.path.join(output_dir,filename)
- os.remove(filename)
- ifextention=='.app'andname==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
- ifself._no_res:
- self._remove_res(self._iosapp_path)
- cocos.Logging.info("buildsucceeded.")
好了,我们可以使用如下命令编译了
Python cocos.py compile -s /projects/MyGame/proj.ios_mac -m debug -p iOS