HarmonyOS 学习路之开发基础知识——应用配置文件
简介
应用的每个 HAP 的根目录下都存在一个“config.json”配置文件,文件内容主要涵盖以下三个方面:
应用的全局配置信息,包含应用的包名、生产厂商、版本号等基本信息。
应用在具体设备上的配置信息,包含应用的备份恢复、网络安全等能力。
HAP 包的配置信息,包含每个 Ability 必须定义的基本属性(如包名、类名、类型以及 Ability 提供的能力),以及应用访问系统或其他应用受保护部分所需的权限等。
配置文件的组成
配置文件“config.json”采用 JSON 文件格式,其中包含了一系列配置项,每个配置项由属性和值两部分构成:
属性属性出现顺序不分先后,且每个属性最多只允许出现一次。
值每个属性的值为 JSON 的基本数据类型(数值、字符串、布尔值、数组、对象或者 null 类型)。如果属性值需要引用资源文件,可参见资源文件。
配置文件的元素
此部分提供配置文件“config.json”中所有属性的详细解释。
DevEco Studio 提供了两种编辑“config.json”文件的方式。在“config.json”的编辑窗口中,可在右上角切换代码编辑视图或可视化编辑视图。
图 1 config.json 文件的可视化编辑视图


配置文件的内部结构
“config.json”由“app”、“deviceConfig”和“module”三个部分组成,缺一不可。

app 对象的内部结构



deviceConfig 对象的内部结构




module 对象的内部结构



name:表示 Ability 名称。description:表示对 Ability 的描述。icon:表示 Ability 图标资源文件的索引。label:表示 Ability 对用户显示的名称。uri:表示 Ability 的统一资源标识符。launchType:表示 Ability 的启动模式,支持“standard”和“singleton”两种模式
standard:表示该 Ability 可以有多实例。“standard”模式适用于大多数应用场。
singleton:表示该 Ability 只可以有一个实例。例如,具有全局唯一性的呼叫来电界面即采用“singleton”模式。
visible:表示 Ability 是否可以被其他应用调用。permissions:表示其他应用的 Ability 调用此 Ability 时需要申请的权限。orientation:表示该 Ability 的显示模式。


版权声明: 本文为 InfoQ 作者【爱吃土豆丝的打工人】的原创文章。
原文链接:【http://xie.infoq.cn/article/5f3574deb909e8112c80ccbe1】。文章转载请联系作者。
评论