On the Mac, the command-line is available via the Terminal application. On the PC, it's available as Command Prompt underAccessories.
The more likely it is that you run the CLI from different machines, the more it makes sense to maintain a remote source code repository, whose assets you pull down to local working directories.
To install the
phonegap
command-line tool, follow these steps:- Download and install Node.js. Following installation, you should be able to invoke
node
ornpm
on your command line. - Install the
phonegap
utility. In Unix, prefixing the additionalsudo
command may be necessary to install development utilities in otherwise restricted directories:$ sudo npm install -g phonegap
The installation log may produce errors for any uninstalled platform SDKs. Following installation, you should be able to runphonegap
on the command line.
Create the App
Go to the directory where you maintain your source code, and run a command such as the following:
$ phonegap create hello com.example.hello HelloWorld
The first argument specifies a hello directory to be generated for your project. Its
www
subdirectory houses your application's home page, along with various resources under css
, js
, and img
, which follow common web development file-naming conventions. The config.xml
file contains important metadata needed to generate and distribute the application.
The other two arguments are optional: the
com.example.hello
argument provides your project with a reverse domain-style identifier, and the HelloWorld
provides the application's display text. The -i
and -n
command-line options and their corresponding flags make these explicit: $ phonegap create hello -n HelloWorld -i com.example.hello
$ phonegap create hello --name HelloWorld --id com.example.hello
Alterately, you can edit both of these optional values in the
config.xml
file later during development.Build the App
All subsequent commands need to be run within the project's directory, or any subdirectories within its scope:
$ cd hello
By default, the
phonegap create
script generates a skeletal web-based application whose home page is the project's www/index.html
file, with its default logic referenced from www/js/index.js
. Edit this application however you want, but initialize it as part of a deviceready
event handler, which executes once device APIs become available.
The
build
command compiles an application for whichever platform you specify, identified by common stub arguments, generating platform-specific files within the project's platforms
subdirectory. For example, the following targets iPhone and iPad devices: $ phonegap build ios
[phonegap] detecting iOS SDK environment...
[phonegap] using the local environment
[phonegap] compiling iOS...
[phonegap] successfully compiled iOS app
High-level information on the command's progress displays as feedback. If you need lower-level details, use the
-V
(verbose) option: $ phonegap -V build ios
No comments:
Post a Comment