#跟着坚果学鸿蒙#ArkGuard混淆开启指南<二>
·
三种混淆配置文件
- obfuscation-rules.txt
HAP、HAR和HSP模块的build-profile.json5配置文件中均有arkOptions.obfuscation.ruleOptions.files字段,用于指定在编译本模块时需要生效的混淆规则,新建工程时会创建默认文件obfuscation-rules.txt。
- consumer-rules.txt
对于HAR模块,在build-profile.json5中额外有一个arkOptions.obfuscation.consumerFiles字段,用于指定当本包被依赖时,期望在当前编译流程生效的混淆规则,新建HAR模块时会创建默认文件consumer-rules.txt。它与obfuscation-rules.txt的区别是:obfuscation-rules.txt在编译本模块时生效,consumer-rules.txt在编译依赖本模块的其他模块时生效。
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": true,
"files": ["./obfuscation-rules.txt"],
}
"consumerFiles": ["./consumer-rules.txt"]
}
}
- obfuscation.txt
不同于以上两种开发者可自行修改的配置文件,obfuscation.txt是在编译构建HAR时根据consumer-rules.txt和依赖模块的混淆规则文件自动生成的文件,它作为一种编译产物存在于发布的HAR包中。在其他应用依赖该发布包时,会合并其中的混淆规则应用于当前编译流程。obfuscation.txt内容的生成及合并逻辑请参考混淆规则合并策略。
三种配置文件的差异:
配置文件(示例) | 配置类型 | 是否可修改配置 | 是否影响本模块的混淆 | 是否影响其他模块的混淆 |
---|---|---|---|---|
obfuscation-rules.txt | 自定义 | 是 | 是 | 否 |
consumer-rules.txt | 自定义 | 是 | 否 | 是 |
obfuscation.txt | 编译产物 | 不涉及,构建HAR时自动生成。 | 不涉及 | 是 |
更多推荐
所有评论(0)