HP AppPulse Mobile Adding HP AppPulse Mobile to Your Android App Document Release Date: May 2015
How to Add HP AppPulse Mobile to Your Android App How to Add HP AppPulse Mobile to Your Android App For a quick overview showing this process, watch this video. Before you Begin Within AppPulse Mobile, add an application. HP AppPulse Mobile (1.9) Page 2 of 18
How to Add HP AppPulse Mobile to Your Android App Step 1: Download the SDK From the window that appears, download and extract the AppPulse Mobile SDK. Step 2: Add AppPulse Mobile to Your App You need to have Java Runtime Environment (JRE) 1.7 or higher installed. To verify what version you have, run java -version in a Windows command line. To install JRE, click here. 1. Copy the application key generated in the previous step. If you already closed the window, you can access the application's settings within AppPulse Mobile and copy the application key from there. HP AppPulse Mobile (1.9) Page 3 of 18
How to Add HP AppPulse Mobile to Your Android App 2. Open a Windows command line (Start > Run > cmd), and enter the following: <Unzipped SDK directory>\apppulse_mobile.bat -appkey <application key> <path and name of your APK> For example: C:\MySDKFiles\AppPulse_mobile.bat -appkey pwl3i8kjke C:\MyAPK\myapp.apk You now have a new APK in the same location as the original APK file, with the suffix signed.debug.apk. The new APK is signed with a debug key, which is the standard for testing and developing Android mobile apps. The above steps are mandatory. For other options, including parameters you can use to sign the APK with your private key, see " Advanced Options" on the next page. If you run into any problems, see "Basic Setup: Troubleshooting" on page 9. Step 3: Run Your App 1. Install the new APK on an Android device or emulator, and use your app. 2. Now open AppPulse Mobile, and explore your app's user experience! What's Next? When you are ready to upload it, sign the new APK with your private key and upload it to the Google Play store. To sign using AppPulse Mobile, see "Signing-Related Parameters" on page 6. As soon as users interact with your app, AppPulse Mobile shows your users' experience in detail. HP AppPulse Mobile (1.9) Page 4 of 18
Advanced Options Advanced Options When you add HP AppPulse Mobile to your app, you can define one or more advanced options as described in the following section. To use advanced options, enter the following in the command line: <Unzipped SDK directory>\apppulse_mobile.bat -appkey <application key> <optional parameters> <path and name of your APK> You can enter the following optional parameters: Parameter Description -o <File path> By default, the instrumented APK is created in the same directory as the original APK. Use this parameter to specify a different output file. -optin -overrideacra By default, user data is automatically reported to AppPulse Mobile. If you use this parameter, data will not be reported unless users activate data reporting (opt-in), as defined in your app. For details, see "Enabling Users to Opt-In/Opt-Out of Data Reporting" on page 8. AppPulse Mobile uses a version of the ACRA library to collect data on crashes. If your app already uses ACRA, by default AppPulse Mobile will not show crash data for the app. You can use this flag to add the AppPulse Mobile ACRA library version and override your current ACRA library. Note that this will disable your existing ACRA-based reporting mechanism, and you will see crash data in AppPulse Mobile. -sdfile <File path> -stacktracesizelimit <n> -tempdir <Temp directory> Use this parameter to block sensitive data; for details see "Protecting Sensitive Data" on the next page. By default, crash reports' stacktrace have a size limit of 2 KB. Use this parameter to modify this limit (possible range: 0-10). Setting a higher limit will impact network load accordingly. HP AppPulse Mobile uses your temp directory to run the instrumentation. Use this parameter to specify a different temporary directory. HP AppPulse Mobile (1.9) Page 5 of 18
Advanced Options Signing-Related Parameters By default, the instrumented APK is signed with a debug key, which is standard for testing and developing Android mobile apps. However, you must sign the APK with your private key before you can upload it to the Google Play store. If you want, you can use AppPulse Mobile to sign the instrumented APK, using the following optional parameters: Parameter -keystore <Keystore file>] -storepass <Keystore password> -alias <Key alias> -keypass <Key password> Description The path and name of the keystore file to be used for signing. A password for the keystore, if configured. The alias to the private key entry in the keystore. A password for the private key entry in the keystore, if configured. Protecting Sensitive Data To prevent reporting sensitive data such as a button or URL showing an account number, HP AppPulse Mobile automatically shows *** instead of any sequence of 4 or more of the following elements: 0-9,. - (digit, comma, period, hyphen). For example, if your app reports Paid by account 413-57, HP AppPulse Mobile shows Paid by account ***. Before adding HP AppPulse Mobile to your app, you can customize the default data masking as follows: No data masking. If you do not want these strings replaced, open the SDK and delete the file <Unzipped SDK directory>\apkinfuser\hpfilter.xml. Run the default command line described in "How to Add HP AppPulse Mobile to Your Android App" on page 2. Change data masking rules. To define specific rules relevant for your particular app, open the SDK and locate the file <Unzipped SDK directory>\apkinfuser\hpfilter.xml. This file contains the default rule, and a template for creating additional rules. Each rule has two parts: <detection string> <replacement string>. The detection uses regular expressions. You can add as many rules as needed; each rule is a separate Item node. Add or edit rules as needed, save the file, and run the default command line described in "How to Add HP AppPulse Mobile to Your Android App" on page 2. Use a different xml file. You can create a different XML file using the guidelines described above. When you run the command line, specify the location of your file with the -sdfile <File path> parameter. HP AppPulse Mobile (1.9) Page 6 of 18
Advanced Options Protecting Sensitive URL Parameters By default, AppPulse Mobile also masks sensitive URL parameters. For example, http://www.example.com/customers/orders?username=dave&os=android is reported as http://www.example.com/customers/orders?username=*&os=*. If you need custom masking (for example if a REST URLs contain usernames such as http://www.example.com/customers/546789876/orders/), you can configure a mask in the following file: <Unzipped SDK directory>\apkinfuser\hpfilter.xml. Example: </Items>> <MaskUrls> <MaskUrl>http://www.example.com/customers/(.*?)/orders/(.*?) /there</maskurl> <MaskUrl>http://www.example.com/customers/(.*?)/orders</MaskUrl> <MaskUrl>http://www.example.com/customers/(.*?)/orders/.*</MaskUrl> </MaskUrls> The URLs are configured as regular expressions, where the capture groups (parenthesized parts) are the parts that will be masked. In the example above, the URL http://www.example.com/customers/546789876/orders will be masked to http://www.example.com/customers/*/orders. HP AppPulse Mobile (1.9) Page 7 of 18
Advanced Options Enabling Users to Opt-In/Opt-Out of Data Reporting Some apps give each user the ability to avoid sending data from their device, for example using a Settings menu item (opt-out). Other apps ask users to actively approve data collection, for example when the app is first launched (opt-in). By default, data is automatically sent from mobile apps to AppPulse Mobile. You can use the -optin parameter to disable default data reporting; in this case data is only collected from users who opt in. Note that the relevant user interface and interaction within the app are up to the application developer. To enable or disable reporting from your app to AppPulse Mobile, change the Boolean value enabled in the SharedPreferences HPUserMonitoring. The change will take effect the next time the user opens the app. For example: private static final String HP_RUM_API_PREFERENCES_NAME = "HPUserMonitoring"; private static final String HP_RUM_API_PREFERENCES_ENABLED = "enabled"; public void disablereporting(view view) { SharedPreferences.Editor spe = getsharedpreferences(hp_rum_api_ PREFERENCES_NAME, Context.MODE_MULTI_PROCESS).edit(); spe.putboolean(hp_rum_api_preferences_enabled, false).commit(); } public void enablereporting(view view) { SharedPreferences.Editor spe = getsharedpreferences(hp_rum_api_ PREFERENCES_NAME, Context.MODE_MULTI_PROCESS).edit(); spe.putboolean(hp_rum_api_preferences_enabled, true).commit(); } HP AppPulse Mobile (1.9) Page 8 of 18
Basic Setup: Troubleshooting Basic Setup: Troubleshooting Supported versions HP AppPulse Mobile supports apps with Android 2.3 (API 9) and higher. Signing issues By default, the instrumented APK is signed with a debug key, which is standard for testing and developing Android mobile apps. However, you must sign the APK with your private key before you can upload it to the Google Play store. If you try to upload your instrumented app without signing, you will receive a message: Upload failed. You uploaded an APK that was signed in debug mode. You can use AppPulse Mobile to sign the instrumented APK, as described in "Signing-Related Parameters" on page 6. Some applications require that you sign the app with the original certificate in order to properly run it on a device. For example, if you use Google Wallet or Google Maps, your app requires the original certificate. This is also true if your application uses custom permissions that are signature protected, or if your application explicitly validates signatures. If you are unable to properly run your app after adding AppPulse Mobile, sign the new APK with your original certificate. Obfuscation issues If your app uses obfuscation, AppPulse Mobile cannot be added to the app if you include the Android Support Library in the obfuscation process. Make sure it is excluded from obfuscation (for example, for ProGuard use -keep class android.support.** { *; }). HP AppPulse Mobile (1.9) Page 9 of 18
Basic Setup: Troubleshooting Error messages The following section lists messages that may appear when adding HP AppPulse Mobile to your app, with their explanation. Message: Instrumentation process was unable to run - Java Runtime Environment was not found. Explanation: If you do not have JRE installed, install it from http://java.com/en/download/. If you have JRE installed but instrumentation still fails, access your system variables, and open the PATH variable for editing. Verify that the Java Home is properly defined in the PATH variable; for example: C:\Program Files\Java\jre7\bin. After you edit the variable, close the existing command line and open a new one to continue instrumentation. Message: Could not reserve enough space for object heap. Explanation: If you are running JRE 32-bit, install 64-bit if supported by your OS. If you are running JRE 64-bit, the batch file assigns 2048KB of RAM for this process. If you need more, access the HP AppPulse Mobile SDK and open the ApkInfuser.bat file for editing. Locate the string -Xmx2048m and increase this value as needed, depending on your available system resources. Message: Explanation: Warning: You already have the ACRA library in your application for monitoring crashes. You can use the -overrideacra flag to replace your existing ACRA library. In this case, you'll get our detailed crash reports solution instead. AppPulse Mobile uses the ACRA library to collect data on crashes. Since your app is already using ACRA, by default AppPulse Mobile will not collect crash data for the app. You can use the -overrideacra flag to add the AppPulse Mobile ACRA library version and override your current ACRA library. Message: Warning: Unable to override ACRA because your ACRA is obfuscated. Crashes will therefore not be reported via our solution. HP AppPulse Mobile (1.9) Page 10 of 18
Basic Setup: Troubleshooting Explanation: You used the -overrideacra flag to override your current ACRA library, but your ACRA library is obfuscated (class names are changed). Since you have customized your ACRA we will not override it, and AppPulse Mobile will not show your crash data. Message: Explanation: Note: You are using the Override ACRA flag to enable AppPulse Mobile crash reports. You used the -overrideacra flag to add the AppPulse Mobile ACRA library version and override your current ACRA library. This disables your existing ACRA-based reporting mechanism, and you will see crash data in AppPulse Mobile. Message: Explanation: Note: Your application contains some html or javascript components, which are not yet supported. The current version of HP AppPulse Mobile does not yet support monitoring of hybrid components. This capability is coming soon! Message: Explanation: There was a problem in decoding dex file. This application is obfuscated to avoid post-build instrumentation. Your app includes bytecode obfuscation techniques that employ "junk byte injection." Contact HP Support for help with instrumenting your app. Message: SEVERE: Incorrect number of arguments, or illegal character used. SEVERE: The following path was not found: <path> Explanation: The command to add HP AppPulse Mobile to your app must contain the SDK batch location, the application key, and the apk location. Check if your command is missing one of these, or if any parameter in the command contains illegal characters ( ^ < > %). Message: Explanation: Failed to open dex file The classes.dex file is missing from your original apk, and AppPulse Mobile cannot be added unless this file exists. Use a zip viewer (like 7-zip) to see if the classes.dex file exists in your original apk. If it does exist, try to extract this file only from the original apk. You may see that your anti-virus software deletes it immediately. In this case, disable the anti-virus before adding AppPulse Mobile to your app, then re-enable your anti-virus software. HP AppPulse Mobile (1.9) Page 11 of 18
AppPulse Mobile SDK AppPulse Mobile SDK In order to add the AppPulse Mobile SDK and use its APIs, add the location of the jar to the classpath in your project dependencies. The jar is located in the following location: <unzipped sdk directory>\sdk\hpapppulsemobile.jar. After you rebuild your project you can use the following APIs: "Handled Exceptions and Crashes API" below "Breadcrumbs API" on the next page "User Action Customization APIs" on page 14 Handled Exceptions and Crashes API AppPulse Mobile automatically identifies and reports crashes. However, there are certain situation where exceptions occur and are caught by the application code, meaning they do not lead to a crash. The following APIs provide you with the ability to report these kind of exceptions with a severity level that will cause them to be displayed in AppPulse Mobile as either crashes or errors, helping you improve application quality and stability. You can use the following APIs to report the exception or crash you would like to monitor. Handled Exceptions A non-fatal exception will be displayed as an event in the Stability > Errors area. AppPulse Mobile will display the exception type, the developer-added description, and a link to show the full stack trace. HpAppPulse.reportException (Exception exception, String description) HpAppPulse.reportException (Exception exception) exception is an object containing all the relevant information of the problem (stack trace, user message). description is an optional field in case you want some text displayed in the errors page. If no description is used, the text will be taken from the exception message. Here's an example in the code: HP AppPulse Mobile (1.9) Page 12 of 18
AppPulse Mobile SDK Handled Crashes Use this API when you catch a crash or exception that leads to exit the application. A fatal exception will be displayed as a crash in the Stability > Errors area, and will have the same data as a crash. HpAppPulse.reportCrash(Exception exception) exception is an object containing all the relevant information of the problem (stack trace, user message). Here's an example in the code: Breadcrumbs API This API gives you the ability to add custom breadcrumbs in critical places in your application, containing information on the application's inner state. AppPulse Mobile displays these custom HP AppPulse Mobile (1.9) Page 13 of 18
AppPulse Mobile SDK breadcrumbs in reports on crashes, making it easier for you to investigate the source of the problem. HPAppPulse.addBreadcrumb(String name) name is a short logical name which describes the breadcrumb context. This will be displayed in the AppPulse Mobile UI. The following are examples in the code: User Action Customization APIs HP AppPulse Mobile automatically assigns names to your application's screens and user actions (UI controls) based on a number of methods. If you want to customize these screen and control names as they appear in AppPulse Mobile, you can use the following APIs to define naming and grouping as relevant to your needs. This includes the following: "Control Name" on the next page "Control Type" on the next page "Screen Name" on page 16 "Screen Name by Activity " on page 16 "Screen Name by Control Container " on page 16 "Enumeration of Control Types" on page 17 HP AppPulse Mobile (1.9) Page 14 of 18
AppPulse Mobile SDK Control Name Sets the name and type for a given control. A control is a View (android.app.view) on which a listener was set. For example, in order to click a button, an onclicklistener is set on this button. For this button, you set the name or type of the control using the following API. If you would like to consider a few separate controls as an identical control (for example two separate lists that really do the same thing), you can group them together by setting the same name and type. For example, suppose you have a list containing three items: Flights to x, Flights to y, and Flights to z, and AppPulse Mobile identifies this as a menu with three distinct actions. You can set each of the options with the same name/id, grouped under the category Flights to a location. void setactionname(view view, String actionname); Example: HpAppPulse.setActionName(myView, myname ); Control Type Sets the type for a given control. (For a definition of HPControlType enum; see "Enumeration of Control Types" on page 17.) For example, you can use this if you want a list to be considered a menu, so AppPulse Mobile will show a separate action for each item and not one action of list. Another example would be if you think the type of control is not what it appears to be, such as a control that looks like a button but has a checkbox and a textview in it, and you would like to see it as a button. void setcontroltype(view view, HPControlType controltype); Example: HpAppPulse.setControlType(myView, HpAppPulse.HPControlType.Button); Here's an example in the code: HP AppPulse Mobile (1.9) Page 15 of 18
AppPulse Mobile SDK Screen Name You can set the name for a specific screen by calling the following API on an existing activity. This should be added in the onstart or onresume method of the activity. You can also set the screen name for a specific control. You can use this to group several screen together by setting the same name. Screen Name by Activity Sets the screen name based on the activity. This API needs to be called during the activity onstart or onresume lifecycle methods. void setscreenname(activity activity, String screenname); Example: HpAppPulse.setScreenName(myActivity, myscreenname ); Here's an example in the code: Screen Name by Control Container Sets the screen name based on a given control container. For example, if a list item is clicked and you want the screen name to be based on the list container, the user will call this method on the list rather than on the list item. void setscreenname(view view, String screenname); Example: HpAppPulse.setScreenName(myView, myscreenname ); Here's an example in the code: HP AppPulse Mobile (1.9) Page 16 of 18
AppPulse Mobile SDK Enumeration of Control Types public enum HPControlType { Button, RadioButton, Tab, Menu, List, DropDown, CheckBox } Protecting Sensitive Data Collected by the SDK In some cases, you may not want to show specific information collected via the AppPulse Mobile APIs, such as a screen name that includes a sensitive parameter. To mask such data, open the SDK and locate the file <Unzipped SDK directory>\apkinfuser\hpfilter.xml. Uncomment and edit the <SDK> block as needed. This block contains a template for creating masking rules. Each rule has two parts: <detection string> <replacement string>. The detection uses regular expressions. You can add as many rules as needed; each rule is a separate SDKItem node. HP AppPulse Mobile (1.9) Page 17 of 18
AppPulse Mobile SDK Legal Notices Warranty The only warranties for HP products and services are set forth in the express warranty statements accompanying such products and services. Nothing herein should be construed as constituting an additional warranty. HP shall not be liable for technical or editorial errors or omissions contained herein. The information contained herein is subject to change without notice. Restricted Rights Legend Confidential computer software. Valid license from HP required for possession, use or copying. Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under vendor's standard commercial license. Copyright Notice Copyright 2014-2015 Hewlett-Packard Development Company, L.P. Trademark Notices Apple is a trademark of Apple Computer, Inc., registered in the U.S. and other countries. Google and Android are registered trademarks of Google Inc. HP AppPulse Mobile (1.9) Page 18 of 18