JBoss.orgCommunity Documentation

Chapter 7. Hybrid Mobile Tools and CordovaSim

7.1. Overview of Hybrid Mobile Tools and CordovaSim
7.1.1. About Apache Cordova
7.1.2. About Hybrid Mobile Tools
7.1.3. About CordovaSim
7.1.4. System Requirements for Hybrid Mobile Tools
7.1.5. System Requirements for CordovaSim
7.1.6. Install Hybrid Mobile Tools and CordovaSim
7.2. Features of Hybrid Mobile Tools and CordovaSim
7.2.1. Features Overview
7.2.2. Create a Hybrid Mobile Project
7.2.3. Enable Cordova Plug-ins for an Application
7.2.4. Manage Cordova Settings of a Hybrid Mobile Project
7.2.5. Run a Hybrid Mobile Application on Devices and Simulators
7.2.6. Manage Hybrid Mobile Project Run Configurations
7.2.7. Export a Hybrid Mobile Project

Apache Cordova is a framework for hybrid mobile application development. It simplifies mobile application development by enabling developers to use device-independent APIs, in place of native code, to access device functionality.

Cordova consists of plug-ins, each providing a wrapper API to gain access to corresponding native device APIs. Cordova APIs are available for a range of device functionality, including cameras, accelerometers, and filesystems. All of the Cordova APIs have a JavaScript interface and native backing code to support a variety of different device operating systems, including iOS and Android.

The JavaScript interface of Cordova APIs provides consistent methods for accessing native device functionality regardless of operating system. Applications using Cordova are written once and packaged using native software development kits (SDKs) to produce hybrid mobile applications.

Cordova applications have a distinctive project structure:

Apache Cordova is an open source project, of which there are various distributions. PhoneGap, in addition to being the originator of Cordova, and IBM Worklight are such distributions.

Hybrid Mobile Tools provides tooling for developing Cordova-based hybrid mobile applications within the IDE. It simplifies the process of getting started with the Cordova technology that can be used for these types of applications and provides workflows for developing Cordova-based hybrid mobile applications.

Hybrid Mobile Tools consists of the Apache Cordova API and wizards, a dedicated editor and actions for developing Cordova-based hybrid mobile applications for iOS and Android operating systems:

Hybrid Mobile Tools, together with CordovaSim, provides an effective hybrid mobile development and testing environment.

CordovaSim is a mobile application simulator. It enables you to view and test Cordova-based hybrid mobile applications through a mobile device simulator.

CordovaSim consists of a device input panel based on an extended version of Apache Ripple, teamed with BrowserSim. The input panel provides the ability to give sample input for device features to the application, such as camera, geolocation and accelerometer data. BrowserSim displays and enables user interaction with the application.

Extensions to the device input panel for CordovaSim include the following:

The overall system requirements of JBoss Tools are applicable for Hybrid Mobile Tools and can be viewed at https://community.jboss.org/wiki/MatrixOfSupportedPlatformsRuntimesAndTechnologiesInJBossToolsJBDS on the JBoss Tools website. But, as reiterated below, there are additional system requirements and restrictions when using Hybrid Mobile Tools.

Hybrid Mobile Tools actions involving iOS and Android require the associated SDKs to be installed on your system.

Note

CordovaSim is a standalone simulator for mobile device operating systems, including iOS and Android. It does not require native SDKs to be installed in order to simulate successfully.

iOS SDK (including simulator)

This is available as part of Apple XCode. For further information see https://developer.apple.com/xcode/ on the Apple website.

Android SDK (including emulator)

This is available as part of Android Development Tools. For further information see http://developer.android.com/sdk/index.html on the Android Developers website. Note that for Android actions in Hybrid Mobile Tools it is only necessary to install the Android SDK, which includes the Android Emulator.

Once downloaded, you must use the included Android SDK Manager to further download necessary APIs and set up Android virtual devices (AVDs).

Once the Android SDK is installed, you need to inform the IDE of its location. In the IDE, click WindowPreferences and select Hybrid Mobile. In the Android SDK Directory field, type the path of the installed SDK or click Browse to navigate to the location. Click Apply and click OK to close the Preferences window.

The overall system requirements of JBoss Tools are applicable for CordovaSim and can be viewed at https://community.jboss.org/wiki/MatrixOfSupportedPlatformsRuntimesAndTechnologiesInJBossToolsJBDS on the JBoss Tools website. But CordovaSim uses BrowserSim and, as reiterated below, there are additional system requirements and restrictions when using BrowserSim on Microsoft Windows operating systems.

BrowserSim depends on WebKit and, consequently, requires Apple Safari to be installed on Microsoft Windows operating systems. Only a 32-bit version of Apple Safari is available for Microsoft Windows operating systems. To work around this restriction for 64-bit Microsoft Windows operating systems, you must set BrowserSim to use a 32-bit JVM when running in 64-bit versions of Eclipse. Note that 32-bit JVM choice is limited to Oracle 32-bit JRE 1.6, JDK 1.6, or JDK 1.7 on Microsoft Windows operating systems because Oracle 32-bit JRE 1.7 is incompatible with Apple Safari.

To set BrowserSim to use a 32-bit JVM, click WindowPreferences. Expand JBoss Tools and select BrowserSim/CordovaSim. Under Select JRE to run BrowserSim, click Select and from the list select a 32-bit JRE or Java developer kit. Click Apply and click OK to close the window.

A project wizard is available to assist you in generating new hybrid mobile applications, as demonstrated in the procedure below. It creates a Cordova project with structure compatible with projects generated by the Cordova command-line interface (CLI).

Procedure 7.1. Create a Hybrid Mobile Project

  1. Click FileNewProject.

  2. Expand Mobile, select Hybrid Mobile (Cordova) Application Project and click Next.

  3. Complete the following fields:

    • In the Project name field, type a name for the project. This value is the name of the directory to be created and in which the source files for the application are stored, for example My_App.

    • In the Name field, type a name by which the hybrid mobile application is to be known. This value is the display text used to represent the application in listings and device home screens, for example My Application.

    • In the ID field, type an ID for the hybrid mobile application. The value is typically a reverse domain-style identifier, for example com.example.myapp, and for applications that are to be distributed through device platform application stores the ID value will be provided by the store.

      Note

      There are restrictions on the ID you can use for an application. IDs must consist only of alphanumeric characters and dots. IDs must begin with an alpha character and contain at least one dot.

  4. By default, the project is created in a subdirectory of the workspace that is named according to the project name. To change the default location, clear the Use default location check box. From the Choose file system list, select the default or RSE (Remote System Explorer) as appropriate. In the Location field, type the path where the project is to be created or click Browse to navigate to the location.

  5. To create the project, click Finish.

During project creation, the wizard imports project dependencies and populates a config.xml file. Once created, the project is listed in the Project Explorer tab and the config.xml file is automatically opened in the Cordova Configuration Editor.

Plug-ins, or features, provide the application with access to the necessary Cordova APIs at runtime. Hybrid Mobile Tools provides actions for installed and removing plug-ins associated with applications, as detailed here.

The Cordova Configuration Editor is available for managing the settings of Cordova projects that are specified in the config.xml file. This editor has four modes: Overview, Platform Properties, Icons & Splash Screen, and config.xml. As described below, the first three modes provide interfaces for configuring the settings specified in the config.xml file and the fourth mode enables direct editing of the file.

The Overview mode details explanatory application information. Within this mode you can specify the name and description of the project, the content source of the application, and author details.

The Platform Properties mode specifies Cordova project functionality, such as features (plug-ins and parameters), preferences and access.

The Icon & Splash Screen mode lists the icon and splash screen images to be used on the various operating systems and resolutions for which the application is being developed.

The config.xml mode provides an editor in which to view and modify the config.xml file directly.

To open the Cordova Configuration Editor for a specific hybrid mobile project, in the Project Explorer tab right-click the config.xml file. Click Open WithCordova Configuration Editor. All changes to the Cordova settings of a project must be saved before the results will take effect. To save, press Ctrl+S.

The Platform Properties mode of the Cordova Configuration Editor enables you to specify the Cordova settings in your hybrid mobile project. Features, parameters, preferences and access can be added and removed as detailed below.

Add a feature

Features are the Cordova API plug-ins required by the application in order to access native APIs at runtime. Examples include Camera, Contacts and Geolocation.

To add a feature, click Add for the Features table. The Cordova Plug-in Discovery wizard opens. Follow the instructions as appropriate for the plug-in source:

To add the feature, click Finish.

Add a parameter

All parameters are associated with a feature and provide information about the specific mapping of Cordova and native APIs.

To add a parameter, from the Features table select an item for which to create a parameter. For the Params table, click Add. In the name and value fields, type the service name and Java class full name (including namespace), respectively. To add the parameter, click OK.

Add a preference

Preferences details the global, cross-platform and platform-specific behaviors for the web view of the hybrid mobile application.

To add a preference, click Add for the Preference table. Complete the name and value fields as appropriate. To add the parameter, click OK.

By default for an application created with the Hybrid Mobile Tools project wizard, the Preferences table has two entries. The fullscreen and webviewbounce elements specify whether the application is fullscreen and bounces when pulled down in iOS devices, respectively. For a full list of available preferences see http://cordova.apache.org/docs/en/edge/config_ref_index.md.html#The%20config.xml%20File on the Apache Cordova website.

Add access

Access entries specify the external network resources to which the application has access, also referred to as whitelisting.

To add an access entry, click Add for the Access table. In the required Origin field, type the URL to which access is granted, using * as a wildcard character. Select the Allow Subdomains and Browser Only check boxes as appropriate. These items enable access to subdomains and cause links to open in browsers rather than the application window, respectively. To add the access entry, click OK.

By default for an application created with the Hybrid Mobile Tools project wizard, the Access table has an entry allowing access to all networks, <access origin="*" />. You are advised to declare access to specific network resources.

Remove a feature, parameter, preference or access

In the appropriate table, select the item to be removed and click Remove. Note that removing a feature also removes the associated parameters.

All changes to config.xml must be saved before the results will take effect. To save, press Ctrl+S.

The Icons & Splash Screen mode of the Cordova Configuration Editor enables you to control the icons and splash screen used by the application on each operating system. Icons are used as the visual representation of the application on different platforms and splash screens are used when the application starts on different platforms. In this mode, icons and splash screens can be added and removed as detailed below.

All changes to config.xml must be saved before the results will take effect. To save, press Ctrl+S.

You can use the actions of Hybrid Mobile Tools to run applications on devices and simulators, as detailed below.

Run on an Android device

In the Project Explorer tab, right-click the project name and click Run AsRun on Android Device. This option calls the external Android SDK to package the workspace project and run it on an Android device if one is attached. Note that Android APIs and AVDs must be installed and the IDE correctly configured to use the Android SDK for this option to execute successfully.

Run on an Android emulator

In the Project Explorer tab, right-click the project name and click Run AsRun on Android Emulator. This option calls the external Android SDK to package the workspace project and run it on the Android emulator. Note that Android APIs and AVDs must be installed and the IDE correctly configured to use the Android SDK for this option to execute successfully.

Run on iOS Simulator

Important

This option is only displayed when using OS X operating systems, for which iOS Simulator is available. For information about iOS Simulator see https://developer.apple.com/xcode/index.php on the Apple Developer website.

In the Project Explorer tab, right-click the project name and click Run AsRun on iOS Emulator. This option calls the external iOS SDK to package the workspace project into an XCode project and run it on the iOS Simulator.

Run with CordovaSim

In the Project Explorer tab, right-click the project name and click Run AsRun with CordovaSim. This opens the application in CordovaSim, which is composed of a BrowserSim simulated device and a device input panel.

Run configurations inform simulators how to run the application associated with a project. Hybrid Mobile Tools generates a default run configuration for a project the first time it is run by a specific simulator. This default run configuration is simulator-specific and named according to the project name. You can create and customize multiple run configurations for your projects using the Run Configurations manager.

The information below details how to manage run configurations using the Run Configurations manger. To open the Run Configurations manger for a project, in the Project Explorer tab right-click the project name and click Run AsRun Configurations. Note that run configurations are organized by simulator within the Run Configurations manager, namely CordovaSim, Android and iOS Simulator.

Create a run configuration

From the list of run environments, right-click the simulator and click New. Complete the fields as appropriate. To save the new run configuration, click Apply.

View and edit a run configuration

From the list of run environments, expand the simulator. This shows a list of the run configurations associated with the simulator.

Details for a run configuration are organized in tabs. All simulators have the same Common tab. These options include where to save the run configuration information and how standard input and output are managed. Additional customizable options vary according to simulator:

To change the value of any variables listed in the tabs, click the appropriate field and edit the content. To save changes, click Apply.

Run an application using a run configuration

From the list of run environments, expand the simulator and select a run configuration. Click Run. This starts the simulator, which runs the application associated with the project using the specified configuration settings.