問題描述
突然間,我在我的 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.
從清單合并中發(fā)生的事實意味著只需升級依賴項可能會導致這個錯誤.例如,如果您升級到最新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 發(fā)布了一系列補丁版本的 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.*
系列中的現有插件,請升級到該列表中的關聯(lián)補丁版本(或更高版本),您不應該再遇到該錯誤(例如,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 開發(fā)者博客文章了解更多信息.
See this Android Developers Blog post for more.
這篇關于如何修復“意外元素<查詢>在“清單"中找到錯誤?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!