Using Forcehybrid

For creating hybrid apps, Mobile SDK provides the forcehybrid npm utility. This utility works with the Cordova command line to build hybrid Mobile SDK projects. With forcehybrid, you can create hybrid projects for iOS, Android, or both in a single pass.

Forcehybrid gives you two ways to create your app.

  • Specify the type of application you want, along with basic configuration data.

    OR

  • Use an existing Mobile SDK app as a template. You still provide the basic configuration data.

You can use forcehybrid interactively at the command line, or in script mode with command line parameters. To see usage information, type forcehybrid without arguments.

To enter application options interactively at a command prompt, type forcehybrid create. The forcehybrid utility then prompts you for each configuration option. For example:

This example creates a hybrid local app named “LocalHybridTest” in the ./LocalHybridTest/ directory, with iOS and Android targets.

Although forcehybrid create sets up hybrid projects for the platforms you specify, the app isn’t ready for building until you’ve finished the setup at the Cordova command line. See Create Hybrid Apps

In script mode, you enter your parameters in a single command line instruction:

This example creates a hybrid local app named “packagetest” in the ./PackageTest/ directory, with iOS and Android targets. Here’s a description of the available options.

The forcehybrid createWithTemplate command is identical to forcehybrid create except that it asks for a GitHub repo URI instead of an app type. You set this path to point to any repo directory that contains a Mobile SDK app that can be used as a template. Your template app can be any supported Mobile SDK app type. The force script changes the template’s identifiers and configuration to match the values you provide for the other parameters.

Before you use createWithTemplate, it's helpful to know which templates are available. To find out, type forcehybrid listtemplates. This command prints a list of templates provided by Mobile SDK. Each listing includes a brief description of the template and its GitHub URI. For example:

Once you've found a template's URI, you can plug it into the forcehybrid command line. Here’s command line usage information for forcehybrid createWithTemplate:

For any template in the SalesforceMobileSDK-Templates repo, you can drop the path for templaterepouri—just the template name will do. For example, consider the following command line call:

This call replicates the hybrid local template app. It recreates the app in the current directory with the same source code and resources as the template app. Forcehybrid changes the app name to “MyHybrid” throughout the project. (This createwithtemplate call is equivalent to creating a hybrid_local app with forcehybrid.)

The forcehybrid script

  • Generates apps with the Cordova command line.
  • Downloads the template app and a bootconfig.json file from GitHub.
  • Downloads the SalesforceMobileSDK Cordova plugin from GitHub. This plugin delivers the Mobile SDK libraries as Android and iOS library projects.