我在尝试构建 Android 应用程序时收到以下错误:
任务:app:mergeDebugResources 失败
失败:构建失败并出现异常。
- 什么地方出了错:
任务“:app:mergeDebugResources”执行失败。
该项目使用 AndroidX 依赖项,但未启用“android.useAndroidX”属性。在 gradle.properties 文件中将此属性设置为 true 并重试。
检测到以下 AndroidX 依赖项: androidx.versionedparcelable:versionedparcelable:1.0.0、androidx.slidingpanelayout:slidingpanelayout:1.0.0、androidx.fragment:fragment:1.0.0、androidx.core:core:1.0.0、androidx.customview :customview:1.0.0, androidx.swiperefreshlayout:swiperefreshlayout:1.0.0, androidx.interpolator:interpolator:1.0.0, androidx.loader:loader:1.0.0, androidx.drawerlayout:drawerlayout:1.0.0, androidx.viewpager :viewpager:1.0.0, androidx.collection:collection:1.0.0, androidx.localbroadcastmanager:localbroadcastmanager:1.0.0, androidx.lifecycle:lifecycle-common:2.0.0, androidx.arch.core:core-common:2.0 .0,androidx.annotation:注释:1.0.0,androidx.lifecycle:lifecycle-livedata:2.0.0,androidx.legacy:legacy-support-core-ui:1.0.0,androidx.lifecycle:lifecycle-viewmodel:2.0 .0、androidx.lifecycle:lifecycle-livedata-core:2.0.0、androidx.legacy:legacy-support-v4:1.0.0、androidx.media:media:1.0.0、androidx.arch.core:core-runtime :2.0.0,androidx.legacy:legacy-support-core-utils:1.0.0,androidx.documentfile:documentfile:1.0.0,androidx.cursoradapter:cursoradapter:1.0.0,androidx.lifecycle:lifecycle-runtime:2.0 .0, androidx.coordinatorlayout:coordinatorlayout:1.0.0, androidx.asynclayoutinflater:asynclayoutinflater:1.0.0, androidx.print:print:1.0.0
我修改了项目的 gradle.properties 文件并将“android.userAndroidX”设置为 true。但每次我尝试再次构建时,它都会自动返回 false。
在构建过程中 gradle.properties 是否有可能被任何其他任务覆盖?
Thanks!
想必您正在使用cordova-android@8
(type cordova platform ls
以查找项目中的平台版本)。
所以你有两个选择:
-
更新至cordova-android@9
它隐式支持 AndroidX:
cordova platform rm android && cordova platform add android@9
In your 配置文件添加以下行:
<preference name="AndroidXEnabled" value="true" />
更多详细信息请参见此处:科尔多瓦文档 https://cordova.apache.org/announcements/2020/06/29/cordova-android-9.0.0.html
-
Add cordova-插件-androidx https://github.com/dpa99c/cordova-plugin-androidx到您的 Cordova 项目,该项目会持续设置本机 AndroidX 标志cordova-android@8
:
cordova plugin add cordova-plugin-androidx
如果添加其中之一后您的项目仍然无法构建,可能是因为它包含 Cordova 插件,其本机 Android 代码引用了旧版 Android 支持库(AndroidX 是其后继者)。
要解决此问题,您可以添加科尔多瓦插件 androidx 适配器 https://github.com/dpa99c/cordova-plugin-androidx-adapter到您的项目,它将动态修补这些插件的源代码以将它们迁移到 AndroidX:
cordova plugin add cordova-plugin-androidx-adapter
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)