Integrating HMS+GMS Ads with Jetpack Compose

Sena Zincircioğlu
Huawei Developers
Published in
4 min readJun 15, 2023
Google and Huawei

Introduction

In the world of mobile applications, monetization plays a crucial role in sustaining and enhancing the user experience. Advertising is one of the primary revenue streams for app developers, and integrating ads seamlessly into Android applications is essential. With the advent of Jetpack Compose, the modern UI toolkit for Android development, developers can create engaging and dynamic user interfaces more efficiently. In this article, we will explore how to integrate HMS+GMS (Huawei Mobile Services + Google Mobile Services) Ads into Android applications built with Jetpack Compose, allowing developers to maximize their revenue potential.

Before we talk about the integration stages, let’s briefly talk about these mobile services and Jetpack Compose.

Understanding HMS+GMS Ads

Huawei Mobile Services (HMS) and Google Mobile Services (GMS) are the app ecosystems provided by Huawei and Google, respectively. Both platforms offer advertising solutions to help developers monetize their applications effectively. By integrating HMS+GMS Ads, developers can reach a wider audience, optimize revenue generation, and deliver targeted ads to users.

GMS and HMS

Jetpack Compose: The Modern UI Toolkit

Jetpack Compose revolutionizes Android app development by simplifying the creation of UIs with a declarative programming model. It enables developers to build dynamic and responsive interfaces efficiently, resulting in enhanced user experiences. Jetpack Compose’s flexible and modular architecture makes it an ideal choice for integrating HMS+GMS Ads seamlessly into Android applications.

Jetpack Compose

Integrating HMS+GMS Ads in Jetpack Compose

To integrate HMS+GMS Ads into your Android application built with Jetpack Compose, follow these steps:

  1. Register your application with both Huawei and Google developer platforms.
  2. Implement the necessary dependencies for HMS and GMS Ads in your app’s build.gradle file.

3. Provide the following permissions and required services to be defined in the `AndroidManifest.xml` file:

4. Set up HMS Ads Kit and GMS Mobile Ads SDK configurations.

5. Create ad units on both platforms and obtain the corresponding ad unit IDs.

6. Design your ad layout using Jetpack Compose components such as Column, Row, and Box.

7. Initialize and load ads programmatically within your Composable functions using the provided APIs.

  • HMS Integration:

To integrate Compose with HMS, create a `HmsAdsView` component like the following example:

HMS Integration with Compose
  • GMS Integration:

To integrate Compose with GMS, create a `GmsAdsView` component like this:

GMS Integration with Compose

8. Customize ad targeting, such as setting geographical location or user preferences, to deliver relevant ads.

9. Handle ad events and implement appropriate actions, such as tracking clicks or displaying reward-based ads.

10. Test your integration thoroughly across different devices and scenarios.

11. Monitor and optimize ad performance using analytics tools provided by both HMS Ads Kit and GMS Mobile Ads SDK.

Note:

You can find detailed information about all configuration and development stages of HMS Ads Kit from this link.

You can find detailed information about all configuration and development stages of Google Ads from this this link.

You can find detailed information about all development stages of Jetpack Compose from this link.

Best Practices for Integration

  • Keep your UI design and ad placement user-friendly and non-intrusive to maintain a positive user experience.
  • Use ad mediation to combine HMS and GMS Ads, maximizing fill rates and revenue potential.
  • Leverage the targeting capabilities of both platforms to deliver more relevant ads to your users.
  • Regularly update the HMS and GMS Ads SDKs to benefit from new features and improvements.
  • Monitor ad performance metrics and make data-driven decisions to optimize revenue generation.

Note:

If you want to monetize from both Google and Huawei Ads, you can performed mediation by integrating Huawei Admob Mediation Plugin to your project. You can access the plugin source codes from this link and also you can refer to this article to learn how to integrate the plugin.

Admob Mediation

Conclusion

Integrating HMS+GMS Ads into Android applications built with Jetpack Compose provides developers with a powerful combination of monetization opportunities. By following the integration steps outlined in this article and adhering to best practices, developers can maximize their revenue potential while delivering a seamless and engaging user experience. With the flexibility and efficiency of Jetpack Compose, developers can create visually appealing interfaces that blend seamlessly with the ads, ensuring a harmonious integration of the advertising component within their applications.

--

--