Automating a cordova ios build

One of our customers needed an android and iOS mobile application.  We identified cordova as the technology to be used to develop it.

We had done a cordova/phonegap application earlier for another customer.  When we did that, it was only for android.  Subsequently, we got it running in iOS also (with minimal efforts), but the exercise of building the iOS project was not automated.

This time, I wanted to automate the iOS build process too. 

One of the best practices for cordova projects is not to check-in the contents of platform folder.  Cordova copies over the contents of www folder to the corresponding subfolders of the platform folder during each build.  We wanted to follow this practice.

It is good to create the cordova project right.  Previously, we had used phonegap CLI to create the project and subsequently used cordova commands to build it.  While this works, it is better to stick with one - either phonegap or cordova.   

We chose cordova for the following reasons:

  • config.xml created with cordova is simpler than that created with phonegap.  
  • phonegap CLI creates resources folders/files with default icons for every supported platform.  
  • phonegap CLI build is less flexible compared to cordova (though internally I suspect phonegap uses cordova commands)

[Note:  at the time of writing this, version of cordova is 3.4.1, xcode-5.1.  Needless to say, things change across versions]

Anyway, this is how we created our project

cordova create <folder-name> <package-name> <app-name>

Thereafter all the development happened in www folder.  Here is how we had automated the android build.  The idea was to do a similar exercise for iOS.

iOS differs from android in two ways.

a) iOS app can only be built on a Mac system.  

So the linux system on the cloud running jenkins was not sufficient.  We needed to set up an ios-slave jenkins instance.

b) the creation and distribution of an iOS app is different from android

For android, we could create a release build using cordova CLI and deploy it to Google Play store in alpha/beta testing for testers to play with.

In case of iOS

  • cordova does not provide a mechanism to generate a distribution (ipa) file.  We need to take recourse to some additional native commands (details below).
  • Also, the distribution file thus created cannot be installed through email.  Testflight is the recommended way to do this.
This is how we went about this

Add ios platform

cordova platform add ios

Do a release build for ios

This isn't straightforward as you can see.

One would think, the following would work

cordova build ios --release

But no, this did a release build for the emulator.  The one which did the required code-signing is the following:

cordova build ios --device

After doing a build, the above command attempted to sign the build.  To do this, it needed to pick an appropriate certificate.  It did this based on the information in the file cordova/build.xcconfig inside platforms/ios.

There seemed to be a bug in this file, due to which failed to pick an appropriate certificate.  The fix was to alter the word "Developer" with "Distribution".  

Since we did not want to check-in platform specific file, the way to do this was to add a hook in the hooks folder.  

Now, could we not have used xcodebuild to build the generated xcode project, instead of cordova CLI?  This did not seem to work - at least with xcode 5.1 - without opening the project in xcode and possibly checking in changes to version control.

Essentially xcode project generated by cordova did not contain any scheme.

If xcodebuild had worked, then jenkins xcode plugin would have taken care of automating the build from jenkins.  Now, it was a two-step process, the first step done by cordova and the second, to be done by xcrun.

xcrun -sdk iphoneos PackageApplication -v ${WORKSPACE}/platforms/ios/build/device/my.app -o ${WORKSPACE}/platforms/ios/build/myapp-1.0.${BUILD_NUMBER}.ipa --embed my.mobileprovision --sign "my code signing identity"

This generated an ipa file with the specified provisioning information that allows the devices with UDIDs therein to install the app.

The next step was to upload this to testflight.  This was quite easy, thanks to a combination of testflight API and jenkins testflight plugin.  All it needed was configuring the API and team keys.

Since I did not want all the ios builds to be made available to testflight, I separated the testflight deployment from ios build.  The testflight deployment was a manual item (as a jenkins job is called now), which picked the "latest" ios artifact (using copy artifact plugin) and uploaded to testflight.

[Note:  Artifacts copied using copy artifact accumulate and all of them end up getting uploaded to testflight for each run.  So it makes sense to add a script to delete existing artifacts as the first build step.]

And hey, this is better than the manual upload of artifact that is required to test android app.  Testflight supports android apps also (for now) - maybe I should use that!

My cordova ios project build and release was automated.  And in the entire process, I did not open xcode once.

[Update 3 Feb 2015:  Upload to TestFlight is no longer possible since TestFlight is now Apple and there is no programmatic upload.  As well no android support]

Comments

  1. Hi Raghuram,

    I have tried your command and I was able to create the ipa file. But when I try to install on device it fails. I can confirm that the device uuid is added to the provisioning profile I am using herewith.

    My command is as follows :

    xcrun -sdk iphoneos PackageApplication -v "/Users/ramesh/Downloads/CordovaPrj/platforms/ios/build/device/App Name.app" -o "/Users/ramesh/Downloads/CordovaPrj/release/ios/App_Name_1.0.0.ipa" --embed "/Users/ramesh/Downloads/CordovaPrj/build.tools/my.mobileprovision" --sign "iPhone Distribution: Company Name (B46QVD65GU)"

    could you please help me ?.

    ReplyDelete
  2. Hi, Can you check if you get any error message running the command?

    ReplyDelete
    Replies
    1. actually I don't. I have uploaded my build log here :
      https://drive.google.com/file/d/0B85vUqBPKLOxUGwzdXpPSE90WkE/edit?usp=sharing

      could you please help me out ?.

      Delete
    2. the only error I get is the one when I install the ipa on the iphone. this error was captured using the iphone configuration utility during the ipa installation.

      Jul 9 11:08:44 Rameshs-iPhone librariand[102] : ubiquity account is not configured (or is disabled for this client), not creating collection
      Jul 9 11:08:44 Rameshs-iPhone librariand[102] : error in _handle_client_request: LibrarianErrorDomain/10/Unable to configure the collection.

      Delete
    3. Hi, Stackoverflow is the right place to find a solution for this.

      I see a couple of lines in the log indicating error in codesigning with the message "a sealed resource is missing or invalid", though subsequently it seems to have worked.

      Googling also reveals issues people have had related to "librariand".

      Sorry I can't be of better help. When you do solve the problem, do update this link for others. Thanks.

      Delete
  3. Nice article!

    Can't wait to test this out...!

    ReplyDelete
  4. Thanks for sharing informative article on java application development. Your post helped to understand the career in Java. JAVA Training in Chennai

    ReplyDelete

  5. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
    Regards,
    ccna course in Chennai|ccna training in Chennai

    ReplyDelete
  6. The future of software testing is on positive note. It offers huge career prospects for talented professionals to be skilled software testers. Best software testing training institute in Chennai | Software Testing Training in Chennai | Software testing course in Chennai

    ReplyDelete
  7. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    cloud computing training in chennai | cloud computing courses in chennai

    ReplyDelete
  8. Usually I do not read post on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Great work admin.Keep update more blog.
    Mobile App Development Company
    Android app Development Company
    ios app development Company
    Mobile App Development Companies

    ReplyDelete
  9. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in IOS development, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on IOS development . We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us:
    Name : Arunkumar U
    Email : arun@maxmunus.com
    Skype id: training_maxmunus
    Contact No.-+91-9738507310
    Company Website –http://www.maxmunus.com



    ReplyDelete
  10. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information&its very useful to me...
    Android training in chennai
    Ios training in chennai

    ReplyDelete
  11. Thanks for the Amazing blog... Thanks for sharing
    you can have a look at my blog and suggest some changes if required..

    http://aptronnoida.in/best-erp-sap-training-in-noida.html

    ReplyDelete
  12. I wish to show thanks to you just for bailing me out of this particular trouble.As a result of checking through the net and meeting techniques that were not productive, I thought my life was done.

    Best Java Training Institute Chennai

    Amazon Web Services Training in Chennai


    ReplyDelete
  13. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

    Hadoop training in bangalore

    ReplyDelete

  14. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.

    Embedded training in chennai | Embedded training centre in chennai

    ReplyDelete
  15. This is an incredible post that carries great value. I got so many things to learn from this. Thanks for the post!
    sap abap online training in usa

    ReplyDelete
  16. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 
    Devops training in velachry
    Devops training in OMR
    Deops training in annanagar
    Devops training in chennai
    Devops training in marathahalli
    Devops training in rajajinagar
    Devops training in BTM Layout


    ReplyDelete
  17. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.

    ccna training in chennai



    ccna training in bangalore


    ccna training in pune

    ReplyDelete
  18. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    java training in chennai | java training in bangalore

    java training in tambaram | java training in velachery

    java training in omr

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete

  20. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.

    angularjs Training in bangalore

    angularjs Training in btm

    angularjs Training in electronic-city

    angularjs Training in online

    angularjs Training in marathahalli

    ReplyDelete
  21. Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision. 
    python training in OMR
    python training in tambaram
    python training in annanagar

    ReplyDelete
  22. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    Devops Training in pune

    ReplyDelete
  23. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
    Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune | Selenium online Training

    ReplyDelete
  24. myTectra Placement Portal is a Web based portal brings Potentials Employers and myTectra Candidates on a common platform for placement assistance

    ReplyDelete
  25. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    rpa training in velachery| rpa training in tambaram |rpa training in sholinganallur | rpa training in annanagar| rpa training in kalyannagar

    ReplyDelete
  26. You rock particularly for the high caliber and results-arranged offer assistance. I won't reconsider to embrace your blog entry to anyone who needs and needs bolster about this region.
    fire and safety course in chennai

    ReplyDelete
  27. I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post I would like to read this

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in btm

    ReplyDelete

Post a Comment