Join Chris Griffith for an in-depth discussion in this video Building from the command-line interface, part of Up and Running with PhoneGap Build.
Another popular method for creating PhoneGap applications is to use the command line interface, or CLI. This tool is built using OJS, and allows users a fast method to bootstrap their PhoneGap projects, compile and run their applications with locally installed SDKs, and the ability to use PhoneGap Build servers to compile their applications. Let me show you a little what PhoneGap see what I can do. I have my terminal window open. And I now need to change my working directory to the samoca_cli directory on desktop. To use the CLI on Windows machine, command line is available as Command Prompt under Accessories.
The commands are the same regardless of the operating system. So, I'm going to change my working directory to the SAMOCA_CLI. And by simply dragging, dropping that directory on to the terminal window, it actually will resolve the working path for me. Now that I've changed my working path to that SAMOCA_CLI directory, I can now use the PhoneGap Create command to actually create a PhoneGap skeleton application for me that I can use. So to do that, we will type in phonegap create.
And then we're going to have it create this within a samoca directory. And then we were going to use the app id as well, we need to identify. So this will be com.ajsoftware.lynda samoca. And the PhoneGap will now create that project. Let's take a look at it. So, you can see, it has created a smoker directory for us. And inside there, it has created four other directories: mergers, platforms, plugins and a www directory.
By default, PhoneGap Create Script has generated a skeleton, web based application for us. Our primary source files will be located within the ww directory, as you can see at the bottom of this list. If we use any plugins for our applications, and it's quite likely we will, their code will be located in the plugins directory. If we're building locally, each platform that you target will have its resources stored within the platforms directory. The merges directory offers a place to specify assets to deploy on specific platforms. Each platform specific sub-directory within mirrors the directory structure of the www source tree, allowing you to override or add files as needed.
I've now switched back to the terminal application. I again need to change my working directory to within that SAMOCA directory that we just created. So, that is done with a cd samoca. And to make sure that we're there, I will use the Unix command ls, to list out the directory. There. Now our files are properly in place, we can now use the command line interface to actually take our application, and load it up to the PhoneGap Build server. But first, let's replace the skeleton app with our samoca app.
Let's go ahead and just move that to the trash. And now, let's go ahead and copy over our samoca test files into this WWW folder. Great. Now we have our application within the CLI generated structure that we can use. Now let's return back to the terminal. Although typically, the use of the CLI will be with locally installed copies of each platform's SDK, we can still use PhoneGap Build to compile our native applications for us. To sign into the PhoneGap Build system, we'll use the following command.
Phonegap, remote, login, u. Now, u, after this, will be your username. Space -p. And then finally, your password. And then press Return. We've now logged into the PhoneGap system. Now that we've signed into the service, we can instruct PhoneGap Bbuild to build our application. Type in phonegap remote build.
But don't hit anything yet. Unlike the other systems, say, within Dreamweaver or Edge Code or uploading through a zip file or GitHub, where they build for all platforms, the CLI will build platform by platform. So, we must specify which platform we want the PhoneGap Build system to build for us. So, in this case, let's go ahead and just build for Android. So, I will go ahead and add space, android. And this will now compress and send the files up to the PhoneGap system and create an Android application for us.
And now the PhoneGap CLI has compressed the app, it's now uploading, and in a moment, PhoneGap Build will be building it. It is possible to have the terminal generate a QR code that we can scan and download and install our app. But I find it more useful to have the PhoneGap Build site up, to download and install the compiled application from there. Well, having access to PhoneGap Build via command line interface is more useful, is that the build process can now be integrated into various automated build tools, like Grunt. Thus, streamlining your tool with workflow.
So, with those few simple commands, we can create, upload, and compile our PhoneGap application, all from the command line.
- Creating a PhoneGap Build account
- Exploring the HTML structure of an app
- Configuring your mobile device for development
- Building from Dreamweaver, Edge Code, or the command line
- Setting up a config.xml file
- Setting parameters and permissions
- Deploying on iOS or Android