01/10/2025 10:53:00
Development of the Exception Reporting Module
I. Plugin development instructions
The Exception Reporting module supports reporting the exception stack information when an exception or crash occurs in a game, so as to facilitate game developers to locate and resolve exceptions.
II. Client Plugin Development
2.1 Android Platform
2.1.1 Class implementation rules instructions
- Package naming rule: fixed as
com.tencent.gcloud.msdk.crash
- Class naming rule:
channel + Crash
, such as:BuglyCrash
- Must implement the
CrashInterface
interfaceinit
function, used to initialize the Exception Reporting moduleupdateChannel
function: MSDK will automatically call this interface when the user logs in or logs out the game. The channel can set the exception reporting data according to the currently logged-in user information.logInfo
function, used for user-defined log printing. Log information is first output to the local. The cached log information will be reported when an exception occurs.setUserValue
function, used to set the user data for exception reportingreportException
function, used to report user-defined exceptions
2.1.2 Description of the exception reporting callback
If the Exception Reporting module can give a game-related callback when an exception occurs and can dynamically increase additional information for game settings, it is needed to pay attention to the two interfaces provided by MSDK
MSDKCrash.attachmentMessageForException()
, used to get the string information of the game settingsMSDKCrash.attachmentForException()
, used to get the binary information of the game settings
The Exception Reporting module can call the two methods when an exception is called back and can append the data to the information to be reported
2.1.3 CrashInterface interface
init function
The Exception Reporting module's initialization function. It is recommended to call the updateChannel method to set the channel information when the Exception module is initialized.
@Override public void init() { // The channel's initialization logic ... // Update the channel information updateChannel(); }
updateChannel function
The channel information updating function. MSDK will automatically call this interface when the user logs in or out the game. The channel can set the exception reporting data according to the current user's login information.
@Override public void updateChannel() { // Get MSDK Openid String openId = null; MSDKLoginRet loginRet = MSDKLogin.getLoginRet(); if (loginRet != null && IT.isNonEmpty(loginRet.openID)) { openId = loginRet.openID; } // Call the channel's user ID setting interface ... }
logInfo function
The user-defined log print function, which is used to record some key business debugging information and can more fully reflect the context in which a crash or exception occurs to APP. The log information is reported when an exception occurs. And the log information will be output locally according to the currently set log level.
@Override public void logInfo(int level, String tag, String log) { // The user-defined log printing logic of the channel ... }
setUserValue function
Set the user-defined data for exception reporting. After being successfully set through this interface, the user-defined Key-Value data will be reported with exception information when Crash occurs.
@Override public void setUserValue(String key, String value) { // The channel's user data setting logic ... }
reportException function
The user-defined exception reporting function. The game can define some exceptions by itself and report these exceptions.
@Override public void reportException(int type, String exceptionName, String exceptionMsg, String exceptionStack, HashMap<String, String> extInfo) { // The channel's user-defined exception reporting function ... }
[info] For details, please refer to Demo Code
2.2 iOS Platform
2.2.1 Class implementation rules instructions
- Must implement the
MSDKCrashDelegate
interfaceinitCrashReport
function, used to initialize the Exception Reporting module- [Optional]
updateChannel
function. MSDK will automatically call this interface when the user logs in or out the game. The channel can set the exception reporting data according to the current user's login information. - [Optional]
reportLog
function, used for printing the user-defined log. The log information is output locally at first, and the cached log information will be reported when an exception occurs. - [Optional]
setUserData
function, used to set the user data for exception reporting - [Optional]
reportException
function, used to report user-defined exceptions
2.2.2 Description of the exception reporting callback
Remarks about the callback function: If a plugin supports callback when Crash occurs, it cannotify the user through the synchronization method of the callback mode; and the user can set the data returned to the plugin for further processing. For the rules of the callback function, please refer to Client Channel Access Rules
observerID
callback function IDkMethodNameCrashExtraMessage
triggersMSDKCrashObserver.OnCrashExtraMessageNotify
callback. The user-defined string data set by the user can be obtained through ret.datakMethodNameCrashExtraData
triggersMSDKCrashObserver.OnCrashExtraDataNotify
callback. The user-defined binary data set by the user can be obtained through ret.data
ret
return struct- The return result is
InnerCrashRet
, which is used to receive the user-set data result
- The return result is
methodNameID
Function ID defined by MSDK, used to define the callback methodkMethodNameCrashExtraMessage
is a custom binary data method IDkMethodNameCrashExtraData
is a custom String data method ID
2.2.3 MSDKCrashDelegate interface
initCrashReport function
The Exception Reporting module's initialization function. It is recommended to call the updateChannel method to set the channel information when the Exception module is initialized.
- (void)initCrashReport { // The channel's initialization logic ... // Update the channel information updateChannel(); }
updateChannel function
The channel information updating function. MSDK will automatically call this interface when the user logs in or out the game. The channel can set the exception reporting data according to the current user's login information.
- (void)updateChannel MSDKLoginRet loginRet; if (MSDKLogin::GetLoginRet(loginRet)) { const char* openID = loginRet.openID.c_str(); // The channel's user ID setting logic ... } }
reportLog function
The user-defined log print function, which is used to record some key business debugging information and can more fully reflect the context in which a crash or exception occurs to APP. The log information is reported when an exception occurs. And the log information will be output locally according to the currently set log level.
- (void)reportLog:(int)level tag:(NSString *)tag log:(NSString *)log { // The user-defined log printing logic of the channel ... }
setUserData function
Set the user-defined data for exception reporting. After being successfully set through this interface, the user-defined Key-Value data will be reported with exception information when Crash occurs.
- (void)setUserData:(NSString *)key value:(NSString *)value { // The channel's user data setting logic ... }
reportException function
The user-defined exception reporting function. The game can define some exceptions by itself and report these exceptions.
- (void)reportException:(int)type exceptionName:(NSString *)exceptionName exceptionMsg:(NSString *)exceptionMsg exceptionStack:(NSString *)exceptionStack extInfo:(NSDictionary *)extInfo{ // The channel's exception reporting logic ... }
[info] For details, please refer to Demo Code
All rights reserved.