AliAhmadUnityDev
AliAhmadUnityDev

Reputation: 31

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

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

Upvotes: 2

Views: 11520

Answers (4)

emrettc
emrettc

Reputation: 1

First download gradle-5.4.6

Go to Build Settings > Android, and set Build System to Gradle to use the custom Gradle version.

Go to Preferences > External Tools > Android > Gradle Installed with Unity. Clear the option, and specify a custom version of 5.6.4 or later.

Go to Project Settings > Player > Android tab > Publishing Settings > Build, and select Custom Gradle Template.

Edit the generated file Assets/Plugins/Android/mainTemplate.gradle, and set the dependency com.android.tools.build:gradle to 3.6.0 or later based on the Gradle version you use.

      com.android.tools.build:gradle:3.6.0'

I hope, this will solve your problem.

adding!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

you should do this for all generated gradle files you should do version control

Upvotes: 0

Amir Khavari
Amir Khavari

Reputation: 21

I had the same issue and was googling for more than a week without finding the solution. The solution is actually too simple, you have to enable Launcher Gradle Template and edit the file that unity will generate, add:

configurations.all {
  resolutionStrategy {
    force 'androidx.core:core:1.6.0'
    force 'androidx.core:core-ktx:1.6.0'
  }
}

At the end of your launcherTemplate.gradle file in Plugins/Android.

Credits of the answer is for this answer

EDIT: You need to migrate your Google Packages to be handled with Google itself, instead of being handled by Unity Package Manager. I also needed to update my Unity IAP package to a version higher than 3. Read more...

Upvotes: 0

Rahajul Amin
Rahajul Amin

Reputation: 11

  • First download gradle-5.4.6

  • Go to Build Settings > Android, and set Build System to Gradle to use the custom Gradle version.

  • Go to Preferences > External Tools > Android > Gradle Installed with Unity. Clear the option, and specify a custom version of 5.6.4 or later.

  • Go to Project Settings > Player > Android tab > Publishing Settings > Build, and select Custom Gradle Template.

  • Edit the generated file Assets/Plugins/Android/mainTemplate.gradle, and set the dependency com.android.tools.build:gradle to 3.6.0 or later based on the Gradle version you use.

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.0'
    }
}

I hope, this will solve your problem.

Upvotes: 1

hardartcore
hardartcore

Reputation: 17037

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.

Upvotes: 4

Related Questions