Convertor is a code conversion tool supporting Java and Kotlin projects. This tool can help you quickly convert the existing Android app code for calling third-party APIs into the app code integrated with the HMS Core. The tool provides the following functions to help you complete the conversion:
The following figure shows the code conversion process.

One advantage of this conversion policy is that you can use a set of code to call third-party APIs or HMS APIs as well as release the app in third-party app stores and on HUAWEI AppGallery at the same time. The XMS Adapter automatically generated by the tool schedules third-party APIs and HMS APIs, and separates or decouples service code from adapter code. You just pay attention to services, and do not need to spend much time on the differences between third-party APIs and HMS APIs.
For details about the principle, please refer to Add HMS API Policy.
The figure below shows the Convertor menu entry.

The Convertor converts selected code, but will not convert the third-party packages on which the project is dependent.
If you import dependencies using the compile keyword in the project, change the keyword to implementation.
The following table lists the HMS API conversion supported by each kit.
Kit | To HMS API | Add HMS API |
|---|---|---|
Account | Supported | Supported |
In-App Purchases | Supported | Not supported |
Push | Supported | Supported |
Ads | Supported | Supported |
Analytics | Supported | Supported |
Location | Supported | Supported |
Map | Supported | Supported |
Game Service | Supported | Supported |
Drive | Supported | Not supported |
Wallet | Supported | Supported |
Health | Supported | Supported |
ML | Supported | Supported |
Awareness | Supported | Supported |
Scan | Supported | Supported |
Nearby Service | Supported | Supported |
Safety Detect | Supported | Supported |
Dynamic Tag Manager | Supported | Not supported |
Identity | Supported | Supported |
Panorama | Supported | Supported |
HMS Core base | Supported | Supported |
FIDO | Supported | Supported |
Remote Configuration | Supported | Supported |
Crash | Supported | Supported |
Cloud Functions | Supported | Supported |
App Linking | Supported | Supported |
Auth Service | Supported | Supported |
App Messaging | Supported | Supported |
APM | Supported | Supported |
Cloud Storage | Supported | Supported |
For the Add HMS API policy, you will need to make the following modifications:
For the Add HMS API policy, you will need to make the following modifications:
If the intent.getXXX() or intent.putXXX() method is used, manually write code for the Add HMS API policy. Example:
Code for using the GMS API:
DetectedActivity detectedActivity = ...; Intent intent = new Intent(BROADCAST_INTENT_ACTION); intent.putExtra(DETECTED_ACTIVITY_EXTRA_ID, detectedActivity);
DetectedActivity detectedActivity = ...;
Intent intent = new Intent(BROADCAST_INTENT_ACTION);
if (org.xms.g.utils.GlobalEnvSetting.isHms) {
intent.putExtra(DETECTED_ACTIVITY_EXTRA_ID, (com.huawei.hms.location.ActivityIdentificationData)detectedActivity.getHInstance());
} else {
intent.putExtra(DETECTED_ACTIVITY_EXTRA_ID, (com.google.android.gms.location.DetectedActivity)detectedActivity.getGInstance());
} The animation below illustrates the analysis and conversion process for a project.


If Project Type is set to App, XMS Adapter code is generated in the XMS Adapter module. You will see the following results after the analysis.

If Project Type is set to Library, you will see the following results after the analysis.

Key Field | Description |
|---|---|
Update the following items before analysis | Before the conversion starts, make sure to:
|
Analysis Result | Statistics on GMS APIs used in the project. Click Details to view the GMS API usages in the current project. |
Add HMS API |
|
To HMS API | Convert GMS APIs into HMS APIs so that your app can run on any Huawei device. |
HMS API First | Configure your routing policy to preferentially call HMS APIs when your app is installed on devices that support HMS APIs but do not support GMS APIs. |
GMS API First | Configure your routing policy to preferentially call GMS APIs when your app is installed on devices that support GMS APIs but do not support HMS APIs. |
Dependent GMS APIs | GMS APIs and GMS methods used in the current project. |
Convertible GMS Methods | The number of GMS methods that can be converted automatically and manually, and the automatic conversion rate, under the two conversion policies. |
Unconvertible GMS APIs | GMS APIs that are not compatible under each conversion policy. Select an appropriate conversion policy based on this result. |
Unconvertible GMS Methods | The number of GMS methods that are not supported by HMS. Click Details to view more information. |
Select a conversion policy | Conversion policy. In the Add HMS API policy, you can set to prioritize HMS APIs or GMS APIs. |
Generate code for creating app dependent only on GMS SDK | Under the Add HMS API policy, the ability to generate differentiated adapter code is provided to help developers build APKs dependent only on GMS. If this option is selected, a prompt will be displayed. Click the link in the prompt to view details in the document. |
Generate code for creating app dependent only on HMS SDK | Under the Add HMS API policy, the ability to generate differentiated adapter code is provided to help developers build APKs dependent only on HMS. If this option is selected, a prompt will be displayed. Click the link in the prompt to view details in the document. |
Path for storing the generated code (for Add HMS API only) | Under the Add HMS API policy, XMS Adapter code is stored in the XMS Adapter module in the root path of the project. |
Export analysis result | Statistics on GMS APIs used in the project. Click Export analysis result to export the GMS API usages in the current project. |
Based on the HMS API or GMS API routing policy selected during conversion, you need to call the GlobalEnvSetting.init method in the project to determine whether the app will run in the HMS or GMS environment. For details about how to set the route, please refer to Route Initialization Policy in the Add HMS API Scenario.
This method can be used to check whether the current mobile phone can run HMS or GMS.

Key Field | Description |
|---|---|
Show Converted |
NOTE: Only the results for the current analysis are displayed. If you scan the project again after processing it, the records of the last scan cannot be viewed. |
Convert | Converts the selected records. |
Revert | Undoes automatic conversion of selected items. Currently, pressing Ctrl+Z to undo the conversion is not supported. |
Total | Total number of items to be processed. |
Converted | Total number of records of GMS APIs that have been converted. |
Conversion Type | Conversion types available for the scanning results. The options are as follows:
|
Content | Original content to be converted. |
Description | Conversion description. |
The animation below illustrates how to process analysis results.

According to the analysis results, some GMS APIs can be automatically converted by the IDE, while others require manual conversion.
The Auto and Dummy types can be converted in one of the following ways:


to synchronize the content in Fix File to Original File, and close the page. The conversion is complete.
The information in Fix File cannot be edited.
After the conversion is complete, the conversion analysis result page is displayed, on which the converted item is dimmed and selected. To roll back the conversion, select the item and click Revert.

Conversion method for the Manual type: Click the item to be converted to have the corresponding code displayed, then modify based on the description in the scanning results. After the modification, manually change the check box of the item from
to
.
After all the items are converted and the status changes to
or
, a message is displayed, asking you whether to check the integrity. Click Jump to go to the integrity check page.

Manual Instruction (currently, only Map Kit and Location Kit support this function):
You will get help from Manual Instruction when you need to perform manual conversion by HMS Toolkit. Click the Location Kit or Map Kit item to be manually converted in Conversion and click Go to Manual Instruction in the following figure. The Manual Instruction window is displayed.

The following figure shows the Manual Instruction window.


After the project is created, a dialog box shown in the following figure is displayed in the lower right corner. Click Open Project to open the project using Android Studio.

In the Add HMS API scenario, you will need to implement the code logic conversion based on the service context. The following APIs are used in Add HMS API scenarios, and may be involved during the conversion of all kits. For details about how to use the APIs, please refer to the manual conversion guide of each kit, which can be obtained by clicking the Description link in the manually modified item.
API | Description |
|---|---|
org.xms.g.utils.GlobalEnvSetting.isHms() | Determines the route during manual conversion. |
org.xms.g.utils.GlobalEnvSetting.useGms() | Sets the GMS route for dynamic route switchover after sign-in. |
org.xms.g.utils.GlobalEnvSetting.useHms() | Sets the HMS route for dynamic route switchover after sign-in. |
Object getGInstance() | Obtains the corresponding GMS or HMS instance from the Adapter instance. |
Object getHInstance() | |
org.xms.g.utils.Utils.getXmsObjectWithGmsObject(Object object) | Obtains the corresponding Adapter instance from the GMS instance.
|
org.xms.g.utils.Utils.getXmsObjectWithHmsObject(Object object) | Obtains the corresponding Adapter instance from the HMS instance.
|
isInstance | Called by the IDE plug-in to replace the instanceof keyword in Java and convert obj instanceof G to X.isInstance(obj). |
dynamicCast | Called by the IDE plug-in to forcibly convert the Java type from (G)obj to X.dynamicCast(obj). |
After all records are processed, compile the file. After the compilation is successful, the conversion is complete.
Go to HMS > Convertor > Open Last Conversion to open the last conversion results, that is, the last conversion analysis results.

If you have not finished processing all conversion items, but have closed Android Studio or the project, and reopened the project, you can load the project records in this way and go on with the conversion. It is not recommended that you use this method in other scenarios.
You can save the project and conversion information.
For a large-scale project, if you have performed conversion for some items, and wish to back up the project code in progress and conversion list, click Save All. You can then click Restore Project to restore the project from the backup progress and continue conversion.
The backup path is set during the last scan, and the backup .zip file is named in format of project name+timestamp+comment mode+conversion policy+conversion progress.
Go to HMS > Convertor > Restore Project to open the restoration page of the backup project, and restore the file in the archive path to the required path.
After restoring the backup file, manually select the current project path in the work tree, right-click the path and click Reload from Disk to update it. There are two types of backup files:

If you have modified XMS Adapter code or added kits, Convertor will generate new XMS Adapter code based on the new build.gradle file and is also able to show you the differences between the old and new XMS Adapter code. The following illustrates the two scenarios where new XMS Adapter code is generated.
Modify XMS Adapter code and generate new XMS Adapter code. New XMS Adapter code is generated in the XMS Adapter module, and the old code is backed up. Additionally, Convertor can compare the old and new code.


