How We Published a Large Ecommerce App on the Huawei AppGallery Store

Background

Our client is a large retailer with over 250 offline stores across Ukraine, an ecommerce website, and a mobile app development for Android and iOS that we’ve been developing and supporting for the past three years. The Android app has over 100,000 monthly active users, and this number continues to grow.

After the sales of Huawei devices significantly increased in Ukraine, we recommended that our client publish an app on the Huawei AppGallery store to reach a wider audience.

Huawei executives announced that Google services won’t be available for Huawei phones ever again, so all devices from the Huawei Mate 30 series on will support only Huawei Mobile Services

Though there are still many Huawei smartphones that support Google Mobile Services (GMS), the newest devices such as the Huawei Mate 30, Huawei Mate 30 Pro, and Honor V30 only have Huawei Mobile Services (HMS).

The upcoming Huawei P40 and Huawei P40 Pro won’t support GMS either. Huawei executives have announced that Google services won’t be available for Huawei phones ever again, so all devices from the Huawei Mate 30 series will support only Huawei Mobile Services. This means everything from Google Maps to authorization via Google services no longer works on new Huawei devices.

Our goal

Our goal was to publish an existing Android app on Huawei mobile app store that’s called AppGallery.To ensure it would work on all Huawei devices, we needed to implement HMS into the app and release the app to the AppGallery with two sets of services: both HMS and GMS.

Huawei AppGallery adaption services
Are you planning to expand your audience and adapt your app for Huawei Mobile Services? We can help you release your app on Huawei AppGallery

GMS vs HMS

After the US convicted Huawei of installing spy software on its devices, Google banned Huawei from using its services. Huawei then came up with its own GMS alternatives. So, what are Huawei mobile services? They’re services that Huawei developers created to replace the same services from Google. Here are the services that currently replace GMS on Huawei devices:

GMS HMS Description
Google Maps Map Kit An SDK for adding maps to applications; the API provides access to servers, loads data, displays maps, and responds to map gestures
Location Services Location Kit  An API for locating users with the help of all available technologies (GPS, Wi-Fi, and cellular networks)
Google Analytics Analytics Kit An SDK for gathering data with a preinstalled set of analytics models

There’s also a large list of Huawei developer tools like SDKs and APIs that replace both GMS and Firebase services from Huawei App Gallery developers:

  • Account Kit
  • Ads Kit
  • Analytics Kit
  • Awareness Kit
  • Drive Kit
  • Dynamic Tag Manager
  • FIDO
  • Game Service
  • Health Kit
  • Identity Kit
  • In-App Purchases
  • ML Kit
  • Nearby Service
  • Panorama Kit
  • Push Kit
  • Safety Detect
  • Scan Kit
  • Site Kit
  • Wallet Kit
  • WisePlay DRM
  • AppGalleryKit
  • Package Service

This list continues to grow, and Huawei plans to cover all Google Mobile Services with its own alternatives.

How we published an app on the AppGallery store

Now we’ll show you a step-by-step guide to adapting an Android application for the Huawei AppGallery.

There are several approaches to integrating HMS in applications. Some developers duplicate an app, give it another name, and use that copy in AppGallery. This approach isn’t the best, though, as developers will then need to simultaneously support two apps whose code is almost identical.

For our client’s eCommerce app, we chose another solution.

We started by adding a separate flavor into a productFlavors block in the Huawei console app:

flavorDimensions "default"
    productFlavors {
        prodaction {
            dimension "default"
        }
        alternative {
            dimension "default"
            versionNameSuffix "-ALTERNATIV"
        }
        huaweiStore {
            dimension "default"
            applicationIdSuffix ".huawei"
            versionCode 197
            versionName "3.6.1"
        }
    }


In the flavor called huaweiStore we used the same project settings with one exception: we added the .huawei, applicationIdSuffix, as it’s a requirement of AppGallery if you plan to use HMS in your app. We also changed the versionCode and versionName to separate the version count from the primary app. For this flavor, we also needed to create a folder with the path ../app/src/huaweiStore and add the agconnect-services.json file to it. This file will be available after you log in as a developer and register both your app and API in AppGallery.

Then we added a classpath and a link to our Huawei repository to the build.gradle file.

buildscript {
    repositories {
        …
        maven { url 'http://developer.huawei.com/repo/' }
    }
    dependencies {
        ...
       classpath 'com.huawei.agconnect:agcp:1.2.1.300'
   }
...
}

…
allprojects {
    repositories {
        maven { url 'http://developer.huawei.com/repo/' }
    }
}

You’ll also need to add this in your build.gradle file:

apply plugin: 'com.huawei.agconnect'

This is a plugin that will allow you to integrate an agconnect-services.json file with service settings. This file is the analog of google-services.json, and you can get it after registering as a Huawei developer and authorizing your app in AppGallery. Learn more about how to do that here.

Now it’s time to start adding services to our code. First, we created a utility for checking what Google Mobile Services are used in the app.

public static SupportServices howServicesAvailable(Context context) {
        if (isGooglePlayServicesAvailable == null) {
            GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
            HuaweiApiAvailability huaweiApiAvailability = HuaweiApiAvailability.getInstance();
            if (googleApiAvailability.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS) {
                isGooglePlayServicesAvailable = SupportServices.GOOGLE;
            } else if (huaweiApiAvailability.isHuaweiMobileServicesAvailable(context) == com.huawei.hms.api.ConnectionResult.SUCCESS) {
                isGooglePlayServicesAvailable = SupportServices.HUAWEI;
            } else isGooglePlayServicesAvailable = SupportServices.NONE;
        }
        return isGooglePlayServicesAvailable;
    }

Here, SupportServices is a simple enum that lists all possible services in case we need to add any others apart from those that already exist in the app. We’ll be using this utility further to check which services we need to initiate.

switch (Utils.howServicesAvailable(mContext)) {
            case GOOGLE:
                //initialization of Google service
                break;
            case HUAWEI:
                //initialization of Huawei service
                break;
            default:
}

We’ll show you how to integrate two services in one line of code using the Location service as an example.

huawei app appgallery
appgallery review guidelines huawei developers

These are all the classes we have in our Location service:

MainActivity — Checks all permissions and initiates the process of obtaining the Location object with location data that updates every 10 seconds.

LocationManager — A class that initiates a Factory Method pattern. This pattern checks service availability and initiates the abstract class with the object. The type of the object depends on the available service.

AbstractLocationService — An abstract class that actualizes abstract methods of a particular service.

GoogleLocationService and HuaweiLocationService — Derivative classes of AbstractLocationService that realize the methods they get from their parent class. They use these methods to get access to the Location service and its data as well as to call their Location service APIs.

Now let’s see how all these elements work together.

After checking all the necessary permissions, the activity initiates LocationManager, which checks if the services are available. In our case, GMS is of a higher priority, but you can easily change the logic. Depending on the response, LocationManager assigns an instance of the chosen service (GMS or HMS) to the AbstractLocationService class.

private void initLocationService(Context context) {
        switch (Utils.howServicesAvailable(context)) {
            case GOOGLE:
                mLocationService = new GoogleLocationService(context);
                break;
            case HUAWEI:
                mLocationService = new HuaweiLocationService(context);
                break;
            default:
        }
    }

These services then initiate the necessary objects and await responses from AbstractLocationService to receive the location.

Huawei AppGallery adaption services
Are you planning to expand your audience and adapt your app for Huawei Mobile Services? We can help you release your app on Huawei AppGallery

Google Mobile Services example

import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.FusedLocationProviderClient;

...

public GoogleLocationService(Context context) {
        super(context);
        mFusedProvider = LocationServices.getFusedLocationProviderClient(context);
        mSettingClient = LocationServices.getSettingsClient(context);
}

public void startUpdateLocation(){
    ...
}

public void stopUpdateLocation(){
    ...
}

public void getLocation(OnLocationCallback callback){
   ...
}

Huawei Mobile Services

import com.huawei.hms.location.FusedLocationProviderClient;
import com.huawei.hms.location.LocationServices;
import com.huawei.hms.location.FusedLocationProviderClient;

...

public HuaweiLocationService(Context context) {
        super(context);
        mHuaweiFussedProvider = LocationServices.getFusedLocationProviderClient(context);
        mSettingClient = LocationServices.getSettingsClient(context);
}

public void startUpdateLocation(){
    ...
}

public void stopUpdateLocation(){
    ...
}

public void getLocation(OnLocationCallback callback){
   ...
}

As you can see, the difference is minimal. While LocationService is realized, only the import lines will be different, as these services address different SDKs. Also, you can see small differences in methods from AbstractLocationService: startUpdateLocation, stopUpdateLocation, getLocation(OnLocationCallback callback).

You may see greater differences when working with other services. It all depends on the way Google and Huawei work with a particular API or framework.

Latest news in the Huawei world: Harmony OS app development

On the 10th of September, China hosted the Huawei Developer Conference 2020, at which the Chinese tech giant officially unveiled Hongmeng OS 2.0, or Harmony OS 2.0, as it will be called outside of China.

After the conference, Wang Chenglu, President of Huawei’s Consumer Software Division, said that the operating system is already working very well and is completely different from Android.

The Hongmeng OS distribution will regularly add support for new devices, and in the future, each of them will be a peripheral for each other. As conceived by Huawei, this will allow Hongmeng to make a breakthrough in the industry.

Wang Chenglu believes that disconnecting Huawei from Android will definitely do more good than harm. According to him, Huawei still has a contract with Google, but after it is fulfilled by both parties, Hongmeng OS will have more options

Our results

We accomplished our goal in the most efficient way possible by combining two types of services in one application without having to split it into two separate but mostly identical apps.

Now, users of the Honor 9X Pro, View 30 Pro, and Huawei Mate XS can install our client’s app from the listing on AppGallery and use all of its capabilities, including:

  • Push notifications
  • Geolocation
  • In-app payments
  • Gamification features

Also, our client will be able to improve their marketing strategies based on analytics that we implemented through HMS.

We’re now offering all our clients to release their applications on AppGallery. If you ask yourself “Do I need Huawei mobile services integrated into my app?”, the answer is probably yes. Huawei Mobile Services already has over 570 million daily users across the globe, and their AppGallery store is available in 170+ countries. All future Huawei devices are expected to work with HMS, so it’s an important part of the mobile market no developer or business should ignore.

In this article, we’ve provided detailed instructions on how to publish an app on Huawei AppGallery. If you want to do the same for your app, don’t hesitate to contact us.

Huawei AppGallery adaption services
Are you planning to expand your audience and adapt your app for Huawei Mobile Services? We can help you release your app on Huawei AppGallery