Repackage your APK files

Before you begin:

You'll find the apk2bar tool in the bin subfolder where you installed the BlackBerry SDK for Android apps.

  1. On the command line, navigate to the bin subfolder where you installed the BlackBerry SDK.
  2. Run the apk2bar tool using the following syntax:
    apk2bar <Android_app_or_folder> [<compatibility_exceptions>] [<Android_SDK_folder>] [<blacklist file>] [-t <bar folder>] [-w[1-5]] [-a <author name>][-d [<debug-token file>]] [-m] [-rv] [-etr] [-etl] [-etn] [-ci] [-la<n>] [-R] [-os <version>]

    This table explains the values the of the arguments used in the above syntax.

    Argument

    Description

    <Android_app_or_folder>

    This argument specifies a single APK file, or a folder that contains one or more APK files and any custom manifest files. If a folder is specified, the apk2bar tool repackages all the APK files in the folder.

    <compatibility_exceptions>

    This argument specifies the path to the compatibility exceptions file. Specify this argument only if you also specify the -rv argument. This file contains a list of the APIs and features that the BlackBerry 10 OS does not support. If this argument is not specified, the apk2bar tool uses a default value of ../blackberry/Apk2Bar_compatibility_excepts.xml.

    <Android_SDK_folder>

    This argument specifies the location of the Android SDK. Alternatively, you can use the environment variable %ANDROID_HOME%, if it was set.

    -v

    This argument prints the version of the tool.

    -t <bar folder>

    This optional argument specifies the target folder where the bar(s) will be generated. Otherwise, the APK source folder is used.

    [-w[1-5]]

    This argument filters the bar generation for warnings of 1-5 or above. -w with no level means -w5

    -d [<debug_token>]

    This argument indicates that the application is being tested in a development mode.

    You can also specify the file path of the debug token. When a debug token is specified, the apk2bar tool uses it to the extract author information.

    If you intend to test the file on the BlackBerry 10 Device Simulator instead of a BlackBerry 10 device, you can omit this argument.

    -t <output_folder>

    This argument specifies the folder where the apk2bar tool saves the BAR files and other output files. If no output folder is specified, the apk2bar tool places the repackaged BAR files in the same folder as the APK files.

    -a <author_name>

    This argument specifies the author name for the BAR files. The author name should match the company name you specified using the -dname argument when you created a developer certificate. If no author name is specified, the default author name is %USERNAME%.

    -w <warning_level>

    This argument specifies a warning impact level, represented by an integer of 1 to 5. If an APK file generates any warnings that are equal to or exceed the specified impact level, the apk2bar tool does not repackage the app.

    If this argument is specified with no warning level, then the default warning level is set to 5. The apk2bar tool repackages all APK files except those that generate a level 5 warning.

    If this argument is not specified, the apk2bar tool repackages all APK files, and ignores all warnings. Unless you used the apk2barVerifier tool to verify your files and have already removed the APK files that may generate a warning, you should not run the apk2bar tool without specifying the -w option.

    -m

    This argument instructs the tool to look for a custom manifest file for each APK file it repackages. If you specify this argument, for each APK file, the apk2bar tool checks for a corresponding manifest file in the same folder. For example, if the tool is repackaging a file called helloworld.apk, it will look for a file called helloworld.MF. If it does not find a corresponding manifest file in the folder, the tool generates it.

    -rv

    This argument instructs the command-line tool to run the apk2barVerifier tool before the APK files are repackaged as BAR files.

    -cg

    This argument defines the application category as core.games. On the BlackBerry 10 OS, the application is grouped in the Game category.

    -cm

    This argument defines the application category as core.media. On the BlackBerry 10 OS, the application is grouped in the Media category.

    -etl

    This argument truncates the application's Entry-Point-Name in the manifest file so that it does not exceed 25 characters (the maximum allowed on the BlackBerry 10 OS). The -etl argument truncates the name from the left.

    -etr

    This argument truncates the application's Entry-Point-Name in the manifest file so that it does not exceed 25 characters (the maximum allowed on the BlackBerry 10 OS). The -etr argument truncates the name from the right.

    -etn

    This argument means that the application Entry-Point-Name will not be truncated.

    -ma

    This argument adds custom attributes from custom manifest files. E.g., Helloworld.apk to include attributes from Helloworld.MF.

    -ci

    This argument allows you to use a corresponding custom icon file for each app 1st Entry-Point; e.g. Helloworld.apk to use Helloworld.png.

    -la <n>

    This argument picks the launchable activity n. n = 0, 1, 2; 0 = all; 1 = 1st; 100 = last

    -r

    This argument allows you to find .apk, .cfg, and .mf files recursively in specified folders.

    -os <version>

    This optional argument allows you to specify the minimal target Tablet OS version; e.g. 2.1, 10, or 10.0.9

    Impact Legend: 5= Severe; 4 = High/context; 3 = Medium/context; 2 = Medium-low/context; 1 = Minor

After running the apk2bar tool, you can check the newly created BAR files to see whether any of the APK files could not be repackaged. There are two reasons why the apk2bar tool can fail:
  • The APK file generated a warning with an impact level that exceeded the impact level that you specified when you ran the tool. If you want your application to generate only low-level warnings, make sure that you specify an appropriate impact level. Remember that higher impact levels indicate increased severity.

  • When the apk2bar tool mapped attributes from the AndroidManifest.xml file associated with the APK file, one or more mapped attributes were not valid. To correct the problem, change the generated manifest file for the application to verify that all attribute values are valid. For more information, see Fix invalid entries in a BAR manifest file.

If all the files were successfully repackaged, you can proceed to test them on a BlackBerry 10 device.

comments powered by Disqus