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.
Using forcehybrid create Interactively
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.
1$ forcehybrid create
2Enter the target platform(s) separated by commas (ios, android): ios,android
3Enter your application type (hybrid_local, hybrid_remote): <press RETURN>
4Enter your application name: LocalHybridTest
5Enter your package name: com.myhybrid.ios
6Enter your organization name (Acme, Inc.): BestApps.com
7Enter output directory for your app (leave empty for the current directory): LocalHybridTestUsing forcehybrid create in Script Mode
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.
1$ forcehybrid create --platform=ios,android --apptype=hybrid_local --appname=packagetest
2--packagename=com.test.my_new_app --organization="Acme Widgets, Inc."
3--outputdir=PackageTest1Usage:
2
3# create ios/android hybrid_local or hybrid_remote mobile application
4forcehybrid create
5 --platform=Comma separated platforms (ios, android)
6 --apptype=Application Type (hybrid_local, hybrid_remote)
7 --appname=Application Name
8 --packagename=App Package Identifier (e.g. com.mycompany.myapp)
9 --organization=Organization Name (Your company's/organization's name)
10 [--startpage=App Start Page (The start page of your remote app. Only required for hybrid_remote)]
11 [--outputdir=Output Directory (Leave empty for current directory)]Using forcehybrid createWithTemplate
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:
1Available templates:
2
31) Basic hybrid local applicationforcehybrid createwithtemplate
4 --templaterepouri=HybridLocalTemplate
52) Basic hybrid remote applicationforcehybrid createwithtemplate
6 --templaterepouri=HybridRemoteTemplateOnce 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.)
1# create ios/android hybrid_local or hybrid_remote mobile application from a template
2forcehybrid createWithTemplate
3 --platform=Comma separated platforms (ios, android)
4 --templaterepouri=Template repo URI
5 --appname=Application Name
6 --packagename=App Package Identifier (e.g. com.mycompany.myapp)
7 --organization=Organization Name (Your company's/organization's name)
8 [--outputdir=Output Directory (Leave empty for current directory)]1forcehybrid createWithTemplate
2--platform=android
3--templaterepouri=HybridLocalTemplate
4--appname=MyHybrid
5-—packagename=com.mycompany.hybridlocal
6--organization="Acme Software, Inc."How the Forcehybrid Script Generates New Apps
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.