HarmonyOS--认证服务-操作步骤

HarmonyOS--认证服务

文章目录


一、注册华为账号开通认证服务

二、添加项目:*包名要与项目的包名保持一致

三、获取需要的文件

四、创建项目:*包名要与项目的包名保持一致

五、添加json文件

六、加入请求权限

typescript 复制代码
在module.json5文件中添加:"requestPermissions": [{"name": "ohos.permission.INTERNET"}],

七、加入依赖

typescript 复制代码
"dependencies": {
    "@hw-agconnect/hmcore": "^1.0.1",
    "@hw-agconnect/cloud": "^1.0.1",
    "@hw-agconnect/auth-ohos": "^1.1.3"
  }

八、修改构建配置文件:build-profile.json5

typescript 复制代码
{
  "apiType": "stageMode",
  "showInServiceCenter": true, // 新添加
  "buildOption": { // 新添加:内容
    //配置筛选har依赖.so资源文件的过滤规则
    "napiLibFilterOption": {
      //按照.so文件的优先级顺序,打包最高优先级的.so文件
      "pickFirsts": [
        "**/1.so"
      ],
      //按照.so文件的优先级顺序,打包最低优先级的.so 文件
      "pickLasts": [
        "**/2.so"
      ],
      //排除的.so文件
      "excludes": [
        "**/3.so"
      ],
      //允许当.so重名冲突时,使用高优先级的.so文件覆盖低优先级的.so文件
      "enableOverride": true,
    }
  },
  "buildOptionSet": [
    {
      "name": "release",
      "arkOptions": {
        "obfuscation": {
          "ruleOptions": {
            "enable": false,
            "files": [
              "./obfuscation-rules.txt"
            ]
          }
        }
      }
    },
  ],
  "targets": [
    {
      "name": "default"
    },
    {
      "name": "ohosTest",
    }
  ]
}

九、集成SDK

typescript 复制代码
导包:
import { initialize } from '@hw-agconnect/hmcore';
typescript 复制代码
async  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
     // 根据管理读取文件,根据信息读取里面的数据
    try {
      let input = await this.context.resourceManager
        .getRawFileContent('agconnect-services.json')
      let jsonString = util.TextDecoder.create('utf-8',
        {
          ignoreBOM: true
        }).decodeWithStream(input, {
        stream: false
      });
      initialize(this.context, JSON.parse(jsonString));
      console.info('system===>SDK集成成功')
    } catch (e) {
      console.info('system===>SDK集成失败')
      hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
    }
  }

十、FQA

typescript 复制代码
问题:{"code":203817988,"message":"third provider is disabled"}
查看服务配置,相关验证是否启动。
相关推荐
一只栖枝4 小时前
华为 HCIE 大数据认证中 Linux 命令行的运用及价值
大数据·linux·运维·华为·华为认证·hcie·it
zhanshuo8 小时前
在鸿蒙里优雅地处理网络错误:从 Demo 到实战案例
harmonyos
zhanshuo8 小时前
在鸿蒙中实现深色/浅色模式切换:从原理到可运行 Demo
harmonyos
whysqwhw13 小时前
鸿蒙分布式投屏
harmonyos
whysqwhw14 小时前
鸿蒙AVSession Kit
harmonyos
whysqwhw16 小时前
鸿蒙各种生命周期
harmonyos
whysqwhw17 小时前
鸿蒙音频编码
harmonyos
whysqwhw17 小时前
鸿蒙音频解码
harmonyos
whysqwhw17 小时前
鸿蒙视频解码
harmonyos
whysqwhw18 小时前
鸿蒙视频编码
harmonyos