# SDK 配置

# 1、SDK 说明

TIP

SDK 提供两种 zip 资源,一种是不包含配置的 SDK,一种是包含配置的 SDK。包含配置的 SDK 为正式参数,游戏直接替换配置文件或替换内部参数;不包含配置的 SDK 仅做接入使用,无法联调。

Java 环境要求 JDK17

# 1.1、SDK 目录结构说明

  • /demo :demo 工程

  • /resource : SDK 资源

    /resource/entry/libs/dhsdkhelper.har : SDK har 包

    /resource/entry/src/main/resources/rawfile/dh_config.json : SDK 配置文件,直接拷贝至/entry/src/main/resources/rawfile 目录

    /resource/entry/src/main/resources/rawfile/dh_wenxin_config.json : SDK 配置文件,直接拷贝至/entry/src/main/resources/rawfile 目录

    /resource/entry/build-profile.json5 : Module 级配置文件

    /resource/entry/oh-package.json5 : Module 级配置文件

    /resource/hvigor/hvigor-config.json5 : 编译工具版本配置文件

    /resource/material : 签名配置目录

    /resource/oh-package.json5 : 工程级配置文件

    /resource/*-debug.p7b : 联调版本 p7b profile

    /resource/*-publish.p7b : 发布版本 p7b profile

    /resource/dh-debug.cer : 联调版本 cer

    /resource/dh-release.cer : 发布版本 cer

    /resource/dh.p12 : 签名文件

# 1.2、SDK 配置

# 1.2.1 拷贝 har 和配置

  • 拷贝/resource/entry/libs/dhsdkhelper.har 到游戏工程 entry/libs 目录下,如果游戏工程 entry 目录下没有 libs 目录,请先创建目录
  • 拷贝/resource/entry/src/main/resources/rawfile 目录到游戏工程 entry/src/main/resources 目录下
  • 拷贝/resource/material 目录、/resource/*.p7b 文件、/resource/*.cer 文件、/resource/dh.p12 共一个目录,5 个文件到游戏工程根目录下

# 1.2.2 修改配置

# 1.2.2.1 修改工程级 build-profile.json5

(1) 修改 app/signingConfigs 值

参考/resource/build-profile.json5,拷贝内部app/signingConfigs值替换游戏app/signingConfigs值
说明:name为default的配置是联调签名配置,name为publish的配置是发布签名配置,根据当前包体属性选择修改app/products元素中的signingConfig值
示例如下:
"app": {
    "signingConfigs": [
    {
        "name": "default",
        "type": "HarmonyOS",
        "material": {
            "storePassword": "***",
            "certpath": "dh-debug.cer",
            "keyAlias": "***",
            "keyPassword": "***",
            "profile": "zhzf2-debug.p7b",
            "signAlg": "SHA256withECDSA",
            "storeFile": "dh.p12"
        }
    },
    {
        "name": "publish",
        "type": "HarmonyOS",
        "material": {
            "storePassword": "***",
            "certpath": "dh-release.cer",
            "keyAlias": "***",
            "keyPassword": "***",
            "profile": "zhzf2-publish.p7b",
            "signAlg": "SHA256withECDSA",
            "storeFile": "dh.p12"
        }
    }],
    "products": [
    {
        "name": "default",
        "signingConfig": "default",
        "compatibleSdkVersion": "5.0.0(12)",
        "runtimeOS": "HarmonyOS"
    }]
}

(2) 修改 app/products 值

app/products各个元素中增加buildOption属性,值为
{
	"strictMode": {
		"useNormalizedOHMUrl": true
	}
}
示例如下:
"products": [
      {
        "name": "default",
        "signingConfig": "default",
        "compatibleSdkVersion": "5.0.0(12)",
        "runtimeOS": "HarmonyOS",
        "buildOption": {
          "strictMode": {
            "useNormalizedOHMUrl": true
          }
        }
      }
    ]
# 1.2.2.2 修改 entry/build-profile.json5
如果研发没有buildOption字段,直接拷贝/resource/entry/build-profile.json5内部的buildOption字段和值;
如果研发有动态import模块,请buildOption/arkOptions/runtimeOnly/packages的数组值中追加dhsdkhelper
示例如下:
"buildOption": {
    "arkOptions": {
      "runtimeOnly": {
        // 配置本模块变量动态import其他模块名,要求与dependencies中配置的名字一致。
        "packages": [
          "dhsdkhelper"
        ]
      }
    }
  }
# 1.2.2.3 修改 entry/oh-package.json5
如果研发有引用模块,记得保留现有dhsdkhelper的引用,dependencies值中追加"dhsdkhelper": "file:libs/dhsdkhelper.har",同时执行ohpm install;
注意:追加内容不允许修改!!!
示例如下:
"dependencies": {
	"dhsdkhelper": "file:libs/dhsdkhelper.har"
}
# 1.2.2.4 修改 entry/src/main/module.json5

(1) module/abilities 增加 skills 属性,同时替换子属性 uris/host 为 QQ 的 appid(QQ appid 联系技术获取)

"skills": [
    //qq
    {
      "entities": [
        "entity.system.browser"
      ],
      "actions": [
        "ohos.want.action.viewData",
      ],
      "uris": [
        {
          "scheme": "qqopenapi",
          "host": "102065523",
          "path": "auth",
          "linkFeature": "Login",
        }
      ]
    },
    //push,用于标识应用首页的skill(即配置了"entity.system.home"和"action.system.home"的skill)中不要配置uris。
    {
      "entities": [
        "entity.system.home"
      ],
      "actions": [
        "action.system.home"
      ]
    },
    //wechat
    {
      "entities": [
        "entity.system.home",
      ],
      "actions": [
        "action.system.home",
        "wxentity.action.open"
      ]
    }
]

(2) module 增加 querySchemes

"querySchemes": [
	"https",
	"qqopenapi",
	"weixin"
]

# 2、查询配置

调用代码示例如下:

/**
 * 异步获取SDK配置信息接口
 * @context 应用上下文
 * @param key 需要查询的配置名称
 * @return 返回字符串,查不到会返回“”
 */
let value:string = await DHSDKHelper.query(context,key);

配置信息,主要参数说明如下:

key 别名 示例 备注
dh_appId 开放平台 AppID
dh_channelId 渠道编号 1058(官方安卓)、1013(官方 iOS)、3481(官方鸿蒙) 安卓/苹果 Key 相同(一级渠道)
dh_channelName 渠道名称
dh_mainchannel CPS 主渠道 100001 玩家广告来源渠道(二级渠道)
dh_secochannel CPS 次渠道 100002 玩家广告来源渠道(三级渠道)
dev_os 设备系统
dev_uuid 设备唯一 ID
dev_brand 设备品牌
dev_model 设备型号
firebase_messaging_token firebase 推送 token
dh_mode 国内海外标识 国内为1,海外为0
Last Updated: 2026/2/26 16:18:27