How to fix "unexpected element <queries> found in <manifest>" error?

AndroidFlutterAndroid Gradle-PluginAndroid ManifestManifest

Android Problem Overview


All of a sudden, I am getting this build error in my Android project:

unexpected element <queries> found in <manifest>

How do I fix it?

Android Solutions


Solution 1 - Android

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.

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.

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 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

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').

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>.

See this Android Developers Blog post for more.

Solution 2 - Android

I had this issue in flutter but i believe this solution will work for both flutter and native android dev.

Follow these steps

  1. Read this short blog to get some understanding: click here
  1. Delete the .gradle folder inside the android folder ie android>.gradle

  2. In the project build.gradle file, upgrade ur class path appropriately based on the blog in the link above, e.g i upgraded to classpath 'com.android.tools.build:gradle:4.0.1'

  3. Upgrade the distribution url too. Its in android>gradle>gradle-wrapper.properties file appropriately. e.g i upgraded it to distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

  4. You can invalidate caches and restart your android studio. Make sure you have a good internet connection because it will download the new gradle files.

Thanks.

Solution 3 - Android

I also had same issue on Android Studio 4.1.1, suddenly, 2 days ago. I solved the issue by upgrading build gradle version.

previous setting in build.gradle file of project was:

classpath("com.android.tools.build:gradle:3.5.3")

current setting:

classpath("com.android.tools.build:gradle:3.5.4")

The issue was gone immediately. :)

Solution 4 - Android

Fixing the error is very simple. Update your android studio to the last version and use the last stable Gradle plugin version. At the current time, I use Android Studio version 4.1.3 with Gradle Plugin 6.8.2

guys please attentions, for use queries you should write queries code in out of application tag not inside application tag

for more info see below photo

https://i.stack.imgur.com/ks0AY.jpg

Solution 5 - Android

I had this error in the react-native-image-crop-picker library and I solved this problem by updating the gradle version as mentioned above.

It was:

classpath("com.android.tools.build:gradle:3.5.3")

Updated to:

classpath("com.android.tools.build:gradle:3.5.4")

And I ran a:

cd android && ./gradlew clean && cd .. && npx react-native run-android

Then it worked ok.

Solution 6 - Android

due to the new default settings and features for package visibility in Android 11 that need to add <queries> you must update your android gradle plugin.

Google has added some patches to current versions listed here:

https://developer.android.com/studio/releases/gradle-plugin.html?buildsystem=cmake#4-0-0

If you want to use a newer version of android gradle you should search for compatible wrapper from here:

https://developer.android.com/studio/releases/gradle-plugin.html?buildsystem=cmake#updating-gradle

Solution 7 - Android

update your Gradle version to 4.0.1+

android/gradle/wrapper/gradle-wrapper.properties update distribution URL to : distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip

android/build.gradle update gradle plugin: classpath 'com.android.tools.build:gradle:4.1.2'

to 4.0.1+ here it is 4.1.2 with Gradle version to 6.5+

you can see the distribution chart at https://stackoverflow.com/a/35272475/10184868

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCommonsWareView Question on Stackoverflow
Solution 1 - AndroidCommonsWareView Answer on Stackoverflow
Solution 2 - AndroidBukunmi View Answer on Stackoverflow
Solution 3 - AndroidHitesh PrajapatiView Answer on Stackoverflow
Solution 4 - Androidkiumars gilanizadehView Answer on Stackoverflow
Solution 5 - AndroidJefferson PatricioView Answer on Stackoverflow
Solution 6 - AndroidMahmoud MabrokView Answer on Stackoverflow
Solution 7 - Androidakash mauryaView Answer on Stackoverflow