HarmonyOS--认证服务
文章目录
- 一、注册华为账号开通认证服务
- 二、添加项目:*包名要与项目的包名保持一致
- 三、获取需要的文件
- 四、创建项目:*包名要与项目的包名保持一致
- 五、添加json文件
- 六、加入请求权限
- 七、加入依赖
- 八、修改构建配置文件:`build-profile.json5`
- 九、集成SDK
- 十、FQA
一、注册华为账号开通认证服务

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

三、获取需要的文件

四、创建项目:*包名要与项目的包名保持一致
五、添加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"}
查看服务配置,相关验证是否启动。
