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"}
查看服务配置,相关验证是否启动。
相关推荐
爱笑的眼睛111 小时前
HarmonyOS 应用开发深入浅出:基于 Stage 模型与声明式 UI 的现代化状态管理实践
华为·harmonyos
爱笑的眼睛112 小时前
HarmonyOS 应用开发深度解析:掌握 ArkTS 声明式 UI 与现代化状态管理
华为·harmonyos
爱笑的眼睛112 小时前
HarmonyOS 应用开发深度解析:基于 ArkTS 的跨组件状态管理最佳实践
华为·harmonyos
前端世界2 小时前
鸿蒙系统下的智能设备故障检测实战:从监控到自愈的全流程实现
华为·harmonyos
2501_919749032 小时前
flutter鸿蒙:使用flutter_local_notifications实现本地通知
flutter·华为·harmonyos
Georgewu12 小时前
【HarmonyOS 6】 The target can not be empty. check the build.profile,json5 file of
harmonyos
Georgewu12 小时前
【HarmonyOS 6】Install Failed: error: failed to install bundle.code:9568322
harmonyos
爱笑的眼睛1114 小时前
HarmonyOS 应用开发新范式:深入剖析 Stage 模型与 ArkTS 状态管理
华为·harmonyos
爱笑的眼睛1115 小时前
深入浅出 HarmonyOS ArkUI 3.0:基于声明式开发范式与高级状态管理构建高性能应用
华为·harmonyos
电手17 小时前
时隔4年麒麟重新登场!华为这8.8英寸新「手机」给我看麻了
华为·智能手机