Crashes reporting for Android apps
Before you begin, make sure that Apptics is integrated into your project by following the Integration Guide.
Add the SDK to your app
- Declare Crash Tracker dependency using Apptics BoM.
Copieddependencies {
// ...
// Apptics BoM, latest version is mentioned in the integration guide.
implementation platform('com.zoho.apptics:apptics-bom:[latest-version]')
// Since BoM version is specified, no need to explicitly specify the dependency version.
implementation 'com.zoho.apptics:apptics-crash-tracker'
}
- Alternatively, if you do not use Apptics BoM you can directly declare the crash tracker dependency with its version.
Copieddependencies {
// Have to explicitly mention the version, if you are not using BoM.
// latest version is mentioned in the integration guide.
implementation 'com.zoho.apptics:apptics-crash-tracker:[latest-version]'
}
Note: We highly recommend using Apptics BoM to avoid unnecessary compatibility issues.
- Initialize Crash Tracker in Application onCreate() method. Once done crashes will be tracked automatically.
CopiedApptics.init(this)
ANR tracking
ANR tracking is available from Apptics BOM0.2.7.2.
AppticsCrashTracker uses Android's ApplicationExitInfo API to report ANRs to Apptics console on initializing the Crash module.
ANR tracking is enabled by default and you can turn off tracking by setting the anrTrackingStatus to false.
Make sure that you disable ANR tracking before initializing Apptics.
CopiedAppticsCrashTracker.anrTrackingStatus = false
Apptics.init()
Add custom properties
Custom properties allow you to get the state of your app leading to the crash. JSONObject set using this method will be attached to the crash report, which may help you to understand and debug the crash better.
Copiedval props = JSONObject()
props.put("some key", "some value")
AppticsCrashTracker.customProperties = props
Get last crash info
- You can always get the previous crash information as stringified JSONObject.
CopiedAppticsCrashTracker.getLastCrashInfo()
,. Sample JSON structure:
{ "issuename": "divide by zero", "crash": "java.lang.ArithmeticException: divide by zero\n\tat com.zoho.apptics.MainActivity(MainActivity.kt:56)", "happendat": 1636449139218, "customproperties": {}, "screenname": "com.zoho.apptics.MainActivity", "sessionstarttime": 1636449117291, "ram": "7.02 GB", "rom": "106.22 GB", "edge": "Unknown", "batteryin": 79, "orientation": 0, "serviceprovider": "Airtel", "networkbandwidth": "", "networkstatus": 0 }
Showing consent pop-up to send previous session crash info
This is an option to gently nudge the user to report the crash, that has happened while the crash tracking was turned off.
- Call the below method on an appropriate screen in your app. This will present a pop-up only if the app has crashed in the previous sessions while the crash tracking was disabled.
CopiedAppticsCrashTracker.showLastSessionCrashedPopup(Activity)
Handled exceptions
In addition to automatically reporting your app's crashes, Apptics also allows you to log handled exceptions (non-fatal).
Log handled exceptions
Log handled exceptions in Apptics using recordException method in AppticsCrashTracker.
Copiedtry {
val i = 1/0
} catch (e: Exception) {
AppticsNonFatals.recordException(e)
}
Add custom properties
A JSONObject can be logged along with the handled exception, which can help understand the scenario better.
Copiedval props = JSONObject()
props.put("some key", "some value")
AppticsNonFatals.recordException(e, props)
Pro-guard mapping
- If your app uses pro-guard to obfuscate classes then the Apptics plugin will automatically upload the mapping file in the web console.
- Quality > Symbols and mapping to verify if the pro-guard file is uploaded or not in the Apptics console.
- If the mapping file is not available, you can add the Pro-guard mapping file manually. Refer to Obfuscation user guide.
- If you want to turn off the automatic uploading of Pro-guard files, set uploadProGuardMappingFile property to false.
Note:If the mapping file with the same package name, version code, version name, and apptics mode is already available in the server, it will be replaced by the new mapping file. Also, mapping upload task depends on the assemble Gradle task.
Copiedapptics {
uploadProGuardMappingFile = ["default": false]
}
Use the below to turn off the automatic mapping file upload for specific build-variant.
Copiedapptics {
uploadProGuardMappingFile = ["<build-variant-name>": false]
}