Build Hybrid Sample Apps

To build hybrid apps from the samples directory of the SalesforceMobileSDK-Shared repository, you use forcehybrid and the Cordova command line. You create a hybrid_local or hybrid_remote app and then add the web assets—HTML, JavaScript, and CSS files—and the bootconfig.json file from the Shared repo.

The ContactExplorer sample requires the cordova-plugin-contacts and cordova-plugin-statusbar plug-ins.

The other hybrid sample apps do not require special Cordova plug-ins.

Note

To build one of the sample apps:

  1. Open a command prompt or terminal window.
  2. Clone the shared repo:
    1git clone https://github.com/forcedotcom/SalesforceMobileSDK-Shared
  3. Use forcehybrid to create an app.
    • For platform, enter one or both platform names: “ios”, “android”, or “ios,android”.
    • For application type (or the apptype parameter), enter “hybrid_local”.
  4. Change to your new app directory:
    1cd <app_target_directory>
  5. For each additional Cordova plug-in you want to add, type:
    1cordova plugin add <plug-in repo or plug-in name>

    Go to https://plugins.cordova.io to search for available plug-ins.

    Note

  6. (Optional—Mac only) To add iOS support to an Android project “after the fact”:
    1cordova platform add ios@7.0.1
  7. (Optional—Mac only) To add Android support to an iOS project “after the fact”:
    1cordova platform add android@12.0.1
  8. Copy the sample source files to the www folder of your new project directory.

    On Mac:

    1cp -RL <local path to SalesforceMobileSDK-Shared>/SampleApps/<template>/* www/

    On Windows:

    1copy <local path to SalesforceMobileSDK-Shared>\SampleApps\<template>\*.* www
    If you’re asked, affirm that you want to overwrite existing files.
  9. Do the final Cordova preparation:
    1cordova prepare
  • Android Studio refers to forcehybrid projects by the platform name ("android"). For example, to run your project, select "android" as the startup project and then click Run.
  • On Windows, Android Studio sets the default project encoding to windows-1252. This setting conflicts with the UTF-8 encoding of the forcehybrid Gradle build files. For best results, change the default project encoding to UTF-8.
  • On Windows, be sure to run Android Studio as administrator.

Note