HarmonyOS鸿蒙Next中如何避免har的Index.d.ets被混淆?
HarmonyOS鸿蒙Next中如何避免har的Index.d.ets被混淆? 开启混淆后Index导出的内容都变了:
export { m } from "./src/main/ets/decoder/f";
我加了
-keep-file-name Index
没有作用
-keep-file-name: 指定要保留的文件/文件夹的名称,但是har的Index.d.ets会涉及到如下代码:
export { XXX } from "./src/main/ets/xxx/xxx"
所以如果./src/main/ets/文件夹/xxx.ets 其中文件夹或者xxx.ets文件混淆后。Index.d.ets显示的还是混淆后的内容,所以可以设置文件夹或者xxx.ets文件不被混淆。
示例代码如下:
-keep-file-name
components // 文件夹名称
**Page // 文件夹下的文件名称
-keep
./src/main/ets/**
这样设置就可以实现避免har的Index.d.ets被混淆。
更多关于HarmonyOS鸿蒙Next中如何避免har的Index.d.ets被混淆?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS Next中,避免har包的Index.d.ets文件被混淆,需在工程的build-profile.json5文件中配置混淆规则。具体操作为:在"buildOption"下的"obfuscation"中添加规则,排除Index.d.ets文件。例如,使用"keep"规则指定文件路径或模式,确保该文件在编译过程中不被混淆处理。
在HarmonyOS Next中,混淆工具默认会处理所有文件,包括Index.d.ets。要避免其被混淆,需要在混淆配置文件中明确排除该文件。
使用以下规则:
-keep class * extends Ability { *; }
-keep class * extends AbilitySlice { *; }
-keep class * extends UIComponent { *; }
-keep class * implements IAbilityMonitor { *; }
对于Index.d.ets,添加:
-keep class * from "Index.d.ets"
同时确保在build-profile.json5中正确配置混淆:
"buildOption": {
"proguardOption": {
"proguardEnabled": true,
"proguardFiles": ["./proguard-rules.pro"]
}
}
如果仍然被混淆,检查文件路径是否正确,并确认混淆配置文件已正确加载。

