> ## Documentation Index
> Fetch the complete documentation index at: https://docs.y.uno/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Test in the sandbox first: base URL https://api-sandbox.y.uno (Test Mode in the Dashboard). Production is https://api.y.uno (Live Mode).
> Every API request needs the public-api-key and private-secret-key headers. Get them in the Dashboard at https://dashboard.y.uno/developers (Developers > Credentials); sandbox and production keys are different.
> Send an X-Idempotency-Key (a UUID) when creating payments, refunds and cancels, so retries do not create duplicates.
> Start with the Quickstart (https://docs.y.uno/docs/quickstart.md) and the agent guide (https://docs.y.uno/agents.md). To search these docs from a coding agent, connect the docs MCP server at https://docs.y.uno/mcp.

# Android 注册

> 在 Android 上使用带预构建 UI 的 full-checkout 注册支付方式，并配置 ProGuard

> [!NOTE]
>
> **This page documents a legacy SDK.** Starting a new integration? Use the [Yuno SDK](https://docs.y.uno/docs/yuno-sdk/get-started.md). Already on a legacy SDK? Follow the [migration guide](https://docs.y.uno/docs/yuno-sdk/migration/overview.md).
>
> The new **Yuno SDK** (Web v2.x, iOS v3.x, Android v3.x, React Native v2.x) replaces the Full, Lite, Seamless, Render, Headless, and Secure Fields SDKs with one API across every platform. Legacy SDKs remain supported side by side during the transition and are scheduled for deprecation in **2027**. Contact your Account Manager for migration planning.

Android SDK 让您可以轻松实现注册流程，将支付方式保存到客户账户。

按照与 [full-checkout](https://docs.y.uno/docs/sdks/full-checkout/android-payments#include-the-library-in-your-project) 相同的步骤在项目中引入库。

## 其他资源

* 如果您不确定应采用哪种流程，请参阅[选择适合您的集成方式](https://docs.y.uno/zh-hans/docs/sdks/overview/choose-integration.md)。

* 查看[发布说明](https://docs.y.uno/changelog/android.md)或访问 [Yuno Android SDK 代码库](https://github.com/yuno-payments/yuno-sdk-android)，确认可用的最新 SDK 版本。

* [full-checkout 注册（Android）](#full-checkout-enrollment-android)：使用预构建 UI 组件自动注册

## 要求

* **最低 SDK 版本**：`minSdkVersion` 23 或更高（Android 6.0）。自 Yuno Android SDK 2.24.0 起必需
* **Java**：已启用 Java 8
* **AndroidX**：使用 AndroidX 而非旧版支持库
* **Android Gradle Plugin**：4.0.0 或更高
* **ProGuard**：6.2.2 或更高
* **Kotlin Gradle Plugin**：1.4.0 或更高
* **ELF 页面大小支持**：符合 Google 的 16 KB ELF 页面对齐要求（适配 Android 15 / ARMv9）

### ProGuard / R8 配置

如果您的项目设置了 `minifyEnabled = true`，请将以下规则添加到您的 `proguard-rules.pro` 文件中，以确保 SDK 正常运行，尤其是在 **AGP 8.x+ R8 完整模式**下。

> [accordion] Yuno 官方 ProGuard / R8 规则
>
> ```proguard theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> # Preserve generic type signatures and annotations
> -keepattributes Signature
> -keepattributes *Annotation*
>
> # Yuno SDK
> -keep class com.yuno.** { *; }
> -dontwarn com.yuno.**
>
> # Gson — R8 full mode compatibility
> -keep class com.google.gson.** { *; }
> -keep,allowobfuscation,allowshrinking,allowoptimization class * extends com.google.gson.reflect.TypeToken
> -dontwarn com.google.gson.**
>
> # Retrofit — R8 full mode compatibility
> -keep,allowobfuscation,allowshrinking interface retrofit2.Call
> -keep,allowobfuscation,allowshrinking class retrofit2.Response
> -keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
> -dontwarn retrofit2.**
>
> # OkHttp + Okio — Suppress warnings
> -dontwarn okhttp3.**
> -dontwarn okio.**
> ```
>
> ### 为什么需要这些规则？
>
> AGP 8.x+ 默认启用 **R8 完整模式**，该模式会大幅剥离泛型类型签名。如果没有 `-keepattributes Signature`，Gson 的 `TypeToken<T>` 可能会在运行时失败，并出现 `java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType`。

## 参数

有关参数的完整列表，请参阅 [Android SDK 通用参考](https://docs.y.uno/zh-hans/docs/sdks/resources/references/android.md)。

| 参数 | 说明 |
| - | - |
| `customerSession` | 来自创建客户会话 API 的客户会话 ID。`apiClientEnroll` 必需。 |
| `countryCode` | ISO 国家代码。`apiClientEnroll` 必需。 |
| `showEnrollmentStatus` | 显示注册结果页面。可选，默认为 true。 |
| `callbackEnrollmentState` | Callback `(state, message)`：返回注册状态，并在 `INTERNAL_ERROR` 时返回 [`StatusMessage?`](https://docs.y.uno/zh-hans/docs/sdks/resources/references/android#statusmessage-error-details)。可选，需要在 onCreate 中调用 `initEnrollment`。第二个参数自 SDK `2.22.0` 起新增。 |
| `keepLoader` | 如果为 `true`，SDK 加载指示器会在注册期间保持显示，避免 UI 闪烁。 |

## full-checkout 注册（Android）

适用于 Android 的 Yuno full-checkout 提供带预构建 UI 的注册、卡片注册、状态处理和基本错误管理。请参阅上文的[要求](#requirements)部分。

### 步骤 1：创建客户

在注册支付方式之前，使用[创建客户 endpoint](https://docs.y.uno/reference/customers/create-customer.md) 在 Yuno 系统中创建客户。此 endpoint 会返回 `customer_id`。然后使用[创建客户会话](https://docs.y.uno/reference/customer-sessions-enrollment/create-customer-session.md) endpoint 创建客户会话，调用注册方法时使用返回的 `customer_session`。

同时，在您的服务器上为该客户会话创建[注册支付方式对象](https://docs.y.uno/reference/payment-methods-checkout/enroll-payment-method-checkout.md)，以定义客户可以注册哪种支付方式。请将您的私有 API 密钥保存在服务器上。

### 步骤 2：在项目中引入库

将 Yuno 库添加到您的 Android 项目：

#### 添加代码库

将 Yuno 的 Maven 代码库添加到项目的 Gradle 配置中：

```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
maven { url "https://yunopayments.jfrog.io/artifactory/snapshots-libs-release" }
```

在 `build.gradle` 中添加依赖项：

```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
dependencies {
    implementation 'com.yuno.payments:android-sdk:2.27.0'
}
```

#### 权限

Yuno SDK 默认包含 `INTERNET` 权限，这是发起网络请求所必需的。

```xml theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
<uses-permission android:name="android.permission.INTERNET" />
```

### 步骤 3：使用公钥初始化 SDK

初始化 SDK：

1. 从 [Yuno Dashboard](https://dashboard.y.uno/) 获取您的公共 API 密钥
2. 如果尚未创建，请创建一个自定义 Application 类
3. 在 Application 类的 `onCreate()` 方法中，使用您的 API 密钥调用 `Yuno.initialize()`：

```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
class CustomApplication : Application() {
  override fun onCreate() {
    super.onCreate()
    Yuno.initialize(
      this,
      PUBLIC_API_KEY,
      config = YunoConfig(
        keepLoader = true,
      ),
    )
  }
}
```

使用数据类 `YunoConfig` 自定义 SDK 的行为。调用 `Yuno.initialize()` 时请包含此配置。可用选项如下：

```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
data class YunoConfig(
    val saveCardEnabled: Boolean = false,
    val keepLoader: Boolean = false,
    val language: YunoLanguage? = null,
    val styles: YunoStyles? = null
)
```

> [!NOTE]
>
> 有关 `keepLoader` 参数和必需的错误处理的详细说明，请参阅 [Android 参考指南](https://docs.y.uno/zh-hans/docs/sdks/resources/references/android.md#keeploader-parameter)。

> [!WARNING]
>
> **cardFlow 已从 YunoConfig 中移除**
>
> 从版本 **2.11.0** 起，`cardFlow` 不再属于 `YunoConfig`。卡片流程配置现在只能通过 **CheckoutBuilder** 处理。

### 步骤 4：注册新的支付方式

注册过程分为两步。首先，初始化流程以设置必要的组件。然后，启动 UI 流程，让用户注册支付方式。

#### 4.1 初始化注册流程

在 activity 的 `onCreate` 方法中调用 `initEnrollment` 方法，让您的应用做好处理注册流程的准备。这是 Android 操作系统要求的必需设置步骤，用于注册契约，使 SDK 能够将最终注册状态发送回您的应用。

```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
fun ComponentActivity.initEnrollment(
    callbackEnrollmentState: ((String?, StatusMessage?) -> Unit)? = null
)
```

#### 4.2 启动注册流程

调用 `startEnrollment` 方法以启动用户界面，开始注册新的支付方式。您可以在 `initEnrollment` 执行后的任意时间调用此方法，例如当用户点击“注册新支付方式”按钮时。

```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
fun Context.startEnrollment(
    customerSession: String,
    countryCode: String,
    showEnrollmentStatus: Boolean = true,
    callbackEnrollmentState: ((String?, StatusMessage?) -> Unit)? = null
)
```

`startEnrollment` 参数：

| 参数 | 说明 |
| - | - |
| `customerSession` | 与当前注册流程关联的客户会话。 |
| `countryCode` | 进行支付的国家代码。有关支持的国家及其代码的完整列表，请参阅[国家覆盖范围](https://docs.y.uno/zh-hans/docs/sdks/resources/country-coverage.md)。 |
| `showEnrollmentStatus` | 指示是否显示注册状态。此参数为可选参数，默认为 `true`。 |
| `callbackEnrollmentState` | 一个函数 `(state, message)`，返回注册流程的当前状态，并在 `INTERNAL_ERROR` 时返回描述失败原因的 [`StatusMessage?`](https://docs.y.uno/zh-hans/docs/sdks/resources/references/android#statusmessage-error-details)（已拒绝的注册不携带消息）。可选，默认为 `null`。要注册此 callback，您必须在 activity 的 `onCreate` 方法中调用 `initEnrollment`。请查看可能返回的状态。 |

## 通用参考

有关完整的参数和自定义详情，请参阅 [Android SDK 通用参考](https://docs.y.uno/zh-hans/docs/sdks/resources/references/android.md)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.