Android resource linking failed : Unity Error :unexpected element <queries> found in <manifest>

AliAhmadUnityDev picture AliAhmadUnityDev · Jan 12, 2021 · Viewed 7.1k times · Source

I am using getting this error when building with Admob (Google Mobile Ads SDK for unity) and Facebook Audience Network SDK for unity. If I use one of these separately in project then there comes no error but if I use both of these, then I start getting this error on build. However I have tested and can confirm that this error doesn't appears on Unity 2020 versions but it comes in all Unity 2018 as well as 2019 versions. Please help me out to solve this error.

I can share the Project complete file if required but it can be easily reproduced by adding Admob unity SDK and Facebook audience network unity sdk and building the project for Android platform.

I am Using:

  • Unity Editor 2018.4.30 LTS version
  • Admob SDK (Google Mobile Ads SDK) version 5.4.0
  • FAcebook Audience Network version 6.2.0
  • Scripting Backend: IL2CPP
  • JDK: jdk1.8.0_271

Unity Console Error Details:

CommandInvokationFailure: Gradle build failed. 
C:\Program Files\Java\jdk1.8.0_271\bin\java.exe -classpath "C:\Program Files\UnityInstallFolder\Unity_2018.4.30\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-5.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

stderr[

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':processReleaseResources'.
> Android resource linking failed
  D:\Projects\ADS Packages\ReportingProjectSample\Temp\gradleOut\build\intermediates\merged_manifests\release\AndroidManifest.xml:36: AAPT: error: unexpected element <queries> found in <manifest>.
      

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 6s
]
stdout[
> Task :preBuild UP-TO-DATE
> Task :GoogleMobileAdsPlugin.androidlib:preBuild UP-TO-DATE
> Task :GoogleMobileAdsPlugin.androidlib:preReleaseBuild UP-TO-DATE
> Task :GoogleMobileAdsPlugin.androidlib:checkReleaseManifest
> Task :GoogleMobileAdsPlugin.androidlib:processReleaseManifest
> Task :preReleaseBuild UP-TO-DATE
> Task :GoogleMobileAdsPlugin.androidlib:compileReleaseAidl NO-SOURCE
> Task :compileReleaseAidl NO-SOURCE
> Task :GoogleMobileAdsPlugin.androidlib:packageReleaseRenderscript NO-SOURCE
> Task :compileReleaseRenderscript NO-SOURCE
> Task :checkReleaseManifest UP-TO-DATE
> Task :generateReleaseBuildConfig UP-TO-DATE
> Task :prepareLintJar UP-TO-DATE
> Task :generateReleaseSources UP-TO-DATE
> Task :GoogleMobileAdsPlugin.androidlib:compileReleaseRenderscript NO-SOURCE
> Task :GoogleMobileAdsPlugin.androidlib:generateReleaseBuildConfig
> Task :GoogleMobileAdsPlugin.androidlib:generateReleaseResValues
> Task :GoogleMobileAdsPlugin.androidlib:generateReleaseResources
> Task :GoogleMobileAdsPlugin.androidlib:packageReleaseResources
> Task :GoogleMobileAdsPlugin.androidlib:generateReleaseRFile
> Task :GoogleMobileAdsPlugin.androidlib:prepareLintJar UP-TO-DATE
> Task :GoogleMobileAdsPlugin.androidlib:generateReleaseSources
> Task :GoogleMobileAdsPlugin.androidlib:javaPreCompileRelease
> Task :GoogleMobileAdsPlugin.androidlib:compileReleaseJavaWithJavac
> Task :GoogleMobileAdsPlugin.androidlib:bundleLibCompileRelease
> Task :javaPreCompileRelease UP-TO-DATE
> Task :mainApkListPersistenceRelease UP-TO-DATE
> Task :generateReleaseResValues UP-TO-DATE
> Task :generateReleaseResources UP-TO-DATE
> Task :mergeReleaseResources
> Task :createReleaseCompatibleScreenManifests
> Task :processReleaseManifest
> Task :processReleaseResources FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings
21 actionable tasks: 13 executed, 8 up-to-date
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <267278aa48b840c7a0e7281223ea050e>:0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <267278aa48b840c7a0e7281223ea050e>:0)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <267278aa48b840c7a0e7281223ea050e>:0)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <267278aa48b840c7a0e7281223ea050e>:0)
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <267278aa48b840c7a0e7281223ea050e>:0)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <267278aa48b840c7a0e7281223ea050e>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <267278aa48b840c7a0e7281223ea050e>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <267278aa48b840c7a0e7281223ea050e>:0)
Rethrow as BuildFailedException: Exception of type 'UnityEditor.Build.BuildFailedException' was thrown.
UnityEditor.Android.PostProcessor.CancelPostProcess.AbortBuild (System.String title, System.String message, System.Exception ex) (at <267278aa48b840c7a0e7281223ea050e>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <267278aa48b840c7a0e7281223ea050e>:0)
UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <267278aa48b840c7a0e7281223ea050e>:0)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <267278aa48b840c7a0e7281223ea050e>:0)
UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:288)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)

Error Image 1

Error Image details2

Error Image details3

Error Image details4

Answer

hardartcore picture hardartcore · Jan 12, 2021

The error you are getting is because since Android 11 Google changed the package visibility. You can learn more about it here: Package Visibilty.

Since the gradle version which Unity uses does not support the newly added <queries> tag which is obviously used by one of the libraries you are using in your projects the build fails.

You have two possible solutions for this:

  1. Change your Target API Level value from Player Settings inside Unity to use Android 10 (API Level 29). This way you will be able to build directly from inside Unity.
  2. The second option is to export your project and build using Android Studio. This will slow down a little bit the development process, because everytime you want to test on a device you will have to build the project two times.