Antom, leading provider of tailored payment solutionsAntom, leading provider of tailored payment solutions

Android 端集成 SDK 资源包

本文为您介绍如何通过 Maven 和手动方式快速集成 Android SDK 资源包。

Maven 集成

请按照以下步骤通过 Maven 集成 SDK 资源包。

  1. 添加 Maven 库:

在项目根目录的 build.gradle 文件中增加如下代码配置:

copy
allprojects {
    repositories {
        maven{
            credentials{
                username "antomsdk@aliyun.com"
                password "Admin1234"
            }
            url "https://globaltech.alipay.com/api/v1/file/repository/antom/"
        }
        // other repositories
        // -------
    }
}
  1. 添加 Maven 依赖:

使用下面代码在 build.gradle 文件中添加依赖项。

copy
// in app build.gradle
// if there are some conflicts with existing sdk, please exclude them
dependencies {
    implementation "com.alipay.antom.sdk:payment-component:${antom_version}"
}

将下面代码中 ANTOM_VERSION 的值替换为最新版本号 1.34.0,以便在 build.gradle 文件中外部化版本号,进行代码升级管理。

copy
ext {
    antom_version = 'ANTOM_VERSION'
}
  1. (可选)集成安全扩展包:

为减少在支付流程中触发更多的安全挑战,Antom 为您提供了 SDK 安全扩展包。如果您想要集成安全扩展包,使用下面代码在 build.gradle 文件中添加 Maven 依赖即可。

copy
dependencies {
    implementation "com.alipay.antom.sdk:securitysdk:1.1.0"
}

集成安全扩展包后,需注意以下事项:

  • 使用 Apache HttpClient:
    • 在项目的根目录配置文件 build.gradle 中声明使用 org.apache.http.legacy 库。
copy
android {
    useLibrary 'org.apache.http.legacy' // 支持 HttpClient
    ......
        }
    • 在清单文件 AndroidManifest.xml 中声明使用 org.apache.http.legacy 库。
copy
<application>
  <uses-library android:name="org.apache.http.legacy" android:required="false"/>
</application>
copy
dependencies {
    implementation 'com.alibaba:fastjson:1.1.70.android'
}

手动集成

如果您不使用 Maven 集成,Antom 还为您提供手动集成方式。请按照以下步骤手动集成资源包:

  1. 下载 SDK 资源包

开发者中心 下载最新版 SDK 资源包,下载路径如下: Resources > Download Detail > Android,选择对应的产品包,点击 View the download address of this package 下载。首次下载需要同意下载协议。

  1. 将解压得到的 .aar 编译文件放置到当前工程应用下的 libs 文件夹下。
  2. 在项目根目录 build.gradle 文件中声明 .aar 编译文件的引用依赖。
copy
dependencies {
    // 配置 SDK aar 包。确保将“xxxxx”替换为下载包的实际版本号。
    implementation(name: 'ams-component-sdk-release-xxxxx', ext: 'aar')

    // 配置 AlipaySDK aar 包。
    implementation(name: 'alipaysdk-android-15.8.14', ext: 'aar')
}