目录

Analytics Kit

As a lightweight IDE tool plugin, HMS Toolkit implements app creation, coding, conversion, debugging, test, and release. It helps you integrate HMS Core APIs with lower costs and higher efficiency.

Configuration Wizard of HMS Toolkit enables you to automatically complete necessary configuration for development preparations.

Configuration Wizard

Installing HMS Toolkit

Windows: Start Android Studio, go to File > Settings > Plugins > Marketplace, enter HMS Toolkit in the search box, and click Install. After the installation is complete, restart Android Studio.

macOS: Start Android Studio, go to Preferences > Plugins > Marketplace, enter HMS Toolkit in the search box, and click Install. After the installation is complete, restart Android Studio.

Configuring the Development Environment

[h2]Configuring App Information in AppGallery Connect

To develop an app, create it in AppGallery Connect and set required information.

  1. Use your HUAWEI ID to sign in to AppGallery Connect. If you do not have any HUAWEI ID, register one by referring to Registration and Verification.
  2. Create a project and create an app. Note that set Package type to APK (Android app).

    You only need to perform the preceding two steps in AppGallery Connect. Then go to Configuration Wizard of HMS Toolkit and perform configurations according to Configuring the HMS Toolkit Environment.

[h2]Configuring the HMS Toolkit Environment

Before calling the Analytics Kit capabilities, perform the following steps to configure the environment:

  1. In Android Studio, go to HMS > Configuration Wizard.

    If you have not signed in to AppGallery Connect, Toolkit automatically opens the browser and prompts you to sign in and perform authorization.

  2. After sign-in authorization, select the team name, project module, integrated kit (Analytics Kit), and certificate type, and click Next.

    After you select the team name and project module, HMS Toolkit automatically checks whether the corresponding app is available in AppGallery Connect. If the error messages in red in the following figure are displayed, click Link to check whether the app has been created in AppGallery Connect.

    • If not, create the app and click Retry.
    • If so, verify that the team name and project module are correct and click Retry.

    The following figure shows the page after the errors are rectified.

    HMS Toolkit automatically checks the integration environment of Analytics Kit, including the general environment and the environment dedicated for the kit.

    HMS Toolkit checks whether each configuration item is correct.
    • If an item fails to pass the check, as shown in the preceding figure, click Link to manually modify the item as prompted. You can also click or refer to the following table to rectify the item. After the setting, click Retry to perform the check again.

      No.

      Check Item

      Suggestions

      1

      Obtain the package name of your application

      Create an app in AppGallery Connect in advance, and make sure that its package name is the same as that specified in HMS Toolkit for the app that you are developing.

      NOTE:

      HMS Toolkit only queries the app in AppGallery Connect based on the package name and does not proactively create an app. The package name is specified by android.defaultConfig.applicationId in build.gradle.

      2

      Check whether there is any app corresponding to your application's package name in AppGallery Connect

      3

      Verify the package name

      Make sure that the package name ends with .HUAWEI or .huawei. This restriction is applied only to joint operations games.

      4

      Generate a signing certificate

      If you select Use Your Certificate, make sure that the certificate file is created successfully, and keyPassword and storePassword are set correctly.

      5

      Configure signing certificate information

      6

      Generate a certificate fingerprint

      7

      Configure the certificate fingerprint in AppGallery Connect

      Manually copy the SHA-256 certificate fingerprint and paste it in the text box under Generate a certificate fingerprint, click the link that appears in the HMS Toolkit window, and enter the SHA-256 certificate fingerprint for the app.

      8

      Check whether the data storage location was set

      Click the link that appears in the HMS Toolkit window, and set a data storage location.

      9

      Check whether the required xxx Kit service was enabled

      Click the link that appears in the HMS Toolkit window, and enable required services.

      After a service is enabled in HMS Toolkit, go to Project settings > Manage APIs in AppGallery Connect and enable the service.

      10

      Check whether the required xxx Kit API was enabled

      11

      Download the agconnect-services.json file

      Ensure that the package name that you have specified for the app when you create it in AppGallery Connect is the same as that of the selected project template.

      12

      Copy the agconnect-services.json file to the module directory

      13

      Add the HMS Maven repository address to the build.gradle file in the project directory for xxx Kit

      No manual intervention is required.

      14

      Add dependencies from AppGallery Connect to the build.gradle file in the project directory for xxx Kit

      15

      Add dependencies from AppGallery Connect to the build.gradle file in the module directory for xxx Kit

      16

      Add dependencies from the xxx Kit SDK to the build.gradle file in the module directory

      17

      Configure obfuscation scripts of xxx Kit

    • If all the items are passed, click Go to coding assistant to call APIs. For details, please refer to Kit Integration Wizard.

Integrating Analytics Kit Through Coding Assistant

Go to HMS > Coding Assistant, and select Analytics Kit in the kit list. The following figure shows all the scenarios of Analytics Kit.

[h2]Analytics Kit Initialization

  1. Go to Coding Assistant > App Services > Analytics Kit and select Add Analytics to your app. On the initialization details page displayed, drag or copy the code of the APIs to specified positions. Then, Analytics Kit is initialized.

  2. In (Optional) Set event reporting policies, select a reporting policy and add its parameters by dragging or copying.

[h2]Tracing of Predefined Events and Custom Events

Go to Coding Assistant > App Services > Analytics Kit and select Log on Analytics event. In Log Events, click New Event to add an event.

Adding a predefined event

  1. In Predefined Events, view the events predefined by the Analytics SDK based on common application scenarios. It is recommended you use these events for tracing and analysis. Select a predefined event ID from the Event ID drop-down list box. Then the event parameters and sample code will be displayed below. Click OK and set Event Name to save the event to Predefined Events and Custom Events in Log Events.

  2. Drag or copy the sample code of the saved event to the project. Then, supplement the parameter values in the sample code in the project as needed. The event tracing configuration is complete.

Adding a custom event

  1. In Custom Events, set an event ID and its parameters as needed. Click OK and set Event Name to save the event to Predefined Events and Custom Events in Log Events. The following uses the brief information about an exam as an example.

  2. Drag or copy the sample code of the saved event to the project. Then, supplement the parameter values in the sample code in the project as needed. The event tracing configuration is complete.

  3. Register the custom event and set relevant parameters on the Analytics Kit console for the event to take effect. Click Login - My project - Huawei Analytics - Management - Event management at the bottom of Custom Events. On the Analytics Kit console displayed, perform registration by referring to Events.

[h2]Event Tracing Template

Analytics Kit provides you with tracing templates and sample code for game and education apps. You can code for event tracing by copying the sample code. With Coding Assistant, you can obtain the sample code of the event tracing template in Android Studio, and drag or copy the code to your project. To import the events from the tracing template, perform the following steps:

  1. Go to Coding Assistant > App Services > Analytics Kit and select Log on Analytics event. In Log Events, click Import Event to import the events.

  2. Set Team and Module for the app that you are developing. Click Get App ID and App Secret to obtain App ID and App Secret. Click Next to obtain the template.

    • If the error message The AccessToken obtaining failed please check out is displayed, you have not configured the event tracing template in advance. In this case, click AppGallery Connect, go to Intelligent data access > Tracing by coding, and configure the template. For details, please refer to Tracing by Coding.

    • If the error message The region service is not enabled for the project is displayed, you have not enabled Analytics Kit. In this case, click AppGallery Connect, go to My projects, find your project, and click the app for which you want to enable Analytics Kit. Go to any submenu under HUAWEI Analytics, click Enable Analytics service. On the Project access settings page displayed, set the data processing location. For details, please refer to Enabling the Service.

  3. Go to Import Event. In the left template list, select the template that you want to import. Then you will find all events in the template from the Event ID drop-down list box. Click Batch Import to import all of the events. They will be saved to Template Events.

  4. Drag or copy the sample code of the events to the project. Then, supplement the parameter values in the sample code in the project as needed. The event tracing configuration is complete.
    • If you want to generate an analysis report of an event tracing template, you need to complete the tracing configuration for all events in the template.
    • After the configuration, you can use the verification function to identify incorrect event tracing configurations. For details, please refer to Verify Tracing Events.
    • If you have imported the events from a tracing template in Template Events and updated the event data in the template on the Analytics Kit console, when you click Import Event again, Coding Assistant will automatically identify the changes of the template and notifies you of the changes.

[h2]User Attribute Settings

  1. Go to Coding Assistant > App Services > Analytics Kit and select Log on Analytics event. In Set UserProfile, click Set UserProfile. On the New UserAttributes page that is displayed, add a user attribute. A maximum of 25 user attributes can be added at a time. Enter the user attribute value as required and click OK to save it.

  2. Drag or copy the code corresponding to the attribute to your app. You need to set the parameters in the attribute as needed to record the attribute.

    The code after the event and user attribute are recorded is as follows.

  3. To delete a user attribute, drag or copy the corresponding code in Delete UserProfile to the specified app.

[h2]Other Functions

For details about other functions such as event analysis, please refer to the development guide.

Building, Loading, and Debugging the App

After the preceding operations are complete, you can use Cloud Debugging in HMS Toolkit to debug the app on a real device. For details, please refer to Cloud Debugging. To enable or disable the debugging mode, perform the following steps:

On the Analytics Kit card, click Analytics Model on the toolbar to enable or disable the debugging mode.
  • If a green dot is displayed in Analytics Model, the debugging mode is enabled, and all events are reported in real time.
  • If a gray dot is displayed in Analytics Model, the debugging mode is disabled, and event reporting is suspended.

[h2]Running or Debugging an App on a Remote Real Device

  1. Go to HMS > Cloud Debugging or click the icon shown in the following figure.

  2. On the Select Remote Device page, you can select a required device by Resolution, Android Version, EMUI Version, Series, and Others. Alternatively, you can use Available Devices.

  3. Click or to run or debug the app, respectively, on the remote device. You can also run ADB commands to perform operations. For details, please refer to ADB commands.

[h2]Running or Debugging an App on a Local Real Device

Click or to run or debug the app, respectively, on the local device.

[h2]Viewing Data

Project overview provides the information you need to quickly understand the recent performance of your app. It displays core indicators (such as new users and user activeness), and provides access to event analysis and activity analysis. You can also view other user behavior analysis data by referring to Project Overview.

  1. Click App Debugging on the toolbar to sign in to AppGallery Connect.

  2. Click My projects and select the app for which you want to view the analysis data.
  3. Go to HUAWEI Analytics > Overview > Project overview and view the data.

Using Cloud Testing to Test the APK

  1. Go to HMS > Cloud Testing or click the icon shown in the following figure.

  2. In Cloud Testing, click New Task.

  3. Set the following task parameters and click Confirm to start the test task:
    • Select Category: Test category. You can select Compatibility Test, Stability Test, Performance Test, and Consumption Test.
    • Please Select Apk File: APK file to be tested.
    • Test Devices: Device for app testing. Only one device can be selected for the stability test (Stability Test). For other tests, you can select multiple devices.
    • Test Duration: This parameter is valid only when Select Category is set to Stability Test. This parameter is optional. The value ranges from 10 to 60 minutes.

    • Application Classification: This parameter is valid only when Select Category is set to Performance Test or Consumption Test. This parameter is optional.

  4. After the task is complete, click to view the test report.

    Click Download report to download the report locally. Click to view the test details. For details about the report description of each test, please refer to Operation Guide.

Publish to AppGallery Connect

After developing and debugging an app, Publish to AppGallery Connect helps you to release the APK package to AppGallery Connect.

  1. In HMS, click Publish to AppGallery Connect.
  2. Select the team name and the APK file (with 1 GB at most) to be released, and click Upload.

    When the APK file is uploaded, the following two checks are performed. If an error is reported, modify the file and upload it again.

    • The file must be in release format. For details about how to generate such an APK file, please refer to How do I generate a release.apk file in a project?.
    • The SHA-256 certificate fingerprint has been obtained and configured in the app information in AppGallery Connect. Procedure: Run the following command in the cmd window to read the information value of the APK file, obtain the SHA-256 certificate fingerprint from the information value, and fill in the SHA-256 certificate fingerprint to the app:
      >keytool -printcert -jarfile app-release.apk directory in the project directory

      Set app-release.apk directory in the project directory as required.

  3. After the upload is complete, click RELEASE. On the page that is displayed, go to Release app > Draft.

  4. Enter the information about the app release and submit for review.