All Products
Search
Document Center

Mobile Platform as a Service:Android client diagnosis

Last Updated:Jul 24, 2023

This topic describes how to use the client diagnosis function on Android clients. In the console, you can send diagnosis tasks through two channels: Message Push Service (Push) and Mobile Sync Service (Sync).

To implement Android client diagnosis, perform the following steps:

  1. Initialize diagnosis service

  2. Write diagnosis logs to client

  3. Pull diagnosis logs in the console

Prerequisites

  • Your app has the MAS component integrated, and log reporting function works correctly. For more information about the accessing steps, see Access Mobile Analysis Service.

  • Your app has the Message Push Service or Mobile Sync Service integrated.

Initialize diagnosis service

The client diagnosis function allows you to pull diagnosis logs through the Sync or Push channels. The methods for initializing different channels are different.

Use Message Push Service (Push)

If you use the Push channel, you must perform the following steps after the app starts to complete initialization:

Use Mobile Sync Service (Sync)

If you use the Sync channel, you must call the following methods after the app starts to complete initialization.

// Set the userId.
MPLogger.setUserId(String userId);
// To initialize the Sync channel, you must set the userId first. Otherwise, initialization will fail.
MPDiagnose.initSyncChannel(Context context);

Write diagnosis logs to client

After the client receives the diagnosis task, the client uploads only the logs written by using MPLogger, the logging tool of mPaaS. Therefore, we recommend that you use MPLogger instead of android.util.Log to write logs. MPLogger provides a logging method that is similar to native logging, as shown in the following code:

void verbose(String tag, String msg);
void debug(String tag, String msg);
void info(String tag, String msg);
void warn(String tag, String msg);
void warn(String tag, Throwable t);
void warn(String tag, String msg, Throwable tr);
void error(String tag, String msg);
void error(String tag, Throwable t);
void error(String tag, String msg, Throwable t);
void print(String tag, String msg);
void print(String tag, Throwable t);

As for the logs written by MPLogger, debug packages are displayed in Logcat while release packages not. The diagnosis logs are stored in the following directories on the device:

  • Debug packages: /sdcard/[PackageName]/applog, if the logs failed to be written to this directory (for example, the app targetSdkVersion is higher than 30), they will be written to the storage directory for release packages.

  • Release packages: /data/data/[PackageName]/files/applog

Pull diagnosis logs in the console

In the console, you can pull logs printed by the logging tool of mPaaS to quickly analyze app crashes and exceptions that specified devices or users encounter.

Step 1: Create a log pull task

  1. Log on to the mPaaS console and then select an app.

  2. In the left-side navigation pane, choose Mobile Analysis Service > Log management.

  3. On the Extract real-time logs tab, click Add.

  4. Enter the information about the task. User ID uniquely identifies a user who logs on to your app. You can set the user ID by calling MPLogger.setUserId(String userId) or the Message Push Service’s user ID reporting method.

  5. Click OK to complete creating the log pull task.

Step 2: Trigger the log pull task

  1. In the log pull task list, find the newly created task, and then select Trigger channel. Click Trigger in the Operations column.

  2. Wait until the task status is updated.

    • Task processed: In this state, you can click View to download the diagnosis logs.

    • Push/Sync service successfully called: This status indicates that the instruction for uploading a diagnosis log has been delivered, but the client has not received the instruction or uploaded the diagnosis log.

      In this case, check whether your app process still exists in the system. If your app process does not exist in the system, restart your app. If the task status does not change after you restart your app, troubleshoot as instructed in the following sections.

Troubleshooting

If you fail to pull logs, you can troubleshoot through the following steps. The troubleshooting methods vary with the diagnosis task delivery channels.

For Push channel

To troubleshoot log pull failures, perform the following steps:

  1. In the mPaaS console, go to the Message Push Service page, and push a normal message to your app by userId to Check if the Push channel works correctly.

  2. If the Push channel works correctly, clear logs in Logcat, and then switch to the push process. In the mPaaS console, find the diagnosis task and then click Trigger in the Operations column. View the log in Logcat.

  3. Search mPush14 to view whether any diagnosis message is received. If no diagnosis messages are received, check whether the Push channel is disconnected.

    image.png
  4. After a diagnosis message is received, check whether the following log exists, which indicates whether the diagnosis message is forwarded to MonitorService.

    If ClientMonitorService is not found, use the mPaaS plug-in to update the SDK:

    • If the baseline version is 10.1.32, upgrade the baseline to 10.1.68, and then upgrade the component to the latest version.

    • If the baseline version is 10.1.60 or 10.1.68, upgrade the component to the latest version.

      2
  5. After MonitorService starts, search AlipayLogUploader to check whether any local diagnosis log exists. If the following log appears, a local diagnosis log is available for uploading.

    A local diagnosis log exists

    If the following log appears, no local diagnosis logs exist.

    No local diagnosis logs exist

    Check the following items:

    • For real-time log pull tasks created in the console, select a time range longer than 1 hour. Ensure that the app runs and a diagnosis log is generated for the app during the selected time range.

    • Whether the following permissions are declared and dynamically applied for the app:

       <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  6. After you confirm that a local diagnosis log exists, search HttpUpload to check whether the log is uploaded. If responseCode is 200, the log is uploaded.

    3

For Sync channel

If you fail to pull logs, you can troubleshoot through the following steps.

  1. Clear logs in Logcat, and then switch to the main process. Initialize the Sync channel and then search isConnected to check whether the Sync channel is connected to the client.

    4
  2. In the mPaaS console, find the diagnosis task, and then click Trigger in the Operations column. Select MPDiagnose to check whether any diagnosis messages are received and whether MonitorService is enabled.

    If no diagnosis messages are received, check whether the specified userId is the same as the userId in the diagnosis task. If no ClientMonitorService is found, use the mPaaS plug-in to update the SDK.

    • If the baseline version is 10.1.32, upgrade the baseline to 10.1.68, and then upgrade the component to the latest version.

    • If the baseline version is 10.1.60 or 10.1.68, upgrade the component to the latest version.

      5
  3. After MonitorService starts, switch to the push process. Select AlipayLogUploader to check whether any local diagnosis log exists. If the following log appears, a local diagnosis log is available for uploading.

    A local diagnosis log exists

    If the following log appears, no local diagnosis logs exist.

    No local diagnosis logs exist

    Check the following items:

    • For real-time log pull tasks created in the console, select a time range longer than 1 hour. Ensure that the app runs and a diagnosis log is generated for the app during the selected time range.

    • Whether the following permissions are declared and dynamically applied for the app:

      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  4. After you confirm that a local diagnosis log exists, search HttpUpload to check whether the log is uploaded. If responseCode is 200, the log is uploaded.

    6