版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/dongxianfei/article/details/123665498


安装或编译出现的错误

Google关于这方面在Android S的改动有文档输出,可以参考如下:Dexpreopt 和 uses-library 检查
此项报错主要是构建系统在Android.bp或Android.mk文件中的信息与Manifest清单之间进行构建时一致性检查,要求声明请求使用的libraries跟AndroidManifest.xml中声明的一致,否则将报错。
接下来查看编译报错:

  1. error: mismatch in the <uses-library> tags between the build system and the manifest:
  2. - required libraries in build system: []
  3. vs. in the manifest: [org.apache.http.legacy]
  4. - optional libraries in build system: []
  5. vs. in the manifest: [com.x.y.z]
  6. - tags in the manifest (.../X_intermediates/manifest/AndroidManifest.xml):
  7. <uses-library android:name="com.x.y.z"/>
  8. <uses-library android:name="org.apache.http.legacy"/>
  9. note: the following options are available:
  10. - to temporarily disable the check on command line, rebuild with RELAX_USES_LIBRARY_CHECK=true (this will set compiler filter "verify" and disable AOT-compilation in dexpreopt)
  11. - to temporarily disable the check for the whole product, set PRODUCT_BROKEN_VERIFY_USES_LIBRARIES := true in the product makefiles
  12. - to fix the check, make build system properties coherent with the manifest
  13. - see build/make/Changes.md for details

根据提示可以做如下三种尝试修改:

1. 产品范围的临时修复

在MK当中配置

  1. PRODUCT_BROKEN_VERIFY_USES_LIBRARIES := true

此项仍然会执行构建时一致性检查,但检查失败并不意味着构建失败。相反,检查失败会使构建系统降级 dex2oat 编译器过滤器以在 dexpreopt 中进行verify ,从而完全禁用此模块的 AOT 编译。

2. 快速进行全局命令行修复

请使用环境变量

  1. RELAX_USES_LIBRARY_CHECK=true

它与PRODUCT_BROKEN_VERIFY_USES_LIBRARIES具有相同的效果,但旨在用于命令行。环境变量覆盖产品变量。

3. 根本原因修复

3.1 请让构建系统了解清单中的标记;

检查AndroidManifest.xml或APK内的清单,可以使用

  1. aapt dump badging $APK | grep uses-library

来检查,然后在MK文件中进行如下配置:

  1. //LOCAL_USES_LIBRARIES := <library-module-name>
  2. //LOCAL_OPTIONAL_USES_LIBRARIES := <library-module-name>
  3. LOCAL_OPTIONAL_USES_LIBRARIES := org.apache.http.legacy androidx.window.extensions androidx.window.sidecar

3.2 一劳永逸之法

  1. //Android.bp
  2. enforce_uses_libs: false,
  3. dex_preopt: {
  4. enabled: false,
  5. },
  6. //Android.mk
  7. LOCAL_ENFORCE_USES_LIBRARIES := false
  8. LOCAL_DEX_PREOPT := false