For up-to-date product documentation, see the IBM MobileFirst Foundation Developer Center.
Create a new Cordova app without the MobileFirst template
We can create a new Cordova app that contains MobileFirst features with a few simple commands.
Before you begin
- You must have Cordova development tools installed. This example uses the Apache Cordova CLI. If we use other Cordova development tools, some of your steps will be different. Refer to our Cordova tool documentation for instructions.
- You must have the IBM MobileFirstâ„¢ Platform Command Line Interface (CLI) installed. For more information, see Install the MobileFirst Platform CLI.
- You must have internet access.
- You must have node.js version 4.0.0 or later installed.
You enter all of the commands in the following steps from your command window.
Procedure
- To initially create your Cordova application, enter cordova create AppName where AppName is the name of the application that you are creating. For example, the following command creates an application named MyApp:
cordova create MyApp
Important: We can optionally include a MobileFirst template when you initially create your app. In this case, some Cordova plug-ins are added for you automatically. For more information, see Create a new Cordova app with the MobileFirst template.
- Enter cd AppName to change to the root directory of your new app.
- To add platforms to our app, enter cordova platform add platform where platform is ios, windows, or android, or any combination of these platforms.
Important: Verify that the version of the platform that you add is supported by IBM MobileFirst Platform Foundation. For a list of minimum supported platform version levels, see Supported Cordova components for MobileFirst cross-platform apps. The latest available platform versions will be downloaded by default with the commands described in this step. To download a previous version of a platform, specify the version number by using the syntax cordova platform add platform@version. For example: cordova platform add windows@4.3.0. For example, the following command adds the iOS, Android, and Windows platforms:
cordova platform add ios android windows
- To add the IBM MobileFirst Platform Foundation SDK plug-in, enter cordova plugin add cordova-plugin-mfp.
Note: If we used the MobileFirst template when you created your app, you do not have to complete this step because the cordova-plugin-mfp plug-in has already been added to our app.
- To add additional Cordova plug-ins for MobileFirst, enter cordova plugin add plugin where plugin is one of the following:
- cordova-plugin-mfp-push
- cordova-plugin-mfp-jsonstore
- cordova-plugin-mfp-fips
- cordova-plugin-mfp-encrypt-utils
For example, the following command installs MobileFirst FIPS 140-2 for Android and JSONStore support:
cordova plugin add cordova-plugin-mfp-fips cordova-plugin-mfp-jsonstore
- Optional: Add other Cordova plug-ins that might be used by your app. For more information see The Command-Line Interface ("Add Plugin Features" section) on the Apache Cordova web site.
For example, to add the Cordova whitelist plug-in:
cordova plugin add cordova-plugin-whitelistOr, for example, to add the CrossWalk plug-in:
cordova plugin add cordova-plugin-crosswalk-webview --variable XWALK_VERSION="org.xwalk:xwalk_core_library:15+"
Note: Some versions of CrossWalk can cause a problem when you run the app on an Android emulator. For more information, see Known limitations.
Results
You now have a Cordova app that is enabled for IBM MobileFirst Platform Foundation. In the case of the example used here, the Cordova application MyApp has the iOS and Android platforms installed, and also has FIPS 140-2 support for Android and JSONStore support (for all platforms) installed. The Cordova whitelist and CrossWalk plug-ins are optionally installed.
What to do next
To further develop your app with features that depend on the MobileFirst Server, register your app with the server. For more information, see Register Cordova applications from the MobileFirst Platform CLI.
Important: (Android and iOS development only.) If you are developing your app for the Android or iOS platforms, when you add the platform to our app that contains the cordova-plugin-mfp plug-in, an existing file in your app is replaced by a version of the file that is provided by MobileFirst Platform Foundation. These files are:
- Android: The file MainActivity.java is replaced. Your original MainActivity.java file is backed up and renamed MainActivity.original.
- iOS: File main.m is replaced. Your original main.m file is backed up and renamed main.m.bak.
If you made any changes to the original versions of these files, we must merge the changes that you made into the new version of the file that is provided by IBM MobileFirst Platform Foundation.
Parent topic: Create Cordova apps that include MobileFirst features