Embedding CordovaLib in your iOS/PhoneGap app project

As you may already know PhoneGap/Cordova 2.x has changed how the framework is referenced in iOS projects. This new approach gives more flexibility and ease of installation but at the same time it has some quirks especially when working in Xcode on multiple projects at the same time. This may actually change in the future releases as you may see there is an active discussion about it on the callback-dev mailing list.

In the meantime I wanted to share how you can quickly change a reference to CordovaLib directly from Xcode. The approach I prefer is to embed CordovaLib under my project directory. This way I can push it to my repository and version control it with my project files.

  1. Copy CordovaLib from/lib/ios/CordovaLib (if you are cloning it from GitHub, CordovaLib can be found directly under root folder) to your Xcode project directory. In my case I copied it into the MyProject subdirectory that is at the same level as MyProject.xcodeproj file. You may also choose a parent directory of MyProject or of course anywhere else you want to have it hosted.
  2. Open your project in Xcode and remove the reference to CordovaLib using the delete button or cmd+backspace.
  3. Right-click on the project root element, select “Add Files to YourProject”… option and choose CordovaLib.xcodeproj file that is under CordovaLib directory you copied in step 1.
  4. Select the MyProject > TARGETS > MyProject > Build Phases tab and add CordovaLib under the Target Dependencies panel.

  5. In the same Build Phases tab expand “Link Binary With Libraries” and add libCordova.a into the list.


Once you are done with the above steps you should be able to rebuild and run your project with embedded CordovaLib.



  • Facebook
  • Twitter
  • DZone
  • LinkedIn
  • Email

12 comments

  1. Whizkid

    Thanks a lot!! You made my day! I am a newbie to PhoneGap and XCode… Was finding it difficult to figure out how to bundle phonegap libs so that the sourcecode could be built on any mac mahcine…

  2. Scott

    Thanks for the post, but I notice your libCordova.a is red as is mine. This keeps me from making an archive. Is there a way to fix this?

    thanks,

  3. Pingback: Another Night of Coding Issues « Comics! Games! Anthropology!
  4. Mark

    Thank you very much! I had to quit Xcode and then restart it in order to get CordovaLib to appear for selection for step 4.

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>