如何修复“意外元素<查询>在“清单"中找到错误?

How to fix quot;unexpected element lt;queriesgt; found in lt;manifestgt;quot; error?(如何修复“意外元素lt;查询gt;在“清单中找到错误?)
本文介绍了如何修复“意外元素<查询>在“清单"中找到错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

突然间,我在我的 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.

这篇关于如何修复“意外元素&lt;查询&gt;在“清单"中找到错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

IncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM(更新到 Android Build Tools 25.1.6 GCM/FCM 后出现 IncompatibleClassChangeError)
How to get current flavor in gradle(如何在 gradle 中获取当前风味)
Multi flavor app based on multi flavor library in Android Gradle(基于 Android Gradle 中多风味库的多风味应用)
Android dependency has different version for the compile and runtime(Android 依赖在编译和运行时有不同的版本)
Transitive dependencies for local aar library(本地 aar 库的传递依赖)
Why I#39;m Getting Duplicate Class When Running My Android Project(为什么我在运行我的 Android 项目时得到重复的类)