(1)安装或编译出现的错误
Google关于这方面在Android S的改动有文档输出,可以参考如下:Dexpreopt 和 uses-library 检查。
此项报错主要是构建系统在Android.bp或Android.mk文件中的信息与Manifest清单之间进行构建时一致性检查,要求声明请求使用的libraries跟AndroidManifest.xml中声明的一致,否则将报错。
接下来查看编译报错:
error: mismatch in the <uses-library> tags between the build system and the manifest: - required libraries in build system: [] vs. in the manifest: [org.apache.http.legacy] - optional libraries in build system: [] vs. in the manifest: [com.x.y.z] - tags in the manifest (.../X_intermediates/manifest/AndroidManifest.xml): <uses-library android:name="com.x.y.z"/> <uses-library android:name="org.apache.http.legacy"/> note: the following options are available: - 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) - to temporarily disable the check for the whole product, set PRODUCT_BROKEN_VERIFY_USES_LIBRARIES := true in the product makefiles - to fix the check, make build system properties coherent with the manifest - see build/make/Changes.md for details
根据提示可以做如下三种尝试修改:
(A)产品范围的临时修复:在MK当中配置PRODUCT_BROKEN_VERIFY_USES_LIBRARIES := true;
此项仍然会执行构建时一致性检查,但检查失败并不意味着构建失败。相反,检查失败会使构建系统降级 dex2oat 编译器过滤器以在 dexpreopt 中进行verify ,从而完全禁用此模块的 AOT 编译。
(B)快速进行全局命令行修复:请使用环境变量RELAX_USES_LIBRARY_CHECK=true;
它与PRODUCT_BROKEN_VERIFY_USES_LIBRARIES具有相同的效果,但旨在用于命令行。环境变量覆盖产品变量。
(C)根本原因修复:请让构建系统了解清单中的标记;
检查AndroidManifest.xml或APK内的清单,可以使用aapt dump badging $APK | grep uses-library来检查,然后在MK文件中进行如下配置:
//LOCAL_USES_LIBRARIES := <library-module-name> //LOCAL_OPTIONAL_USES_LIBRARIES := <library-module-name> LOCAL_OPTIONAL_USES_LIBRARIES := org.apache.http.legacy androidx.window.extensions androidx.window.sidecar
(2)一劳永逸之法
//Android.bp enforce_uses_libs: false, dex_preopt: { enabled: false, }, //Android.mk LOCAL_ENFORCE_USES_LIBRARIES := false LOCAL_DEX_PREOPT := false