# Huawei Configuration

## Overview

MyID SDK supports Huawei devices that use **Huawei Mobile Services (HMS)** instead of **Google Play Services (GMS)**.

If your app runs on Huawei devices (for example, Mate or P series) **without GMS**,
you must add the **MyID Integrity SDK** and configure your Huawei **App ID**.

If this dependency is **missing** and the device **supports HMS**,
the MyID SDK will **crash during initialization**.

---

## Table of contents

* [1. Add the Huawei Integrity SDK](#1-add-the-huawei-integrity-sdk)
* [2. Configure the App ID](#2-configure-the-app-id)
* [3. Pass Huawei App ID to the SDK](#3-pass-huawei-app-id-to-the-sdk)
* [4. Example setup](#4-example-setup)
* [5. Enable Safety Detect in AppGallery Connect](#5-enable-safety-detect-in-appgallery-connect)
* [6. Troubleshooting](#6-troubleshooting)

---

## 1. Add the Huawei Integrity SDK

Add the following dependency to your **module-level** `build.gradle` file:

```gradle
dependencies {
    implementation("uz.myid.sdk.capture:myid-integrity-sdk:3.1.9")
}
```

This library enables the SDK to handle Huawei Mobile Services (HMS)
and prevents runtime crashes on Huawei devices.

---

## 2. Configure the App ID

You need a valid **Huawei App ID** from **AppGallery Connect**.

1. Open [AppGallery Connect](https://developer.huawei.com/consumer/en/service/josp/agc/index.html).
2. Go to your project → **App information**.
3. Copy your **App ID**.
4. Add it to your `AndroidManifest.xml` inside the `<application>` tag:

```xml
<meta-data
    android:name="com.huawei.hms.client.appid"
    android:value="appid=YOUR_HUAWEI_APP_ID" />
```

Replace `YOUR_HUAWEI_APP_ID` with your actual App ID.

---

## 3. Pass Huawei App ID to the SDK

When initializing `MyIdConfig`, include your Huawei App ID using the `withHuaweiAppId()` method:

```kotlin
val config = MyIdConfig.Builder(clientId = "YOUR_CLIENT_ID")
    .withClientHash("YOUR_CLIENT_HASH", "YOUR_CLIENT_HASH_ID")
    .withEnvironment(MyIdEnvironment.Production)
    .withHuaweiAppId("YOUR_HUAWEI_APP_ID")
    .build()
```

This ensures that the SDK recognizes and properly initializes HMS support.

---

## 4. Example setup

**Gradle dependencies:**

```gradle
dependencies {
    implementation("uz.myid.sdk.capture:myid-integrity-sdk:3.1.9")
}
```

**Initialization:**

```kotlin
val config = MyIdConfig.Builder(sessionId = "SESSION_ID")
    .withClientHash("CLIENT_HASH", "CLIENT_HASH_ID")
    .withEnvironment(MyIdEnvironment.Production)
    .withHuaweiAppId("YOUR_HUAWEI_APP_ID")
    .build()

val intent = MyIdClient().createIntent(this, config)
startActivity(intent)
```

---

## 5. Enable Safety Detect in AppGallery Connect

To successfully publish the application in the Huawei AppGallery console, it is necessary to enable and configure the **Safety Detect** service in AppGallery Connect.

**Step-by-step configuration guide:**

1. Open **Huawei AppGallery Connect** and sign in to your Huawei Developer account.
2. Open your project: **Development and services → Select your application**.
3. Go to **Manage APIs → Security → Safety Detect**.
4. Turn the toggle on to activate the Safety Detect service for the selected application.
5. Add the **SHA-256 certificate fingerprint**: **Project settings → App information → Add SHA-256 certificate fingerprint**.
6. Download the updated `agconnect-services.json` file and replace it in the Android project directory: `app/agconnect-services.json`.
7. Configure the SDK: see the [HUAWEI-CONFIGURATION guide](#1-add-the-huawei-integrity-sdk).
8. Sync Gradle and rebuild the project.
9. Verify that Safety Detect is correctly initialized and working before submitting the application for review in AppGallery.

---

## 6. Troubleshooting

| Issue                                  | Cause                           | Solution                                                             |
| -------------------------------------- | ------------------------------- | -------------------------------------------------------------------- |
| SDK crashes on Huawei devices          | `myid-integrity-sdk` not added  | Add `implementation("uz.myid.sdk.capture:myid-integrity-sdk:3.1.9")` |
| SDK fails to initialize                | Missing App ID                  | Add `.withHuaweiAppId("YOUR_HUAWEI_APP_ID")`                         |
| Invalid App ID error                   | Wrong App ID in manifest or SDK | Recheck AppGallery Connect for correct ID                            |
| Works on Google devices but not Huawei | HMS dependency missing          | Make sure Integrity SDK is included                                  |
