HMS and GMS in Flutter app - classes of the same name with different implementation

Viewed 499

I've seen solutions like:

Have both GMS and HMS in the project

to have both GMS and HMS in java based android apps.

Is it possible to do simillar thing in flutter app? I can set the use of different plugins in build.gradle, but is it possible to have the same named classes with different implementation, like in the example above?

2 Answers

Currently, only Java is supported. For other development language, like Flutter, is under analysis and evaluation. It could be supported in a cross-platform IDE in the future release.

Update

The Google Play APK can contain both GMS Ads and HMS Ads without conflicting. Therefore, flavors do not need to be differentiated. You can rename different classes when using, as follows:

import 'package:huawei_ads/hms_ads_lib.dart' as hms_ads;
import 'package:google_mobile_ads/google_mobile_ads.dart' as gms_ads;

hms_ads.BannerAd? _testads;
gms_ads.BannerAd? _testads2;

enter image description here


Currently, the Flutter plug-in of the HMS is available. However, the interfaces in the plug-in are different from those in the GMS. You may need to call the plug-in based on the phone`s environment (G or H).

Overview of Flutter plug-ins Support,see Docs.

Related