Written by: James Dreher
Last month I discussed the BlackBerry Tools for Android Development SDK and how we can troubleshoot Android Install Error Codes using the BlackBerry Deploy tool via the PackageManager Class within the AOSP source code. This month, let’s continue our discussion around the SDK and learn how we can manually edit our manifest file for BlackBerry 10 without requiring access to our project’s source code.
This process can be used to adjust various entries within a manifest, such as setting a custom Application-Version value or adding the _sys_use_consumer_push signing permission when creating push-enabled Android apps on BlackBerry 10.
The BlackBerry APK Packager Tool
Our tool of choice for this task will be the BlackBerry APK Packager, which as you can probably guess, packages the APK file (Android application package) into the BAR file format for BlackBerry 10. I’m a big fan of this tool because once set up, its ease-of-use allows most apps to be repackaged within about 10 seconds. All that’s required is to browse to the APK file of choice (release builds only please), click a Package button, and provide the BlackBerry signing password. The toolset builds the BAR file (BlackBerry archive) from there and results in a release-signed BAR file for distribution via BlackBerry World, or by sideloading it over USB/Wi-Fi.
Android BAR File Structure
Within the newly created BAR file, the toolset actually leaves the APK file intact while adding some additional files to account for the app running on a BlackBerry 10 device. The new BAR file has two main directories within it:
- The META-INF folder contains the new manifest named MANIFEST.MF based upon the AndroidManifest.xml file within the APK, and four (4) BlackBerry signature files (AUTHOR/RDK) to be verified upon installing the app.
- The android folder contains the APK file, in addition to a res subfolder containing the various app icons you’ve included
Upon installation, the BlackBerry 10 OS will install the APK file and its associated Dalvik executables (DEX files) directly to the BlackBerry Runtime for Android apps, while taking the associated meta information and appropriate app icon from the BAR file. The installer process also verifies both the Android and BlackBerry signatures to ensure they’re intact and valid.
Adjusting the Manifest File
When it comes to editing values within our MANIFEST.MF file, we can use any standard text editor to make and save our changes.
1. Repackage the APK using the BlackBerry APK Packager tool
- Provide the location of the APK file
- Select the Package button (you don’t need to sign the BAR yet, but doing so won’t hinder what we are trying to accomplish)
2. Extract the MANIFEST.MF file
- Within your archive editor of choice, open the newly packaged BAR file
- Navigate to the META-INF folder, and save the MANIFEST.MF file to a convenient location on your development machine
- Feel free to change the filename to avoid confusion, if you see fit, keeping the *.MF file extension
- Close the archive editor (no need to save any changes to the BAR file itself if prompted to)
3. Edit the MANIFEST.MF file
- Within your favorite text editor, open the MANIFEST.MF file (or whatever you may have changed the filename to) which was saved in step 2 above
- Make the necessary changes to the entries within the body of the manifest’s text
- Save the changes and close the text editor
4. Repackage the APK file, again, to include the custom manifest file
- Open the BlackBerry APK Package tool
- Provide the location of the APK file (should be the same as step 1 above)
- Expand the Advanced Settings option
- Within the Custom Manifest field, provide the location of the edited manifest file from step 3 above
- Select the Add Custom Manifest Values (merge) checkbox
- Select the Sign checkbox
- Select the Package button
- Provide your BlackBerry signing password when prompted (or walk through the Configure Signing process if you haven’t signed a BAR file before)
5. Verify The Changes
- Just as we did in step 2 above, within your archive editor of choice, open the newly packaged BAR file
- Navigate to the META-INF folder, and confirm the changes made to the MANIFEST.MF file and that there are four (4) signature files to verify that your BAR is fully signed
- Do not change or edit anything, as the checksum values within the signatures will be invalid, causing an error upon installation
What we’re left with is an updated (overwritten) BAR file which reflects the custom changes in the manifest file which were made.