如何修复“意外元素< queries>"在< manifest>"中找到错误? [英] How to fix "unexpected element <queries> found in <manifest>" error?
问题描述
突然之间,我的Android项目中出现了此构建错误:
All of a sudden, I am getting this build error in my Android project:
unexpected element <queries> found in <manifest>
我该如何解决?
推荐答案
Android Gradle插件需要了解新的清单元素,尤其是用于清单合并过程.如果插件有混淆的趋势,看到清单合并中无法识别的元素,将其扔掉出现类似问题中的错误.
The Android Gradle Plugin needs to know about new manifest elements, particularly for the manifest merger process. The plugin has a tendency to get confused if it sees elements in the manifest merger that it does not recognize, tossing out build errors like the one in the question.
在这种情况下,Android 11引入了< queries>
作为清单元素,而旧版本的Android Gradle插件对此元素一无所知.
In this case, Android 11 introduced <queries>
as a manifest element, and older versions of the Android Gradle Plugin do not know about that element.
这是来自清单合并的事实,意味着只需升级依赖项可能会导致此错误.例如,如果您升级到最新版本版本的 com.awesome:awesome-library
,它包含一个< queries>
元素在清单中,您可能会在构建中因上述错误而崩溃,即使您的代码没有任何其他更改.
The fact that this occurs from manifest merger means that simply upgrading a dependency
might bring about this error. For example, if you upgrade to the latest
version of com.awesome:awesome-library
, and it contained a <queries>
element
in its manifest, you might crash with the aforementioned error in your builds,
even without any other changes in your code.
Google发布了一系列Android Gradle插件的修补程序版本来解决此问题:
Google released a series of patch versions of the Android Gradle Plugin to address this:
-
3.3.3
-
3.4.3
-
3.5.4
-
3.6.4
-
4.0.1
如果您正在使用 3.3.*
至 4.0.*
系列中的现有插件,请升级到该列表中的相关补丁程序版本(或更高版本),则不再需要遇到该错误(例如 classpath'com.android.tools.build:gradle:4.0.1'
).
If you are using an existing plugin in the 3.3.*
through 4.0.*
series, upgrade
to the associated patch version (or higher) from that list, and you should no longer
run into that error (e.g., classpath 'com.android.tools.build:gradle:4.0.1'
).
如果您使用的是Android Studio 4.1或更高版本,且具有Android Gradle插件(例如,在 4.1.*
系列中),如果没有任何变化.这些插件版本已经知道< queries>
.
If you are using Android Studio 4.1 or higher, with a matching
Android Gradle Plugin (e.g., in the 4.1.*
series), you should be fine without
any changes. Those plugin versions were already aware of <queries>
.
请参见此Android开发者博客文章以获取更多信息.
See this Android Developers Blog post for more.
这篇关于如何修复“意外元素< queries>"在< manifest>"中找到错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!