This document describes the APIs provided by the Android Crash Analysis software development kit (SDK).
Custom Exception
The Crash Analysis SDK provides an API to report custom exceptions. You can report up to eight custom exceptions at a time.
recordException
Reports a custom exception.
API definition
void recordException(@NonNull Throwable throwable)
Class
ApmCrashAnalysis
Parameters
Parameter | Type | Required | Description |
throwable | Throwable | Yes | The exception. |
Code examples
import com.aliyun.emas.apm.crash.ApmCrashAnalysis
ApmCrashAnalysis.getInstance()
.recordException(RuntimeException("This is an non-fatal"))import com.aliyun.emas.apm.crash.ApmCrashAnalysis;
ApmCrashAnalysis.getInstance()
.recordException(new RuntimeException("This is an non-fatal"));recordException
Reports a custom exception.
This API was added in version 2.3.0. It is used to report custom exceptions for languages other than Java or Kotlin.
API definition
void recordException(@NonNull ExceptionModel exceptionModel)
Class
ApmCrashAnalysis
Parameters
Parameter | Type | Required | Description |
exceptionModel | Yes | The exception. |
Add log information
The Crash Analysis SDK provides an API to add additional log information.
log
Adds log information.
You can call the log API multiple times for a single crash. However, the maximum log size for a single crash is 64 KB. If the log size exceeds 64 KB, the earliest logs are truncated.
API definition
void log(@NonNull String message)
Class
ApmCrashAnalysis
Parameters
Parameter | Type | Required | Description |
message | String | Yes | The log information. |
Add custom dimensions
The Crash Analysis SDK provides a series of APIs to add custom dimensions.
A single crash can contain up to 64 key-value pairs.
setCustomKey
Adds data of the boolean type.
API definition
void setCustomKey(@NonNull String key, boolean value)
Class
ApmCrashAnalysis
Parameters
Parameter | Type | Required | Description |
key | String | Yes | The key. Maximum length: 1,024 characters. Keys longer than this are truncated. |
value | boolean | Yes | The value. |
setCustomKey
Adds data of the double type.
API definition
void setCustomKey(@NonNull String key, double value)
Class
ApmCrashAnalysis
Parameters
Parameter | Type | Required | Description |
key | String | Yes | The key. Maximum length: 1,024 characters. Keys longer than this are truncated. |
value | double | Yes | The value. |
setCustomKey
Adds data of the float type.
API definition
void setCustomKey(@NonNull String key, float value)
Class
ApmCrashAnalysis
Parameters
Parameter | Type | Required | Description |
key | String | Yes | The key. Maximum length: 1,024 characters. Keys longer than this are truncated. |
value | float | Yes | The value. |
setCustomKey
Adds data of the int type.
API definition
void setCustomKey(@NonNull String key, int value)
Class
ApmCrashAnalysis
Parameters
Parameter | Type | Required | Description |
key | String | Yes | The key. Maximum length: 1,024 characters. Keys longer than this are truncated. |
value | int | Yes | The value. |
setCustomKey
Adds data of the long type.
API definition
void setCustomKey(@NonNull String key, long value)
Class
ApmCrashAnalysis
Parameters
Parameter | Type | Required | Description |
key | String | Yes | The key. Maximum length: 1,024 characters. Keys longer than this are truncated. |
value | long | Yes | The value. |
setCustomKey
The value to add is a String.
API definition
void setCustomKey(@NonNull String key, @NonNull String value)
Class
ApmCrashAnalysis
Parameters
Parameter | Type | Required | Description |
key | String | Yes | The key. Maximum length: 1,024 characters. Keys longer than this are truncated. |
value | String | Yes | The value. Maximum length: 1,024 characters. Values longer than this are truncated. |
setCustomKeys
Adds a batch of key-value pairs.
API definition
void setCustomKeys(@NonNull CustomKeysAndValues keysAndValues)
Class
ApmCrashAnalysis
Parameters
Parameter | Type | Required | Description |
keysAndValues | Yes | A batch of key-value pairs. |
CustomKeysAndValues
A CustomKeysAndValues object can contain a group of custom key-value pairs.
putString
The value to add is a String.
API definition
CustomKeysAndValues.Builder putString(@NonNull String key, @NonNull String value)
Class
CustomKeysAndValues.Builder
Parameters
Parameter | Type | Required | Description |
key | String | Yes | The key. Maximum length: 1,024 characters. Keys longer than this are truncated. |
value | String | Yes | The value. Maximum length: 1,024 characters. Values longer than this are truncated. |
putBoolean
Adds data of the boolean type.
API definition
CustomKeysAndValues.Builder putBoolean(@NonNull String key, boolean value)
Class
CustomKeysAndValues.Builder
Parameters
Parameter | Type | Required | Description |
key | String | Yes | The key. Maximum length: 1,024 characters. Keys longer than this are truncated. |
value | boolean | Yes | The value. |
putDouble
Adds data of the double type.
API definition
CustomKeysAndValues.Builder putDouble(@NonNull String key, double value)
Class
CustomKeysAndValues.Builder
Parameters
Parameter | Type | Required | Description |
key | String | Yes | The key. Maximum length: 1,024 characters. Keys longer than this are truncated. |
value | double | Yes | The value. |
putFloat
Adds data of the float type.
API definition
CustomKeysAndValues.Builder putFloat(@NonNull String key, float value)
Class
CustomKeysAndValues.Builder
Parameters
Parameter | Type | Required | Description |
key | String | Yes | The key. Maximum length: 1,024 characters. Keys longer than this are truncated. |
value | float | Yes | The value. |
putLong
Adds data of the long type.
API definition
CustomKeysAndValues.Builder putLong(@NonNull String key, long value)
Class
CustomKeysAndValues.Builder
Parameters
Parameter | Type | Required | Description |
key | String | Yes | The key. Maximum length: 1,024 characters. Keys longer than this are truncated. |
value | long | Yes | The value. |
putInt
The value to add is of the int type.
API definition
CustomKeysAndValues.Builder putInt(@NonNull String key, int value)
Class
CustomKeysAndValues.Builder
Parameters
Parameter | Type | Required | Description |
key | String | Yes | The key. Maximum length: 1,024 characters. Keys longer than this are truncated. |
value | int | Yes | The value. |
build
Builds a CustomKeysAndValues instance.
API definition
CustomKeysAndValues build()
Class
CustomKeysAndValues.Builder
Return value
Type | Description |
CustomKeysAndValues | A CustomKeysAndValues instance. |
ExceptionModel
A data class for custom exceptions. You can construct it using the builder pattern.
This class was added in version 2.3.0.
setName
Sets the exception class name.
API definition
ExceptionModel.Builder setName(@NonNull String name)
Class
ExceptionModel.Builder
Parameters
Parameter | Type | Required | Description |
name | String | Yes | Such as the exception class name in Java. |
setReason
Sets the reason for the exception.
API definition
ExceptionModel.Builder setReason(@NonNull String reason)
Class
ExceptionModel.Builder
Parameters
Parameter | Type | Required | Description |
reason | String | Yes | Such as the exception message in Java. |
setSourceLanguage
Sets the language type.
API definition
ExceptionModel.Builder setSourceLanguage(@NonNull SourceLanguage language)
Class
ExceptionModel.Builder
Parameters
Parameter | Type | Required | Description |
language | SourceLanguage | Yes | The valid values are:
|
setStackTrace
Sets the exception stack trace.
API definition
ExceptionModel.Builder setStackTrace(@Nullable List<StackFrame> stackTrace)
Class
ExceptionModel.Builder
Parameters
Parameter | Type | Required | Description |
stackTrace | List<StackFrame> | No | A list of stack frames. |
setCustom
Specifies whether the exception is custom. Set this to false for exceptions thrown by the platform runtime. Set this to true for exceptions that you catch.
API definition
ExceptionModel.Builder setCustom(boolean custom)
Class
ExceptionModel.Builder
Parameters
Parameter | Type | Required | Description |
custom | boolean | Yes | The default value is true. |
setUrgent
Specifies whether to report immediately.
If you do not report the exception immediately, it is reported with the next crash or in a batch during the next cold start.
API definition
ExceptionModel.Builder setUrgent(boolean urgent)
Class
ExceptionModel.Builder
Parameters
Parameter | Type | Required | Description |
urgent | boolean | Yes | The default value is false. |
setQuitApp
Specifies whether to exit the app after the custom exception is processed.
API definition
ExceptionModel.Builder setQuitApp(boolean quitApp)
Class
ExceptionModel.Builder
Parameters
Parameter | Type | Required | Description |
quitApp | boolean | Yes | The default value is false. |
build
Generates an ExceptionModel instance.
API definition
ExceptionModel build()
Class
ExceptionModel.Builder
StackFrame
A data class for stack frames. You can construct it using the builder pattern.
This class was added in version 2.3.0.
setSymbol
Sets the symbol, which is usually a function or method name.
API definition
StackFrame.Builder setSymbol(@NonNull String symbol)
Class
StackFrame.Builder
Parameters
Parameter | Type | Required | Description |
symbol | String | Yes | The symbol, which is usually a function or method name. |
setFile
Sets the file name.
API definition
StackFrame.Builder setFile(@NonNull String file)
Class
StackFrame.Builder
Parameters
Parameter | Type | Required | Description |
file | String | Yes | The file name. |
setLine
Sets the line number.
API definition
StackFrame.Builder setLine(int line)
Class
StackFrame.Builder
Parameters
Parameter | Type | Required | Description |
line | int | Yes | The line number. |
setLibrary
Sets the library.
API definition
StackFrame.Builder setLibrary(@Nullable String library)
Class
StackFrame.Builder
Parameters
Parameter | Type | Required | Description |
library | String | No | The library. |
setAddress
Sets the address.
API definition
StackFrame.Builder setAddress(long address)
Class
StackFrame.Builder
Parameters
Parameter | Type | Required | Description |
address | long | No | The address. |
build
Generates a StackFrame instance.
API definition
StackFrame build()
Class
StackFrame.Builder