HockeyApp and ProGuard
ProGuard is a tool to obfuscate the code of your Android apps. It removes unused code and renames classes, fields, and methods with semantically obscure names. This article describes how to configure ProGuard together with HockeyApp and how to symbolicate stack traces from such apps.
Configure ProGuard
When you create a new Android project, a proguard.cfg file is automatically generated in the root directory of the project. By default, the file is not activated in the project configuration. To do so, add the following line to the file PROJECT_ROOT/project.properties:
proguard.config=proguard.cfg
You also need to change the proguard.cfg itself by adding the following sections:
-keep public class javax.net.ssl.**
-keepclassmembers public class javax.net.ssl.** {
*;
}
-keep public class org.apache.http.**
-keepclassmembers public class org.apache.http.** {
*;
}
-keepclassmembers class net.hockeyapp.android.UpdateFragment {
*;
}
The first two sections prevent that the SSL verification gets broken by the ProGuard process (without them, a host verification error appears as the HTTP stack uses reflection to resolve the host name for an IP address). The client code uses SSL for all communication with HockeyApp.
The third section keeps the class members of the UpdateFragment from being obfuscated. The HockeySDK uses reflection to create an instance of the fragment, so it wouldn't find the methods when ProGuard obscures the names. If you have implemented your own custom fragment, please add this as well.
Symbolicating Stack Traces
ProGuard generates a file with the mapping between the original and obfuscated class, method, and field names on every build. You can upload this file to HockeyApp to get crash logs symbolicated automatically. The setup is quite simple:
-
Go to your app's page on HockeyApp.
-
Select the version for which you want to activate symbolication.
-
Upload the file proguard/mapping.txt from your project directory.
Please note that HockeyApp can not check if you have uploaded the right file. We therefore recommend to upload the file directly after you have created the .apk file or push it your code repository if you want to upload it later.
You can also upload the file via our API: Upload New Apps or API: Upload New Versions. Just set the parameter "dsym" to your mapping.txt file.
Keeping Line Numbers
ProGuard not only obfuscates the class and method names, but also removes the filename and line numbers from the stacktrace. This makes finding errors complicated, especially in methods with lots of lines. You can keep the line numbers by adding the following code to your proguard.cfg:
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
This will replace the filename in the stacktrace with "SourceFile", but keep the line numbers.