Showing posts with label Command line build. Show all posts
Showing posts with label Command line build. Show all posts

Thursday, 9 October 2014

Making ad hoc build from command line without signing to developer account in Xcode 6 and iOS 8

It was the first problem I face during the use of xcode 6 first time, how can i share .ipa to my clients for demo purpose? I was unable to share an .ipa without signing Apple developer account. Xcode 6 was asking to sign with Developer account to export an .ipa file. Although I had the developer account details but it was the challenge how to make a adhoc build  without signing developer account.
After lots of Googling and consulting with other friends, I found  an alternate solution to achieve ad-hoc  build without signing developer account, solution is  command line/Terminal, you can create a adhoc build using command line tool and or a terminal on mac system.

Let me share the simplest way to create adhoc build using command line tool.

I note down 3 things to create quickest Xcode 6 build. So get ready for these 3 things before opening Terminal.

1- Project path: it will be required in terminal command as a parameter.

2- scheme name: it will be required in terminal command as a parameter.

3- Provisioning Profile name: it will be required in terminal command as a parameter.

Finding scheme name: Default scheme name is the project name but once verify. scheme name displays next to RUN icon in Xcode that is used to execute the app.

Finding Provisioning Profile name: This parameter value will be exact same as it display in Xcode; Provisioning Profile list under Code Signing Identity in build settings section of Xcode 6.

There are three steps two create build from command line tool

1- Clean project
2- Make Archive
3- Export to .ipa file

 Lets start with first. To clean project we will execute below command in Terminal  and or command line tool of mac system.
xcodebuild clean -project <projectname.xcodeproj> -configuration Release -alltargets

here  <projectname.xcodeproj> will be replace with the project path with .xcodeproj extension 

For example on my system's terminal
ajsharma$
xcodebuild clean -project /Users/ajsharma/Documents/iPad/testApp/testApp.xcodeproj -configuration Release -alltargets

Terminal will show you some process and updates and show you success message regarding project clean.
Lets go for next step to Make an archive using below command

xcodebuild archive -project <projectname.xcodeproj> -scheme <schemename> -archivePath <projectname.xcarchive>

here
<projectname.xcodeproj> will be replace with the project path with .xcodeproj extension 
<schemename> will be replace with the shceme name of the project as I discussed above.

<projectname.xcarchive> will be replace with the project path with .xcarchive extension


For example on my system's terminal
ajsharma$
xcodebuild archive -project  /Users/ajsharma/Documents/iPad/testApp/testApp.xcodeproj -scheme testApp -archivePath /Users/ajsharma/Documents/iPad/testApp/testApp.xcarchive

I used same path for as project Path for archivePath you may change it. So an archive file will be create at same path as project path.

@workspace:
Sorry I forgot to mention important command for those who have configured their projects under a WorkSpace or using pods in their projects.
For those people there would be slightly change in  command to make an archive. But I was not using workspace.

xcodebuild -workspace <projectname.xcworkspace> -scheme <schemename> archive -archivePath <projectname.xcarchive

 here;
<projectname.xcworkspace > will be replace with the project path with .xcworkspace extension.
<schemename> will be replace with the shceme name of the project as I discussed above.

<projectname.xcarchive> will be replace with the project path with .xcarchive extension

Lets go for  final step to Export to .ipa  using below command

xcodebuild -exportArchive -archivePath <projectname.xcarchive> -exportPath <projectname> -exportFormat ipa -exportProvisioningProfile “Provisioning Profile Name”

here
<projectname.xcarchive> will be replace with the project path with .xcarchive extension
<projectname>  will be replace with the project path with out .xcarchive or .xcodeproj extension
“Provisioning Profile Name”  will be replace with the Provisioning Profile Name  as I discussed above.

For example on my system's terminal
ajsharma$
xcodebuild -exportArchive -archivePath /Users/ajsharma/Documents/iPad/testApp/testApp.xcarchive -exportPath /Users/ajsharma/Documents/iPad/testApp/testApp -exportFormat ipa -exportProvisioningProfile TestProvision

If everything works fine the final result screen would be some thing like below text as per my project path.

Moving exported product to '/Users/ajsharma/Documents/iPad/testApp/testApp.ipa'
** EXPORT SUCCEEDED **


You can get the .ipa file from the above path as per your project path at your system and share with your client.

If you have any other best way to create adhoc build without using developer account, please share your comments.