简体   繁体   中英

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. Behind the scenes I try to use the xcodebuild command to create the final IPA and return it to the user. All the projects developed using Cordova and prepared to be compiled with XCode with the following commands:

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.

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...

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. 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. (He can also choose other platforms which are supported by the Cordova framework). Much like PhoneGap's build eventually.

You can generate the schemes programmatically using a build hook script that the Cordova CLI will run before building for 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:

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:

#!/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.

Then to run the script edit your project's config.xml and add:

<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. Here I use after_platform_add so the Cordova CLI will add the schemes after the iOS platform is added. 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. Cordova Hook documentation is here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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