Shazron's Cordova (aka PhoneGap) Blog

at Adobe Systems Inc.

Creating a PhoneGap project from the command line (for Xcode 4)

with 66 comments

UPDATE: PhoneGap 0.9.5.1 includes the Xcode 4 template now, download it from phonegap.com

Currently the PhoneGap installer for iOS does not create an Xcode 4 template. The issue is tracked here.

I’ve created a shell script to create a PhoneGap project from the command line. You will still need PhoneGapLib installed – download the installer from http://phonegap.com and run it first.

Instructions are in the shell script itself (open it up in a text editor). View the script, then File -> Save As… to save it. [For Cordova - replace occurrences of 'PhoneGap' in the value for the path with 'Cordova': https://github.com/apache/incubator-cordova-ios/blob/1.0.0/create_project.sh#L41]

Cameron Perry has a good post about using PhoneGap with Xcode 4 that might solve some problems users might have.

Written by shazron

March 16, 2011 at 1:06 am

Posted in phonegap, xcode

66 Responses

Subscribe to comments with RSS.

  1. Thanks Shazron.

    Steve Greenley

    March 16, 2011 at 1:16 am

  2. Hi Shazron,

    many thanks!

    Still a few questions. What are the parameters and ?

    Please give an example for these parameters.

    Arno Hofmann

    March 16, 2011 at 5:59 am

    • I’ve mentioned it in the blog post itself. Open up the script in a text editor, or view the script using the link above. Should explain itself.

      shazron

      March 16, 2011 at 6:32 am

  3. Good stuff. Thanks! I was just about to start on the FileTransfer stuff and realised I’d wiped my XCode 3 install when installing 4, so couldn’t create a new project. Oops.

    Matt Kane

    March 16, 2011 at 8:05 am

  4. Worth noting: the project path needs to be absolute, or it goes into a loop until dying with a “File name too long” error.

    Matt Kane

    March 16, 2011 at 8:12 am

    • thanks Matt, I’ll modify the script soon to convert paths to absolute.

      shazron

      March 16, 2011 at 9:09 am

      • Updated.

        shazron

        March 16, 2011 at 9:27 am

  5. But what is the PATH_TO_PUT_NEW_PROJECT?

    /Library/Developer/Xcode/Templates/Project Templates/Application/

    or

    /Library/Developer/Xcode/Templates/Project Templates/Framework & Library/

    Sorry I’m a beginner with Xcode and PhoneGap.

    Arno Hofmann

    March 16, 2011 at 11:16 am

  6. Neither. It’s the folder where you want your new project to be created. e.g ~/Documents/

    Matt Kane

    March 16, 2011 at 11:18 am

  7. thanks Matt, now I understood!

    Arno Hofmann

    March 16, 2011 at 11:26 am

  8. When the script creates the project, it creates 2 xcode projects (one is an ipad one?). When I open the project it has errors. Missing files; PhoneGapLib.xcodeproj

    Barry

    March 16, 2011 at 8:47 pm

    • @barry in the edge code, the iPad one has been deprecated so you can ignore that. I’ve replied to your other comment regarding the errors.

      shazron

      March 17, 2011 at 12:57 am

  9. When the script creates the project, it creates 2 xcode projects (one is an ipad one?). When I open the project it has errors. Missing files; PhoneGapLib.xcodeproj, VERSION. When I build, it complains that:

    Missing dependency target “PhoneGapLib (from PhoneGapLib.xcodeproj)”
    head: /VERSION: No such file or directory
    cp: /javascripts/phonegap.*.js: No such file or directory

    I have xcode4 and phonegap 0.94 installed. Any ideas on how to get this to work?

    Barry

    March 16, 2011 at 8:50 pm

    • @barry don’t know what’s happening, I tested using the latest edge code. Please post your issue in the PhoneGap Google Groups with more info and possibly screenshots. We can discuss this there.

      shazron

      March 17, 2011 at 12:54 am

  10. I tried your script, but when I compile my project (without any modification) I get several warnings and 3 errors (missing “VERSION” file and others).

    Has this actually worked for anybody else?

    Felipe

    March 16, 2011 at 9:29 pm

    • @felipe let’s discuss this issue where you can post more info, and screenshots – in the PhoneGap Google Groups.

      shazron

      March 17, 2011 at 12:52 am

  11. How do I use it ? chmod doesn’t work for me. I am completely new to this environment. Can you please provide a step by step guideline ?

    kunal

    March 16, 2011 at 9:38 pm

    • If you don’t have chmod installed, there are are other things going on that are outside the scope of my work here. You can post this issue on the Google Group, or Apple’s forums regarding chmod, which comes standard on OS X.

      shazron

      March 17, 2011 at 12:55 am

  12. Hi Shazron,

    thanks for the script, it appeared to work, however I got a build error “[BEROR]No architectures to compile for (ARCHS=i386, VALID_ARCHS=armv6 armv7).”
    which was fixed by adding “i386″ to the existing “arm6 arm7″ at path
    PhoneGapLib -> Build Settings -> Valid Architectures

    Ben

    March 16, 2011 at 11:41 pm

  13. Same issue as Barry and Felipe…

    James

    March 17, 2011 at 4:08 pm

    • @james thanks. need more info (barry and felipe haven’t replied from what I’ve seen on the PhoneGap Google Group), so if you can post it there

      shazron

      March 17, 2011 at 4:10 pm

  14. i posted some screens on this error from barry and felipe!!!

    Google Groups
    Xcode4 – shellscript – Strange Error during compiling

    ty as u see i have the same issue. :(

    neo2freaks

    March 17, 2011 at 4:39 pm

  15. here the screens if u cant wait. :)

    neo2freaks

    March 17, 2011 at 4:40 pm

    • @neo2freaks thanks for posting the screens. Looks like PhoneGapLib is missing. Check that there is a PhoneGapLib folder in your Documents folder. Can you also package up your project, so I can download and check it out?

      shazron

      March 17, 2011 at 4:44 pm

  16. My Project

    http://dl.dropbox.com/u/3979606/project1.zip

    And the PhoneGapLib folder im finder. :)

    neo2freaks

    March 17, 2011 at 5:00 pm

    • thanks! I’ll continue with the reply on the Google Group.

      shazron

      March 17, 2011 at 5:03 pm

  17. Why don’t phonegap recompile their package again? I lost with new path project. Do you mean the phonegap project that I just install .

    Or mean project that we create a new project for each application.

    sam

    March 17, 2011 at 6:18 pm

  18. [...] Este artigo ainda não testei… [...]

  19. [...] you’re not seeing the XCode templates when you go through the new project menus. Check out Shazron’s blog @ Nitobi for a command-line script to get you a new project up and running. It’s not as sexy [...]

  20. Seems like neo2freaks’s project1 zip is good solution for now, with dragging Phonegalib.xcodeproj to project and setting valid architecture gets you rolling. :)

    Kunal

    March 18, 2011 at 3:01 pm

  21. Still shows error for .js not found in javascript folder. and 2 other erros for VERSION file.

    cssninja

    March 18, 2011 at 3:07 pm

  22. i’m happy that my files can help you. @Kunal ;)

    neo2freaks

    March 18, 2011 at 3:17 pm

  23. When PhoneGap setup fully functional with xcode4 will be available ??

    kunal

    March 18, 2011 at 3:56 pm

  24. wouldn’t kill you to post link to actual google groups discusion when you are moving conversation there …

    user

    March 23, 2011 at 11:48 pm

  25. Hi, it works great on simulator but not on real device, it only says : “Build failed” without any other output…

    michelangelog

    March 24, 2011 at 11:16 am

  26. I’m having the same errors as barry and felipe. Any idea what is causing it?

    Connor

    March 26, 2011 at 12:20 am

  27. the solution is downgrade, it is not a joke

    serkan

    March 26, 2011 at 12:57 am

  28. I found out that the compile errors are created by the compile shell scripts.

    if you go to “Build Phases” you have a “touch www folder” and a “copy phonegap javascript” item. Those are shell scripts that copy files into your project folder.

    the problem is in the ${PHONEGAPLIB} var that is used in those scripts. In a weird way the scripts don’t use the value correct, even if you added the PHONEGAPLIB in the source trees…

    Stefan

    March 30, 2011 at 11:36 am

  29. can anyone upload working phonegap xcode4 project?

    user

    March 30, 2011 at 12:55 pm

  30. Thanks Shazron!

    Kelton

    March 30, 2011 at 7:27 pm

  31. For me it took:

    – run the script (./create_project.sh myProject myProjectsFolder)
    – open the myProject.xcodeproject file in xcode 4
    – open preferences (CMD-,)
    – Select “Source Trees” (with the yellow icon at the top)
    – hit the + button
    – enter ‘PHONEGAPLIB’ for the setting name
    – enter any display name
    – enter the **full path** to ~/Documents/PhoneGapLib, which will be /Users/something/Documents/PhoneGapLib
    – Close Preferences Window.
    – Select an iPhone Simulator from the drop down in xcode, beside the stop button
    – Click run.

    The iPhone Simulator should pop up, and open your project with a blank white scree.

    Type something in the body tag in www/index.html in your project to change that.

    The FAQ at https://github.com/phonegap/phonegap-iphone/blob/master/README.md is also helpful, look at it.

    Hope that helped somebody, should by the looks of some of the comments.

    D

    dara

    April 4, 2011 at 2:51 pm

  32. I have this problem, i have tried all the solutions, especially the Dara’s solution but it don’t work …
    This is my problem, could you help me please ?

    http://img541.imageshack.us/i/capturedcran20110406190.png/

    Cclleemm

    April 6, 2011 at 5:09 pm

  33. i used the shell script to create project, and also added the source tree var, as described above. BUT i still am getting the ‘phonegaplib dependency error’ on compile… any thoughts?

    erik

    April 11, 2011 at 5:39 pm

  34. I just wanted to say that Dara’s solution worked like a charm for me with Xcode 4 and PhoneGap 0.9.4.

    Thanks Dara!

    Zach Karpinski

    April 12, 2011 at 1:24 pm

  35. Dara, thank you!
    I wasted a lot of times, then set the PHONEGAPLIB values to full path without “~” it works!!!

    Bruno

    April 13, 2011 at 9:45 am

  36. Thanks so much Dara :)
    work well now

    Reem

    April 13, 2011 at 12:37 pm

  37. When I click on the .xcodeproj file, I don’t get an editor. I’m using the latest version of XCode4 and the latest version of phonegap.

    Jeff Heard

    April 13, 2011 at 12:39 pm

  38. Dara +1, cool solution!
    A reminder that change ‘something’ to your mac username.

    Thanks Dara!

    Ray Ling

    April 13, 2011 at 4:17 pm

  39. I’ve successfully used the script, but I would like to create an XCode4/Phonegap project with XCode 4’s git integration enabled (ie. not install git separately but do the equivelant of checking the box when creating a new non-Phonegap project). Is this possible using the script? Thanks, N.

    Nick

    April 14, 2011 at 4:39 pm

  40. Thanks man, needed this.

    Joe McCann

    April 14, 2011 at 8:02 pm

  41. @dara am try ur steps but i have this error

    ld: library not found for -lPhoneGapLib
    collect2: ld returned 1 exit status
    Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

    omar muwahed

    April 17, 2011 at 1:14 pm

  42. TWiT Commander

    April 20, 2011 at 1:49 pm

  43. I’m unable to use the script. Nothing gets created and I get the following error in terminal. Any ideas?

    xargs: unterminated quote
    Error 1, exiting.
    Cleaning up…

    Dave

    April 23, 2011 at 6:37 pm

  44. Update:
    Nitobi is providing a web service to generate Xcode templates for iOS PhoneGap projects: https://build.phonegap.com/generate

    Also, the issue tracker has moved from LighthouseApp to Github Issues.

    shazron

    April 25, 2011 at 7:02 pm

  45. Why do people like Shazron post so much open shit software? Neither the script or the website work.

    open shit software

    May 2, 2011 at 9:29 pm

  46. Dara: thanks, your instructions worked perfectly for me.

    paul

    May 3, 2011 at 4:52 pm

  47. Another thing: IF I WANTED TO PROGRAM BY EMBEDDING A BROWSER IN MY FUCKING APPS, I’D FUCKING USE A WEBVIEW NATIVELY. PHONEGAP IS THE BIGGEST PIECE OF SHIT I’VE EVER SEEN. GTFO WITH YOUR “CROSS PLATFORM” BULLSHIT. ANYONE CAN CREATE A WEBSITE AND POINT A BROWSER TO IT.

    open shit software

    May 3, 2011 at 4:53 pm

  48. [...] out that PhoneGap’s support for Xcode 4 is still work in progress. I used Sharon Abdullah’s script which creates an Xcode 4 PhoneGap project from the command line. Then I copied my Calc application [...]

  49. @shit Thanks for the kind words, shit (if that’s your real name that is). Oh, I think your caps lock key is broken?

    shazron

    May 5, 2011 at 11:18 pm

  50. Plz help,

    I am trying to use ‘PhoneGap Framework’ for creating webapps for Iphone. I have installed this framework in XCode 3.2 and it simply works fine. But I try same thing in XCode 4.0 it doesn’t and I need to complete the same task in XCode 4.0.

    Steps which I have done till now to install ‘PhoneGap’ framework in XCode 4.0:-

    1- I downloaded the ‘PhoneGap’ framework from ‘http://www.phonegap.com/download and installed it on my system. (Tried atleast 5 times)’.

    2- But the ‘User Template’ didn’t appeared when creating New Project, So I tried to achieve this using the Command script, which I downloaded it from ‘http://blogs.nitobi.com/shazron/wp-content/uploads/2011/03/create_project.sh1.zip’

    3- I ran this script using the command ‘./create_project.sh PhoneGapDemo /Users/patni/Desktop/’ from terminal, But gives the error
    ‘PhoneGapLib is not installed. Download the iOS PhoneGap installer from http://phonegap.com. Go there now (y/n)?’

    4- I don’t understand why this error is coming, although I have installed the ‘PhoneGap’ framework properly,
    When PhoneGap is installed in my system following files has been created:-
    i- com.apple.Xcode.plist in the folder ‘~/Library/Preferences/’,
    ii- ‘PhoneGapLib’ library got created in ‘~/Documents’ folder, &
    iii- XCode template ‘PhoneGap’ in ‘~/Library/Application Support/Developer/Shared/Xcode/Project Templates/’ folder.

    Please correct me if I am wrong, or plz let me know is it possible to install & use ‘PhoneGap’ framework in XCode 4.0.

    Waiting for reply,

    Thanks,
    mobileAppMaster

    mobileappmaster

    May 9, 2011 at 10:52 am

  51. is there any place i can download the script from ? all links are broken !

    thanks in advance

    t23d

    March 23, 2012 at 7:08 pm

    • shazron

      March 23, 2012 at 7:12 pm

      • thanks!!!!!!!!

        t23d

        March 23, 2012 at 7:15 pm

      • hello, when i run the script, i open the project in xcode and don’t get a run option, it’s greyed out. am i missing something?

        t23d

        March 28, 2012 at 2:25 pm

  52. Thanks for the information. Also try Long Path Tool. It helped me with Error 1320 on Win 7. :)

    GarryBrown

    March 12, 2013 at 10:17 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 1,490 other followers

%d bloggers like this: