HarmonyOS 鸿蒙Next中打正式包时报错Obfuscated har modules cannot depend on a shared module.

HarmonyOS 鸿蒙Next中打正式包时报错Obfuscated har modules cannot depend on a shared module. 项目使用多模块进行开发,在IDE选择Build App 打正式包时候 报错。错误如下:

> hvigor ERROR: Obfuscated har modules cannot depend on a shared module.
Detail: Remove the dependency on the shared module or set the har module to be obfuscation enable false.
> hvigor ERROR: BUILD FAILED in 584 ms

更多关于HarmonyOS 鸿蒙Next中打正式包时报错Obfuscated har modules cannot depend on a shared module.的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

通过将类型从har改为hsp可以规避,但是最好安装报错内容的指引,将模块的混淆关掉,可参考文档https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5

{
  "apiType": 'stageMode',
  ...
  "buildOptionSet": [
    {
      "name": "release",
      "arkOptions": {
        "obfuscation": {
          "ruleOptions": {
            "enable": true, // true表示进行混淆,false表示不进行混淆。默认为true
            "files": [
              "./obfuscation-rules.txt" // 混淆规则文件
            ]
          }
        }
      }
    },
  ],
  ...
}

更多关于HarmonyOS 鸿蒙Next中打正式包时报错Obfuscated har modules cannot depend on a shared module.的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,打正式包时出现“Obfuscated har modules cannot depend on a shared module”错误,通常是因为混淆的HAR模块依赖于共享模块。HAR(HarmonyOS Ability Resources)模块是鸿蒙系统的一种资源打包方式,用于在多个模块之间共享资源。混淆(Obfuscation)是一种代码保护机制,通过重命名类、方法和字段来增加反编译的难度。

在鸿蒙Next中,混淆的HAR模块不能依赖于共享模块的原因在于,混淆过程中会修改模块内部的类和方法名称,而共享模块的内容在编译时是静态链接的,混淆后的HAR模块无法正确解析共享模块中的资源或代码,导致编译或打包失败。

要解决这个问题,可以检查项目中的模块依赖关系,确保混淆的HAR模块不直接或间接依赖于共享模块。如果共享模块是必须的,可以考虑将共享模块中的相关内容提取到不混淆的HAR模块中,或者调整混淆配置,排除对共享模块的混淆。

此外,还需要检查build-profile.jsonoh-package.json文件中的模块依赖配置,确保没有错误的依赖关系。如果问题仍然存在,可能需要重新组织模块结构,避免混淆模块与共享模块之间的直接依赖。

总之,该错误的根本原因是混淆模块与共享模块之间的依赖冲突,通过调整模块依赖关系或混淆配置可以解决。

在HarmonyOS鸿蒙Next中打包时出现“Obfuscated har modules cannot depend on a shared module”错误,通常是因为混淆的HAR模块依赖于共享模块,而共享模块不支持混淆。解决方案包括:

  1. 检查依赖关系:确保混淆的HAR模块不依赖于共享模块。
  2. 移除混淆:对依赖共享模块的HAR模块禁用混淆,可在build.gradle中设置minifyEnabled false
  3. 重构模块:将共享模块的功能移至混淆模块中,或调整模块依赖结构。

通过这些步骤,可以有效解决该错误并成功打包。

回到顶部