Creating an Apache Cordova Project

To create projects for use with Kapsel, use the Cordova command line tool.

Prerequisites
Set up your development environment.
Task

You must run the commands from a Windows command prompt, or a terminal window on iOS. See http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface.

  1. Create a folder to hold your Kapsel Cordova projects.
    For example, on Windows, C:\Documents and Settings\<your_account>\Kapsel_Projects, or on OS X, ~/Documents/Kapsel_Projects.
  2. Open a Windows command prompt or terminal and navigate into the project folder you created.
  3. At the command prompt, enter:
    On Windows: cordova -d create <Project_Folder> <Application_ID> <Application Name>
    On Mac: cordova -d create ~<Project_Folder> <Application_ID> <Application Name>
    The -d flag indicates debug output and is optional.
    This may take a few minutes to complete, as an initial download of the template project that is used is downloaded to C:\Users\user\.cordova on Windows, or ~/users/user/.cordova on Mac.
    The parameters are:
    • (Required) <Project_Folder> – the directory to generate for the project.
    • (Optional) <Application_ID> – must match the Application ID as configured on SAP Mobile Platform Server for the application, which is reverse-domain style, for example, com.sap.kapsel.
      Note: <Application_ID> cannot be too simple. For example, you can have "a.b" for an ID, but you cannot have "MyApplicationId." The ID is used as the package name (name space) for the application and it must be at least two pieces separated by a period, otherwise, you will get build errors.
    • (Optional) <Application_Name> – name for the application.

    In this example, you create a project folder named LogonDemo in the Kapsel_Projects directory. The Application ID is "com.mycompany.logon" and the application name is "LogonDemo." Running cordova -d allows you to see the progress of the project creation.

    cordova -d create ~\Kapsel_Projects\LogonDemo com.mycompany.logon LogonDemo
    Your new project includes scripts to build, emulate, and deploy your application.
    Note: All of the Cordova command line interface commands operate against the current folder. The create command creates a folder structure for your Cordova projects while the remaining commands must be issued from within the project folder created by create.
  4. To add the platform, change to the folder you created in the previous step:
    cd <~Project_Name>
    This OS X example adds the Android and iOS platforms, creating both an Xcode project and an Android project.
    cd ~\Kapsel_Projects\LogonDemo 
    cordova platform add ios android 
    Note: Android is supported on both Windows and OS X, but iOS is supported only on OS X.
    Note: You must add the platform before you add any Kapsel plugins.
    The project directory structure is similar to this:
    LogonDemo/
    |--.cordova/
    |-- merges/
    | |-- android/
    | `-- ios/
    |-- platforms/
    | |-- android/
    | `-- ios/
    |-- plugins/
    |-- www/
       -- config.xml
    `
    • .cordova – identifies the project as a Cordova project. The command line interface uses this folder for storing its lazy loaded files. The folder is located immediately under your user’s home folder (On Windows, c:\users\user_name\ , and on Macintosh, /users/user_name/.cordova).
    • merges – contains your Web application assets, such as HTML, CSS, and JavaScript files within platform-specific subfolders. Files in this folder override matching files in the www/ folder for each respective platform.
    • www – this folder contains the main HTML, CSS, and JavaScript assets for your application. The config.xml file contains meta data and native application information needed to generate the application. The index.html file is the default page of the application. Once you finish editing your project's files, update the platform specific files using the cordova -d -prepare command.
    • platforms – native application project structures are contained in subfolders for the platforms you added to your application.
  5. (Optional) You can test your Cordova project by opening it in the respective development environment, for example, Xcode or Eclipse with the ADT plugins, and running it on the simulator or emulator.
  6. Add the plugins. For example, to add the Cordova console plugin and the Kapsel Logon plugin on Windows, enter:
    cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git
     cordova -d plugin add C:\SAP\MobileSDK3\KapselSDK\plugins\logon 
    Note: The path you enter to the Kapsel plugin must be the absolute path (not relative path).
  7. Edit the Web application content in the project's www folder and use the cordova prepare command to copy that content into the Android and iOS project folders:
    cordova -d prepare android
    cordova -d prepare ios
Related tasks
Adding the AppUpdate Plugin
Adding the Logon Plugin
Adding the AuthProxy Plugin
Adding the Logger Plugin
Adding the Push Notification Plugin
Adding the EncryptedStorage Plugin
Adding the Settings Plugin
Related reference
Setting Up the Development Environment