Building Xcode iOS projects and creating *.ipa file from the command line
2014-12-18 13:59
543 查看
For our development process of iOS applications, we are using Jenkins set up on the Mac Mini Server, acting as a Continuous Integration (CI) server. It’s fairly easy to configure Jenkins for Xcode projects using Xcode Plugin - however, from time to time we had some issues with setting it up correctly. In order to debug them, we’ve decided to include small shell scripts that build our iPhone and iPad apps – to compare results between our development machines and CI environment.
With introduction of the Xcode 6, building apps from command line became more important for us. For some reason, Xcode 6 requires signing into the Apple Developer account while exporting iOS binaries (*.ipa files). It means that you can no longer export binaries from the Xcode having just provisioning profile and matching certificate, or do that without internet connection. However, you can do it easily with command line tools!
If needed, you can find some more information about building the Xcode projects from command line on man pages (man xcodebuild) or on Building from the Command Line with Xcode FAQ page from the Apple resources.
This command should open pop up – just click on ‘Install’ button to continue.
By default, xcodebuild will choose *.xcdoeproj project form current directory. However, you must specify scheme – if you haven’t changed anything, it will have same name as a project has. That’s -scheme BestAppEver part. Next, we specify what should be done – here we first clean up with clean action, and then archive project – specified by -archivePath build/BestAppEver part.
Next step – create *.ipa file:
Here we specify that we want to export the *.ipa file (-exportArchive -exportFormat ipa does this job), from the archive we created in previous step (-archivePath “build/BestAppEver.xcarchive”) to a file in build sub-directory (-exportPath “build/BestAppEver.ipa”), with a selected provisioning profile (-exportProvisioningProfile “ProvisioningProfileName”).
I’m often wrapping this commands in a handy build.sh shell script:
I’m often adding pod install just above first xcodebuild command.
BTW, this post was inspired by the response I’ve got on StackOverflow for quoestion “Make Ad-hoc builds in Xcode 6 without signing in to developer account”.
With introduction of the Xcode 6, building apps from command line became more important for us. For some reason, Xcode 6 requires signing into the Apple Developer account while exporting iOS binaries (*.ipa files). It means that you can no longer export binaries from the Xcode having just provisioning profile and matching certificate, or do that without internet connection. However, you can do it easily with command line tools!
If needed, you can find some more information about building the Xcode projects from command line on man pages (man xcodebuild) or on Building from the Command Line with Xcode FAQ page from the Apple resources.
Installing command line tools
First of all, install Xcode command line tool if you haven’t done that yet. Just follow steps from excellent tutorial on osxdaily, or just open your favourite terminal app and type:xcode-select --install
This command should open pop up – just click on ‘Install’ button to continue.
Building Xcode projects (*.xcodeproj file) from the command line
Let’s assume you have project named BestAppEver, freshly created with recent version of the Xcode. Navigate to the directory where *.xcodeproj file is located and, as a first step, let’s create *.xcarchive file:xcodebuild -scheme BestAppEver clean archive -archivePath build/BestAppEver
By default, xcodebuild will choose *.xcdoeproj project form current directory. However, you must specify scheme – if you haven’t changed anything, it will have same name as a project has. That’s -scheme BestAppEver part. Next, we specify what should be done – here we first clean up with clean action, and then archive project – specified by -archivePath build/BestAppEver part.
Next step – create *.ipa file:
xcodebuild -exportArchive -exportFormat ipa -archivePath "build/BestAppEver.xcarchive" -exportPath "build/BestAppEver.ipa" -exportProvisioningProfile "ProvisioningProfileName"
Here we specify that we want to export the *.ipa file (-exportArchive -exportFormat ipa does this job), from the archive we created in previous step (-archivePath “build/BestAppEver.xcarchive”) to a file in build sub-directory (-exportPath “build/BestAppEver.ipa”), with a selected provisioning profile (-exportProvisioningProfile “ProvisioningProfileName”).
I’m often wrapping this commands in a handy build.sh shell script:
#!/bin/sh xcodebuild -scheme BestAppEver clean archive -archivePath build/BestAppEver xcodebuild -exportArchive -exportFormat ipa -archivePath "build/BestAppEver.xcarchive" -exportPath "build/BestAppEver.ipa" -exportProvisioningProfile "ProvisioningProfileName"
Building Xcode workspaces (*.xcworkspace file) from the command line
Of course, most of our projects nowdays are using dependencies managed via cocoapods tool. It means that we should specify which workspace we want to use during creation of an archive file – to do that, add -workspace BestAppEver.xcworkspace switch to the first command. Our build.sh script would then have following content:#!/bin/sh xcodebuild -scheme BestAppEver -workspace BestAppEver.xcworkspace clean archive -archivePath build/BestAppEver xcodebuild -exportArchive -exportFormat ipa -archivePath "build/BestAppEver.xcarchive" -exportPath "build/BestAppEver.ipa" -exportProvisioningProfile "ProvisioningProfileName"
I’m often adding pod install just above first xcodebuild command.
BTW, this post was inspired by the response I’ve got on StackOverflow for quoestion “Make Ad-hoc builds in Xcode 6 without signing in to developer account”.
相关文章推荐
- Building QT projects from the command line
- Xcode4: Running Application Tests From The Command Line in iOS
- 使用命令行工具管理Android项目(Managing Projects from the Command Line)
- Run iOS Simulator from the Command Line (runsim)
- A class file was not written. The project may be inconsistent, if so try refreshing this project and building it. eclipse提示错误
- ios 命令行编译 Build an iPhone app from the command line
- IS12 Changing Project Properties from the Command Line
- A class file was not written. The project may be inconsistent, if so try refreshing this project and building it
- Running Your iOS App in the Simulator From The Command Line
- [转] PhoneGap build with iOS from the command line
- ios xcode Could not load the "MyImage.png" image referenced from a nib in the bundle with identifier "com.mytest.MyProject"
- <iOS>cannot be opened because the project file cannot be parsed. Xcode工程文件打不开..
- Managing Projects from the Command Line(android官网文档)
- 芒果iOS开发之Project/Users/用户名/.../xxx.xcodeproj cannot be open because the project file cannot be parsed
- Creating SQL procedures from the command line
- [SDK学习]Managing Projects from the Command Line
- A class file was not written. The project may be inconsistent, if so try refreshing this project and building it. eclipse提示错误
- How to easily open files and URLs from the command line
- Xcode 8: issue “file xxx.png is missing from working copy” at project building
- ImageMagick Tricks: Web Image Effects from the Command Line and PHP