If you’re having problems creating hybrid apps with forcedroid–this blog post’s for you.
Lately, our developers have reported errors such as:
“The node package shelljs is required to use this script. Run ‘npm install firstname.lastname@example.org‘ before running this script.”
“Error: Execution failed for task ‘:processDebugManifest’.
> Manifest merger failed with multiple errors, see logs”
“Failed to install ‘com.salesforce’:Uh oh!
/Users/xxxxx/HybridApps/myApp/plugins/com.salesforce/src/android/assets/icudt46l.zip not found!”
Errors such as these frequently come from mismatched versions of external dependencies, or unforeseen updates to others. We’re working hard to fix these issues in the upcoming Mobile SDK release. In the meantime, though…Despair not! There’s an easy workaround.
To avoid these issues, we recommend you create and configure your hybrid Android apps entirely from the Cordova command line. You can call
cordova create instead of
forcedroid create, followed by any other Cordova commands you need. We’ve recommended this approach for a while as an alternative. Nowadays, though, it’s a necessity for these corner cases.
Be careful to observe two important details:
- Always add the
SalesforceMobileSDK-CordovaPluginlast, after any other plugins.
- Specify the version of each platform you add. For Android, use:
cordova platform add email@example.com
cordova platform add firstname.lastname@example.org
Note These values apply to Mobile SDK 4.1.1 and will likely change with later releases, so be vigilant!
After you’ve run
cordova prepare, open your project in Android Studio and run it from there. Remember to open the project at <project_folder>/platforms/android/.
Here’s an example.
Create a Hybrid Android App with the Cordova Command Line
The following procedure creates a project named “contactsApp” in a target directory named “contactsApps”. This project incorporates the ContactExplorer hybrid sample app from the SalesforceMobileSDK-Shared git repo.
1. cd to a directory you use for storing Mobile SDK hybrid projects.
2. Run the following commands.
cordova create contactsApp com.salesforce.contactexplorer contactsApp cd contactsApp cordova plugin add org.apache.cordova.contacts cordova plugin add org.apache.cordova.statusbar cordova plugin add https://github.com/forcedotcom/SalesforceMobileSDK-CordovaPlugin cp -RL /SalesforceMobileSDK-Shared/samples/contactexplorer/* www/ cordova platform add email@example.com cordova platform add firstname.lastname@example.org cordova prepare
3. From the Android Studio welcome screen, import the contactsApp/platforms/android folder. If, by any chance, you already have contactsApp installed on your device or emulator, we recommend Force Stopping it and then uninstalling the app before debugging your new app.
4. Run ‘android’.