简体   繁体   English

使用xcodebuild命令从Cordova项目创建IPA

[英]Create IPA from a Cordova project with xcodebuild command

I'm trying to build a system which can compile a project given the source code (the Cordova SDK app project) and the optional provision settings, similiar to PhoneGap's Build. 我正在尝试构建一个系统,该系统可以根据源代码(Cordova SDK应用程序项目)和可选的设置设置(类似于PhoneGap的Build)来编译项目。 Behind the scenes I try to use the xcodebuild command to create the final IPA and return it to the user. 在幕后,我尝试使用xcodebuild命令创建最终IPA并将其返回给用户。 All the projects developed using Cordova and prepared to be compiled with XCode with the following commands: 所有使用Cordova开发并准备使用以下命令通过XCode进行编译的项目:

cordova platform add ios

cordova prepare ios

The problem is that the xcodebuild requires the project's schemes, which according to my search on the subject are generated only when you open the project with the XCode GUI. 问题是xcodebuild需要项目的方案,根据我对主题的搜索,仅当您使用XCode GUI打开项目时才生成该方案。

Is there any way to generate the schemes for the project using command line tools only? 有什么方法可以仅使用命令行工具为项目生成方案吗? Are the schemes are the same for every project so I can copy a static one to each project I want to compile? 每个项目的方案都一样吗,所以我可以将静态副本复制到要编译的每个项目中?

I'm not really a XCode guy or Mac guy for that matter, so I'd be happy for a clear explanation for how and why the solution works, if there is one... 在这件事上,我并不是真正的XCode或Mac专家,所以我很乐意对解决方案的工作方式和原因(如果有解决方案)进行清晰的解释。

Edit: 编辑:

Just to clarify my final intestions: 只是为了澄清我的最终见解:

When I open the project using the XCode GUI (double click the .xcodeproj) it generates the schemes and then I can use the xcodebuild command successfully without any problem. 当我使用XCode GUI(双击.xcodeproj)打开项目时,它会生成方案,然后我可以成功使用xcodebuild命令,而不会出现任何问题。 But I need this system to be completely automated, so that the user can upload he's project built with the Cordova framework and have this system generate the IPA for him if he choose so. 但是我需要这个系统是完全自动化的,以便用户可以上载用Cordova框架构建的项目,并让该系统为他生成IPA(如果他选择的话)。 (He can also choose other platforms which are supported by the Cordova framework). (他还可以选择Cordova框架支持的其他平台)。 Much like PhoneGap's build eventually. 最终类似于PhoneGap的构建。

You can generate the schemes programmatically using a build hook script that the Cordova CLI will run before building for iOS. 您可以使用构建挂钩脚本以编程方式生成方案,Cordova CLI将在构建iOS之前运行该脚本。 I wrote a blog post on this here but here's a summary: 我在这里写了一篇博客文章,但是这里是一个总结:

I chose to use the xcodeproj Ruby gem, you can get this with: 我选择使用xcodeproj Ruby gem,可以通过以下方式获得它:

sudo gem install xcodeproj

Then create a hook script "fix_xcode_schemes.rb" in the hooks folder of your Cordova project, set it to 755 file permissions so that it is executable and put this in the script: 然后在您的Cordova项目的hooks文件夹中创建一个钩子脚本“ fix_xcode_schemes.rb”,将其设置为755文件权限,使其可执行,并将其放入脚本中:

#!/usr/bin/env ruby
require 'xcodeproj'
xcproj = Xcodeproj::Project.open("platforms/ios/schemedemo.xcodeproj")
xcproj.recreate_user_schemes
xcproj.save

Adjust the platforms/ios/schemedemo.xcodeproj to match your project name. 调整platform / ios / schemedemo.xcodeproj以匹配您的项目名称。

Then to run the script edit your project's config.xml and add: 然后运行脚本,编辑项目的config.xml并添加:

<platform name="ios">
    <hook type="after_platform_add" src="hooks/fix_xcode_schemes.rb" />
    ...
</platform>

Full code and Github on the blog post I linked to. 我链接到的博客文章上的完整代码和Github。 Here I use after_platform_add so the Cordova CLI will add the schemes after the iOS platform is added. 在这里,我使用after_platform_add,因此Cordova CLI将在添加iOS平台后添加方案。 For an existing project you may want to swap this for before_prepare or before_build to add the schemes if you don't want to remove and re-add the ios platform to use my original example. 对于现有项目,如果您不想删除并重新添加ios平台以使用我的原始示例,则可能需要将其交换为before_prepare或before_build以添加方案。 Cordova Hook documentation is here . Cordova Hook文档在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM