A professional Jetpack Compose library for Huawei Maps (HMS Map Kit). This SDK allows you to easily integrate Huawei Maps into your Android applications using a Compose-first architecture, following the same patterns as the official Google Maps Compose library.
Huawei Maps Compose provides a declarative way to build map-based UIs on Huawei devices. It bridges the gap between the imperative Huawei Map SDK and Jetpack Compose, offering a seamless developer experience for HMS-core applications.
Whether you are building a dedicated HMS app or a multi-flavor application supporting both GMS and HMS, this SDK provides the tools needed to maintain a clean, modern codebase.
- 🧩 Compose-first: Fully declarative API for map initialization and UI components.
- 📍 Markers: Add and customize markers with ease.
- 🎥 Camera Control: Sophisticated camera state management with
CameraPositionState. - 📐 Shapes: Support for Polylines, Polygons, and Circles.
- 🗺️ Map Settings: Simple toggles for UI settings (zoom, compass, etc.) and map properties.
- 🔄 Lifecycle Aware: Automatic handling of map lifecycle events within Composables.
- 🏗️ Flavor Support: Designed to work side-by-side with GMS-based projects using product flavors.
- 🛡️ Type Safe: Fully written in Kotlin with strict null-safety.
- Minimum SDK: 21+
- Kotlin: 2.0.0+ (Recommended
2.2.21) - Compose Compiler: Compatible with your Kotlin version
- Huawei HMS Core: Installed on the target device
- Huawei Developer Account: Registered and configured in AppGallery Connect
Add the following to your build.gradle.kts files:
In your settings.gradle.kts:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://developer.huawei.com/repo/") }
maven { url = uri("https://jitpack.io") }
}
}In your module-level build.gradle.kts:
dependencies {
implementation("com.github.malikbilal1997:huawei-maps-compose:Tag")
}
apply(plugin = "com.huawei.agconnect")To use Huawei Maps, you must configure your project in AppGallery Connect:
- Create Project: Register your app in the Huawei AppGallery Connect console.
- Enable Map Kit: Navigate to Project Settings > Manage APIs and enable Map Kit.
- SHA-256 Certificate: Add your app's SHA-256 fingerprint in Project Settings.
- Download Config: Download the
agconnect-services.jsonfile. - Place File: Move
agconnect-services.jsonto your app module's root directory (app/).
For production apps, it is best practice to support both GMS and HMS using product flavors. This keeps your APK size small and ensures compatibility across all devices.
android {
flavorDimensions.add("provider")
productFlavors {
create("gms") {
dimension = "provider"
}
create("hms") {
dimension = "provider"
}
}
}Organize your code to abstract the map implementation:
src/main: Common logic and UI.src/gms: GMS-specific implementation (usinggoogle-maps-compose).src/hms: HMS-specific implementation (usinghuawei-maps-compose).
Create a common interface for your Map UI:
// src/main/java/com/example/app/MyMap.kt
@Composable
expect fun MyMap(
modifier: Modifier,
cameraPosition: LatLng,
onMapClick: (LatLng) -> Unit
)Implement it in the respective flavor folders using the appropriate SDK.
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.huawei.hms.maps.model.CameraPosition
import com.huawei.hms.maps.model.LatLng
import com.google.maps.android.compose.*
@Composable
fun MapScreen() {
val singapore = LatLng(1.35, 103.87)
val cameraPositionState = rememberCameraPositionState {
position = CameraPosition.fromLatLngZoom(singapore, 10f)
}
HuaweiMap(
modifier = Modifier.fillMaxSize(),
cameraPositionState = cameraPositionState
) {
Marker(
state = rememberMarkerState(position = singapore),
title = "Singapore",
snippet = "Marker in Singapore"
)
}
}HuaweiMap(modifier = Modifier.fillMaxSize()) {
Polyline(
points = listOf(
LatLng(1.35, 103.87),
LatLng(1.40, 103.90)
),
color = Color.Blue,
width = 5f
)
}To maintain a scalable map integration, we recommend:
- Dependency Injection: Use Hilt or Koin to inject map-related configurations based on the detected environment (GMS vs HMS).
- Repository Pattern: Abstract location and map data fetching into repositories.
- Clean Separation: Keep your Domain models (like a custom
MapLocationclass) separate from SDK-specific models (com.huawei.hms.maps.model.LatLng). Use mappers to convert between them.
| Issue | Possible Solution |
|---|---|
| Map is blank | Ensure agconnect-services.json is in the correct folder and Map Kit is enabled in AGC. |
| API Key Error | Verify that your SHA-256 certificate in AGC matches your signing key. |
| HMS Core Missing | Huawei Maps requires HMS Core installed on the device. It will not work on standard GMS-only devices. |
| Markers not showing | Check if the MarkerState is being updated correctly within the Composable lifecycle. |
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the Apache 2.0 License. See LICENSE for more information.