There are a couple ways to handle this. Of course you can choose to maintain 2 sets of source code, which is highly not recommended, and you can choose to keep libraries from both sides, detect which service is available and call them accordingly. I would however recommend implementating different product flavours and build your product according to the platform.
android{
flavorDimensions "default"
productFlavors{
hmsVersion{
//select the dimension of flavor
dimension "default"
//Configure this flavor specific app name published in Huawei App Gallery
resValue "string", "flavored_app_name", "App name"
}
gmsVersion{
//select the dimension of flavor
dimension "default"
//Configure this flavor specific app name published in Play Store
resValue "string", "flavored_app_name", "App Name"
}
}
}
and then you can do something like this
// HMS Flavor
hmsVersionImplementation 'com.huawei.hms:hianalytics:4.0.3.300'
// GMS Flavor
gmsVersionImplementation 'com.google.firebase:firebase-analytics:17.4.0'