Skip to content

Fixing "unexpected element <queries> found in <manifest>" error

The "unexpected element <queries> found in <manifest>" error occurs when older versions of the Android Gradle Plugin (AGP) encounter the <queries> element introduced in Android 11 for package visibility management.

Problem Overview

This build error typically appears when:

  • Your project or its dependencies use <queries> elements in AndroidManifest.xml
  • You're using an outdated Android Gradle Plugin version (pre-3.3.3)
  • The AGP doesn't recognize the new manifest element during the manifest merging process

Primary Solution: Update Gradle Plugin

The most effective fix is updating your Android Gradle Plugin to a version that supports the <queries> element:

gradle
buildscript {
    dependencies {
        // Update to at least these minimum versions
        classpath 'com.android.tools.build:gradle:4.0.1' // or higher
    }
}
gradle
# Update distribution URL to match your Gradle plugin
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip

Minimum Compatible Versions

AGP VersionMinimum PatchGradle Version
3.3.x3.3.35.6.4
3.4.x3.4.35.6.4
3.5.x3.5.46.0.1
3.6.x3.6.46.1.1
4.0.x4.0.16.1.1

WARNING

Ensure your Gradle wrapper version is compatible with your chosen AGP version. Check the official compatibility chart for details.

Alternative Solutions

For React Native Projects

If you're using React Native with the react-native-image-crop-picker or similar libraries:

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

Clean Build Files

Sometimes cleaning the build directories helps:

  1. Delete the .gradle folder in your android directory
  2. Invalidate caches and restart Android Studio
  3. Ensure you have a stable internet connection for downloading updated dependencies

INFO

Android Studio 4.1+ includes AGP versions that natively support <queries> elements, so upgrading your IDE can also resolve this issue.

Understanding the Queries Element

The <queries> element was introduced in Android 11 to improve package visibility and app security. It allows apps to declare which other apps they intend to interact with, replacing the broader, less secure previous approaches.

Correct placement in AndroidManifest.xml:

xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app">
    
    <!-- queries should be placed at the manifest level, NOT inside application -->
    <queries>
        <package android:name="com.example.otherapp" />
    </queries>
    
    <application>
        <!-- your application content -->
    </application>
</manifest>

AGP 8.x Consideration

For newer AGP 8.x versions, you might encounter a different warning:

Unknown element under <manifest>: queries at Binary XML file line #11

This occurs when running on older Android versions (like Android 10) where the device's manifest parser doesn't recognize the <queries> element. In this case, the warning is generally safe to ignore as it doesn't affect functionality.

Conclusion

The "unexpected element <queries>" error is resolved by updating to compatible versions of the Android Gradle Plugin and Gradle wrapper. For most projects, upgrading to AGP 4.0.1+ and Gradle 6.7+ will resolve the issue. Always ensure your development environment and dependencies are updated to avoid similar compatibility problems with new Android platform features.

For more information on package visibility in Android 11, refer to the official Android developers blog.