Have both GMS and HMS in the project
So, I managed to do it like this:
Defined two flavours
gms {
dimension "services"
buildConfigField "String", "SERVICE_USED", '"g"'
}
hms {
dimension "services"
buildConfigField "String", "SERVICE_USED", '"h"'
}
I use the "g" and "h" in the code whenever I need to decide on doing things like: the API requires a deviceType
of "android" or "iOS" and with the inclusion of the Huawei build we defined another constant "huawei". I use SERVICE_USED
to know what constant to send.
I then did this at the top of the build.gradle:
apply plugin: 'com.android.application'
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Hms")) {
//*meh*
} else {
apply plugin: 'io.fabric'
}
because I was using fabric (and fabric / firebase ... don't really work with HMS) and I also did this at the very bottom of the build.gradle
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Hms")) {
apply plugin: 'com.huawei.agconnect'
} else {
apply plugin: 'com.google.gms.google-services'
}
to only include the proper plugin.
I then started handling each thing that was using gms
(maps, location, push notifications, analytics ) by making a wrapper and separating the code in each flavour. i.e. for push notifications i created a HPushNotif
which has an getToken
method. I define the same class and method in both flavours but I implement them according to the type of service (gms or hms).
I used this type of notation when including dependencies in the project:
//GMS stuff
gmsImplementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
gmsImplementation 'com.google.firebase:firebase-core:16.0.9'
gmsImplementation 'com.google.firebase:firebase-messaging:18.0.0'
gmsImplementation 'com.google.firebase:firebase-crash:16.2.1'
gmsImplementation 'com.google.android.gms:play-services-maps:16.1.0'
gmsImplementation 'com.google.android.gms:play-services-location:16.0.0'
gmsImplementation 'com.google.android.gms:play-services-tagmanager:16.0.8'
//HMS stuff
hmsImplementation 'com.huawei.agconnect:agconnect-core:1.0.0.300'
hmsImplementation 'com.huawei.hms:push:4.0.3.301'
hmsImplementation 'com.huawei.hms:maps:4.0.1.301'
hmsImplementation 'com.huawei.hms:location:4.0.3.303'
The gms
and hms
before the Implementation
refer to the name of the flavours. Those dependencies will only be loaded when the appropriate BuildVariant is selected (i.e. appropriate flavour is being built).
Basically I wrapped the logic for maps, analytics, location and push notifications for both cases. This is how the structure looks. Nothing special.
That's it. When they created HMS they basically copied GMS class by class and methd by method. You'll see that the exact method names match exactly, to the calling parameters even and returning values. They're 99.99% the same. That makes things easier. Basically you just need to copy the code in two classes and import the proper things (at the top of the class). You rarely need to change the code you've already written for GMS.
Hope it helps someone.
If a Huawei device is supporting both GMS and HMS core then why HMS core is not working?
You are advised to use the solution for integrating both GMS and HMS. The advantages are as follows:
- Reduce the complexity of app packaging. A package can be released to both Google Play and HUAWEI AppGallery.
- Reduce the code maintenance cost. The HMS+GMS adaptation layer code is added to the original logic code. In this way, proper code can be automatically called based on the mobile phone. That is, you do not need to modify existing logic code or maintain two sets of code.
It is recommended that you use HUAWEI HMS ToolKit, which can help you quickly add the HMS+GMS adaptation layer code and upgrade your logic code to support both GMS and HMS.
For details, You may refer to this question: Have both GMS and HMS in the project.
HMS Huawei management service
I communicated with Huawei support team, since i'm not using any of GMS services, they reviewed the package and then they published it on app gallery.
Related Topics
How to Get All Android Contacts But Without Those Which Are on Sim
How to Set Internet Options for Android Emulator
Asynctask and Looper.Prepare() Error
Android - Set Text to Textview
Scan_Results_Available_Action Return Empty List in Android 6.0
Implementation of Onscrolllistener to Detect the End of Scrolling in a Listview
Firebase (Fcm): Open Activity and Pass Data on Notification Click. Android
How to Find Older Versions of Eclipse Adt
Android How to Display 2 Listviews in One Activity One After the Other
"Unable to Locate Adb" Using Android Studio
Access the Http Response Headers in a Webview
Android ==> Memory Analysing ==> Eclipse Memory Analyzer
Android - File Provider - Permission Denial
Couldn't Locate Lint-Gradle-Api-26.1.2.Jar for Flutter Project
Android Error - Open Failed Enoent
How to Programmatically Scroll a Scroll View to a Specific Edit Text