Files
zhini_im/荣耀推送集成sdk.txt
rw0067680 c01808ac21 first commit
Change-Id: Ib7c2ab10a2562044fcaf9879388a6cbc1db6ac61
2025-12-23 10:00:49 +08:00

199 lines
5.7 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
针对 Android Studio 开发环境,荣耀提供了 Maven 仓集成方式的 SDK 包。
配置开发环境
引入 asplugin 插件需要在 Android studio 中配置 gradle 的 jdk 版本为 1.8 以上。
添加应用配置文件
登录荣耀开发者服务平台网站,点击应用管理。
在应用列表中找到您需要集成 SDK 的应用,点击应用详情。
在应用基础信息查看页面的SDK 配置区域,点击 mcs-services.json 下载配置文件。
将 mcs-services.json 文件拷贝到应用级根目录下。
配置 SDK 的 Maven仓地址
Android Studio 的代码库配置在 Gradle 插件7.0以下版本、7.0版本和7.1及以上版本有所不同。请根据您当前的 Gradle 插件版本,选择对应的配置过程。
7.0以下版本 7.0版本 7.1及以上版本
注意:
Maven 仓地址无法直接在浏览器中打开访问,只能在 IDE 中配置。如需添加多个 Maven 代码库,请将荣耀的 Maven 仓地址配置在最后。
7.0以下版本
打开 Android Studio 项目级 build.gradle 文件。
添加 asplugin 插件以及 Maven 代码库。
在 buildscript > repositories 中配置 SDK 的 Maven 仓地址。
在 allprojects > repositories 中配置 SDK 的 Maven 仓地址。
如果 App 中添加了 mcs-services.json 文件则需要在 buildscript > dependencies 中增加 asplugin 插件配置。
buildscript {
repositories {
google()
jcenter()
// 配置SDK的Maven仓地址。
maven {url 'https://developer.hihonor.com/repo'}
}
dependencies {
...
// 增加asplugin插件配置推荐您使用最新版本。
classpath 'com.hihonor.mcs:asplugin:2.0.1.300'
// 增加gradle插件配置根据gradle版本选择对应的插件版本号
classpath 'com.android.tools.build:gradle:4.1.2'
}
}
allprojects {
repositories {
google()
jcenter()
// 配置SDK的Maven仓地址。
maven {url 'https://developer.hihonor.com/repo'}
}
}
7.0版本
打开 Android Studio 项目级build.gradle文件。
添加 asplugin 插件以及 Maven 代码库。
在 buildscript > repositories 中配置 SDK 的 Maven 仓地址。
如果App中添加了 mcs-services.json 文件则需要在 buildscript > dependencies 中增加 asplugin 插件配置。
buildscript {
repositories {
google()
jcenter()
// 配置SDK的Maven仓地址。
maven {url 'https://developer.hihonor.com/repo'}
}
dependencies {
...
// 增加asplugin插件配置推荐您使用最新版本。
classpath 'com.hihonor.mcs:asplugin:2.0.1.300'
// 增加gradle插件配置根据gradle版本选择对应的插件版本号
classpath 'com.android.tools.build:gradle:7.0'
}
}
打开项目级 settings.gradle 文件,配置 SDK 的 Maven 仓地址。
dependencyResolutionManagement {
...
repositories {
google()
jcenter()
// 配置SDK的Maven仓地址。
maven {
url 'https://developer.hihonor.com/repo'
}
}
}
7.1及以上版本
打开 Android Studio 项目级 build.gradle 文件。
如果 App 中添加了 mcs-services.json 文件则需要在 buildscript > dependencies 中增加 asplugin 插件配置。
buildscript {
dependencies {
...
// 增加asplugin插件配置推荐您使用最新版本。
classpath 'com.hihonor.mcs:asplugin:2.0.1.300'
// 增加gradle插件配置根据gradle版本选择对应的插件版本号
classpath 'com.android.tools.build:gradle:7.1.+'
}
}
打开项目级 settings.gradle 文件,配置 SDK 的 Maven 仓地址。
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
// 配置SDK的Maven仓地址。
maven {
url 'https://developer.hihonor.com/repo'
}
}
}
dependencyResolutionManagement {
...
repositories {
google()
mavenCentral()
// 配置SDK的Maven仓地址。
maven {
url 'https://developer.hihonor.com/repo'
}
}
}
添加依赖配置
打开应用级的 build.gradle 文件。
在 dependencies 中添加如下编译依赖。
dependencies {
// 添加如下配置,推荐您使用最新版本。
implementation 'com.hihonor.mcs:push:8.0.12.307'
}
注意:
建议您集成的 SDK 使用最新版本号,版本号索引请参见版本信息。
添加 asplugin 插件配置。请根据实际情况选择:
Gradle 7.0 以下添加方式:在文件头部声明下一行添加如下配置。
apply plugin: 'com.hihonor.mcs.asplugin'
Gradle 7.0 以上添加方式在plugins中添加如下配置。
plugins {
// 添加如下配置
id 'com.hihonor.mcs.asplugin'
}
配置签名
将生成签名证书指纹步骤中生成的签名文件拷贝到工程的 app 目录下,在 build.gradle 文件中配置签名。
android {
signingConfigs {
config {
// 根据您实际的签名信息替换以下参数中的xxxx
keyAlias 'xxxx'
keyPassword 'xxxx'
storeFile file('xxxx.jks')
storePassword 'xxxx'
}
}
buildTypes {
debug {
signingConfig signingConfigs.config
}
release {
signingConfig signingConfigs.config
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
同步工程
在完成以上的配置后,点击工具栏中的 gradle 同步图标完成 build.gradle 文件的同步,然后将相关依赖下载到本地。
注意:
如果出现错误,请检查网络连接是否正常,以及检查 build.gradle 文件是否正确。
上一篇