Implementation Guide: How to Successfully Integrate Huawei HMS Core 4.0 SDK in an Android App
Introduction
- In past projects, there have been
requests from clients to integrate the Huawei SDK.
I happened to have made some notes before,
so I organized them now
to share with everyone!
Overall development
is actually quite similar to Google GMS XDD
Integrating HMS
- First, you need to go to the Huawei Developer Console to register and join as a verified member.
For detailed instructions, refer to Account Registration and Verification.
- This step is quite similar to other platforms.
You can create it through the user interface.
Next, you need to enable the API permissions you want to use.
This is also done in the console.
- This step is quite similar to Google.
You can use the tool within AS to generate it directly.
After generating, use the command
keytool -list -v -keystore <keystore-file>
keystore-file: Here you need to input the certificate path.
Then paste the generated Sha256 hash into the configuration of the app you just created in the Huawei console.
-
After generating the signature,
you can downloadagconnect-services.json
from the Huawei console.
Then start adding it to your project. -
This image shows the configuration of the project at that time.
Because the product requirement was
to be able to build different vendor configurations when building the project,
and also to support Google services if someone has installed GMS on their Huawei phone,
the configuration is as shown below.
Of course, during actual project development,
it is better to communicate with your team members. -
Because many function names in
HMS
are thesame names
as inGMS
XD,
it is better todistinguish
them clearly during development.
Whether starting fromconfiguration
orcode separation
,
otherwise, it will be very troublesome to maintain later.
If the coupling is too high and difficult to separate, then…
-
Next, add it to the Android project.
Configuremaven {url 'https://developer.huawei.com/repo/'}
in the build gradle. -
Then import the required HMS kit into the project.
Here, taking HMS map as an example.
Now you can officially start development!
- Small differences between Hms and Gms maps
As mentioned earlier, the function names of HMS and GMS are extremely similar
So if you’ve used GMS before, you should be able to get the hang of it quickly (?
However, I happened to beluckier
During development, I encountered
some slight differences
When setting the polyline, the thickness set by the same constant was different
For example,googlePolylineOption.width(5)
vshuaweiPolylineOption.width(5)
The actual effect was differentSo not all logic can be directly applied XDD It’s best to check!!
Finally, it had to be changed like this to be the same
- Small differences in
push notifications
Mainly thesubclass inheritance
is different
Other than that, the usage is the same
But I’m sharing this because
when developing other Huawei features before
the method and class names were almost identical XD
To Summarize
- Apart from the package names being slightly different
and a few functions being slightly different
overall, the usage of the SDKs from both companies is not very different