Add hooks to an application component
You add hooks to an application component to facilitate automation when the component is added to a MobileFirst project. These additional hooks are optional.
To add hooks, we need to edit the component.wcp file by adding XML inner elements. If we do this directly within MobileFirst Studio, the edited component.wcp file is included in the next version of the application component. If we edit the component.wcp file outside MobileFirst Studio, copy the edited file manually into the MobileFirst Studio workspace location and then run the Create Application Component command again so the application component is updated with the latest version of the component.wcp file.
Before we add hooks, we need to add the appropriate environment element according to the environment that the application component supports. The following table lists the element that we add for each supported environment:
The following example component.wcp file includes the Android environment tag:
Environment Element Android <Android> iPhone <IPhone> iPad <IPad> <ComponentData> <ID>BarCodeScannerUniqueID</ID> <Name>Barcode Scanner Android</Name> <Author>IBM</Author> <Description>Barcode Scanner for Android by IBM</Description> <Version>1.0.0</Version> <Image>barcodeIcons.jpg</Image> <WLVersion>6.1.0</WLVersion> <Android></Android> </ComponentData>Table 2 lists the inner elements supported on Android and the order in which they must appear in the schema.
Order Inner element 1 CordovaPlugin 2 Activities 3 UserPermissions 4 Receivers 5 Strings 6 ExternalLibraries 7 Libraries Table 3 lists the inner elements supported on iOS and the order in which they must appear in the schema.
Order Inner element 1 CordovaPlugin 2 Files 3 Libraries Some hooks result in the insertion of properties in the config.xml file or the AndroidManifest.xml file when the associated application component is added to a MobileFirst project. Every insertion is enclosed in comments that mention the element and application component unique name. For example:
<!--BEGIN ANDROID CORDAVA-PLUGIN AUTOINSERTION FOR BarCodeScannerUniqueID --> <!--END ANDROID CORDAVA-PLUGIN AUTOINSERTION FOR BarCodeScannerUniqueID -->
Add and removing Android library projects
Additional Android projects can be packaged as part of the component.wlc file.Additional projects are packaged in the COMPONENT-DATA folder under the folder ExternalProjects. Any compressed file under that folder is considered to be an "external project" and will be automatically added.
When the component is added to a MobileFirst project, the following things happen:
- Any additional projects are added to the Workspace.
- The additional projects are referenced from theMobileFirst project.
- If the external projects use a higher Android API level than is used by the MobileFirst Android project, the developer is prompted to upgrade to the higher API level.
When the component is removed, the following things happen:
- The additional projects are deleted from the Workspace (and from the file system).
- References to those external projects are removed from the project.
- CordovaPlugin element
This element integrates the Cordova plug-in into the application component by capturing the class name and its fully qualified name. When we add the application component to a MobileFirst project, the CordovaPlugin properties are automatically inserted into the config.xml file.
- Activities element
This element enables you to add activities information to the application component. The information is declared in the Android manifest file in any MobileFirst project that imports the component. The activities specified in the XMLContent element get appended in the Android manifest under the application element.
- UserPermissions element
This element enables you to add information about user permissions to the application component. The information controls end-user access to the native functions of a device, such as its camera or GPS functions.
- Receivers element
This element enables you to add information about broadcast receivers to the application component. The information is declared in the Android manifest file in any MobileFirst project that imports the component.
- Strings element
This element enables you to add information about strings to the application component. The information is declared in the android/native/res/values/strings.xml file in any MobileFirst project that adds the application component.
- Libraries element (Android)
This element enables you to add required libraries to the application component. The libraries are added to the android\native\libs folder in any MobileFirst project that imports the component.
- ExternalLibraries element
This element enables you to add information about external libraries to the application component. The information provides pointers to external libraries that are to be downloaded by the developer who adds the application component to a MobileFirst project. Typically, these libraries are additional libraries not packaged as part of the application component.
- Files element
This element enables you to add information about files required for the application component to work. These files are required by the native project of iPhone or iPad. The information specifies files that need to be added to the Xcode project in a MobileFirst project. The information is displayed as a list in a dialog box whenever a developer adds the application component to a MobileFirst project. The files are not actually copied; instead, the developer is prompted to copy them.
- Libraries element (iPhone and iPad)
This element enables you to add information about libraries to be added to the application component. The information specifies libraries that need to be added to the Xcode project in a MobileFirst project. The information is displayed as a list in a dialog box whenever a developer imports the application component into a MobileFirst project.
Parent topic: Application components