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?
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.
I had this issue in Flutter, but I believe this solution will work for both Flutter and native Flutter development.
Follow these steps
Read this short blog post to get some understanding: Preparing your Gradle build for package visibility in Android 11
Delete the .gradle folder inside the Android folder, i.e., android > .gradle
In the project build.gradle file, upgrade your 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'
Upgrade the distribution URL too. It's 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
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.
I also suddenly had the same issue two days ago in Android Studio 4.1.1. I solved the issue by upgrading the build Gradle version.
Previous setting in the build.gradle file of the 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. :)
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
For use in queries, you should write queries code in out of application tag, not inside application tag.
For more information, see the photo below:
I had this error in the react-native-image-crop-picker library, and I solved this problem by updating the Gradle version as mentioned in previous answers.
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.
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 in Android Gradle plugin release notes, 4.0.0 (April 2020).
If you want to use a newer version of Android Gradle, you should search for a compatible wrapper from Android Gradle plugin release notes, Update Gradle.
Update your Gradle version to 4.0.1 or later.
File android/gradle/wrapper/gradle-wrapper.properties: update the distribution URL to:
distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip
File android/build.gradle: update the Gradle plugin:
classpath 'com.android.tools.build:gradle:4.1.2'
to 4.0.1 or later. Here it is 4.1.2 with Gradle version to 6.5 or later.
You can see the distribution chart at How to update gradle in android studio?
Related
In my NativeScript project, after the last Gradle update, I can't build a new Bundle file (for Android release). This error is about the compatibility of some plugins with the new Gradle version.
I think if I could downgrade the Gradle version to the previous one, the build will succeed.
Is any way that I could do the Grandle downgrade on a NativeScript project?
Looks like there is a way to specify the version of gradle to use in the project itself. But it is not documented anywhere.
I found these references in their code repository on github:
https://github.com/NativeScript/nativescript-cli/search?q=runtimeGradleVersion
However, it is easy to set gradle version outside the project in gradle.properties file.
Linux
On typical Linux(Debian) nodejs|npm installation, the location of this file is:
/usr/local/lib/node_modules/nativescript/vendor/gradle-plugin/gradle/wrapper/gradle-wrapper.properties
For example, if you wish to specify the version 6.4 of gradle, simply change the line from:
distributionUrl=https\://services.gradle.org/distributions/gradle-{{runtimeGradleVersion}}-bin.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-bin.zip
Windows
The location of the file shall be under:
C:\Users\<username>\AppData\Roaming\npm\nativescript\vendor\gradle-plugin\gradle\wrapper\gradle-wrapper.properties
In my React Native app, I got an error about incompatibilities with gradle 6, so I looked in my project structure to find out which version of gradle I was running in my project. I found this line in gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
and this line in build.gradle
classpath("com.android.tools.build:gradle:3.4.2")
What I Want To Know: What's the difference between the reference to gradle in each of these files? In other words, how is version 5.5 being used in my project, and how is 3.4.2 being used?
distributionUrl represents Gradel Version where as classpath represents Android Gradle plugin version.
Gradel vs Android Gradle plugin: Reffer this difference between android gradle plugin and gradle
Gradle is the build system.
You can use it with a lot of plugins. One of these is the plugin for Android.
It is used to provide processes and configurable settings that are specific to building and testing Android applications.
For greater details and mapping of the above two type of versions refer the following URLs
https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
https://developer.android.com/studio/releases/gradle-plugin#updating-plugin
I hope this answer has cleared your doubts.
I added
apply plugin: 'com.google.firebase.firebase-perf'
and when I ran build script I got
/transforms/FirebasePerformancePlugin/dev/debug/174/module-info.class:
D8: Unsupported source file type
What kind of problem it could be?
I updated all plugins, play services, and Android Studio, but with no luck
I Solve This issue by updating gradle version
classpath 'com.android.tools.build:gradle:3.5.3'
Update: Android Gradle Plugin 3.5.0 fixes this. See this issue and this one issue, both fixed.
(Unfortunately, in my project, this other issue still remains even in 3.5.3.)
I started getting the same error after updating a (company internal) library dependency, but then I kept getting it even after reverting that update. Very strange!
> Task :app:transformClassesAndResourcesWithR8ForBetaRelease FAILED
R8 is the new Android code shrinker. If you experience any issues, please file a bug at
https://issuetracker.google.com, using 'Shrinker (R8)' as component name. You can
disable R8 by updating gradle.properties with 'android.enableR8=false'.
.../transforms/FirebasePerformancePlugin/beta/release/66/module-info.class:
D8: Unsupported source file type
The only thing I found that helped was to do what the Gradle build output says and temporarily switch back to ProGuard, with:
android.enableR8=false
in gradle.properties.
This issue was fixed somewhere between Android Studio 3.5 Beta 2 and Android Studio 3.6 Canary 5, there were a bunch of similar issues with module-info.class.
In my case to fix issue I had not only update Android Studio, but also update gradle plugin.
Steps is:
Install new version alongside your stable version (You also can configure current version to use updates from canary chanel)
More info here
Download link (I downloaded 3.6 Canary 5)
After you installed new Android Studio update grade plugin:
in
gradle/wrapper/gradle-wrapper.properties
chande distributionUrl to
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
Don't forget Build->Clean Project
Turn off Firebase-performance plugin.
Android Studio 3.6 Canary 1 has this issue too.
I didn't find another way to release build my project.
i solve this problem with 3 steps:
1.update the "distributionUrl=https://services.gradle.org/distributions/gradle-5.6.4-all.zip"
2.update the "classpath "com.android.tools.build:gradle:3.6.3"
3.update the Studio 3.6.3
in other way(i don't like it)
//apply plugin: 'com.google.firebase.firebase-perf'
...
//classpath "com.google.firebase:perf-plugin:1.3.1"
I try to use inapp order aidl (IInAppBillingService.aidl).when i copy this in (com.android.vending.billing) package it gets error :
i found some article thats here .
but i dont have Buildtools version 22.1.2 in my OpenMuduleSetting like above article.
how can i solve this problem ?
According to this SO issue:
This bug happens when the versions of SDK, Build Tools and Gradle
Plugins doesn't match (in terms of compatibility). The solutions is
verify if you is using the latest versions of them. The gradle plugins
are placed in the build.gradle of the project, and the other versions
are on the build.gradle of the module. For example, for SDK 23, you
must use the Build Tools 23.0.1 and gradle plugins version 1.3.1.
You're using already newer 23.0.3 build tools so please check if your Gradle plugin is at least in '1.3.0' version
Try to use classpath 'com.android.tools.build:gradle:1.5.1'
Edited title to reflect dicussion.
I have an Android Studio project from a friend that seems to compile and run with very weird behavior (i.e crashes, code being cut or simplified in odd ways). I noticed he is also using an out-dated version of Gradle. This being said, I created my own project and ported the code over and it worked just fine. I'm assuming this is a Gradle issue since it controls how the code is optimized. How do I update Gradle in an existing project?
What I've done:
Changed build.gradle and modified the classpath com.android.tools.build:grade:x.x.x to the same version in my new project. No avail.
Changed the gradle-wrapper.properties distributionUrl to an updated version.
Changed File -> Project Structure -> Project -> Gradle Version and Android Plugin Version to the new project version.
None of these fixed the weird behavior. If I'm wrong about the Gradle version being the problem here, please let me know.
Regards!
Try to clean/rebuild the project. You are probably using a newer version o android studio, i highly recommend downloading an old one to mantain old projects.
Theres a lot of changes on every new Android Studio, folders where files must be placed, gradle configs, and there is no way to "update project structure". You can manually update gradle version, but this will not update your config (build.gradle, settings.gradle) and neither your file folders.
Probably the errors you said are caused by the way gradle build files, its trying to build an old structure following a new structure rule.