Create Hybrid Apps
Once you’ve installed forcehybrid and the Cordova command line, you’re ready to create functioning hybrid apps.
If you haven’t already set up the required tools, use the following instructions. Or, if you prefer, complete the Set Up Your Mobile SDK Developer Tools Trailhead project and win Trailhead points for your efforts. Afterwards, return here and pick up at Create a Hybrid Mobile SDK App.
Some of the following steps use the sudo
keyword. This keyword is required in Mac OS X if you lack read/write permissions. Omit the sudo
command if you’re sure you don’t need it or if you’re installing on Windows.
-
Make sure that you meet the requirements listed at Development Prerequisites for iOS and Android. Hybrid development requires at least one native environment, which can be either iOS or Android.
-
Open a command prompt or terminal window.
-
Run
cordova -v
. -
If
cordova -v
reports that the command is not found, install the Cordova command line, version 12.0.0 or later: -
Install the forcehybrid npm package:
If you previously installed an earlier version of forcehybrid, be sure to uninstall it before reinstalling forcehybrid.
-
At a command prompt or terminal window, run
forcehybrid create
.- For platform, enter “ios”, “android”, or “ios,android”.
- For application type:
- Specify
hybrid_local
for a Cordova hybrid app that stores its code on the mobile device. - Specify
hybrid_remote
for a Cordova hybrid app that runs a Visualforce app on the server.
- Specify
- Provide your own app name, package name, and organization strings.
- (Hybrid remote apps only) For start page, specify the relative URL of your Apex landing page—for example,
apex/BasicVFPage
.
-
If you’re importing HTML, JavaScript, CSS, or
bootconfig.json
files, put them in your project’s<outputdir>/www/
directory.Do not include
cordova.js
,cordova.force.js
, or any Cordova plug-ins. -
In your project directory, open the
www/bootconfig.json
file in a UTF-8 compliant text editor and replace the values of the following properties:remoteAccessConsumerKey
—Replace the default value with the consumer key from your connected appoauthRedirectURI
—Replace the default value with the callback URL from your connected app
-
cd
to your app’s project directory. The force script prints the directory name to the screen when it has finished creating your project. For example: “Your application project is ready in <project directory name>.” -
For each additional Cordova plug-in you want to add, type:
Go to https://plugins.cordova.io to search for available plug-ins.
-
(Optional—Mac only) To add a second platform “after the fact”:
-
To add iOS support, type:
-
To add Android support, type:
-
-
Type:
to deploy your web assets to their respective platform-specific directories under the
www/
directory.During development, always run
cordova prepare
after you’ve changed the contents of thewww/
directory, to deploy your changes to the platform-specific project folders.
See “The Command-Line Interface” in the Cordova 3.5 documentation for more information on the Cordova command line.