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"}
查看服务配置,相关验证是否启动。
相关推荐
摘星编程36 分钟前
React Native鸿蒙:Loading加载动画效果
react native·react.js·harmonyos
Swift社区2 小时前
HarmonyOS 页面路由与导航开发
华为·harmonyos
以太浮标2 小时前
华为eNSP模拟器综合实验之- VLAN终结实践案例分析
网络·计算机网络·华为·智能路由器
希望上岸的大菠萝3 小时前
HarmonyOS 6.0 开发环境搭建完全指南 - DevEco Studio 配置 + 真机调试实战
华为·harmonyos
Lancker3 小时前
定制侠 一个国产纯血鸿蒙APP的诞生过程
android·华为·智能手机·鸿蒙·国产操作系统·纯血鸿蒙·华为鸿蒙
大雷神4 小时前
HarmonyOS智慧农业管理应用开发教程--高高种地--第28篇:用户中心与个人资料
华为·harmonyos
雨季6664 小时前
破界与共生:HarmonyOS原生应用生态全景图谱与PC时代三重变局
flutter·华为·harmonyos
一路阳光8514 小时前
华为mate80现在确实没有日日新了,看来华为是对鸿蒙6有信心了
华为·harmonyos
三掌柜6664 小时前
如何从一个开发者成为鸿蒙KOL
华为·harmonyos
哈基米~南北绿豆4 小时前
虚拟机体验:在Windows/Mac上运行鸿蒙PC开发环境
windows·macos·harmonyos