2

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

hardartcore
  • 16,886
  • 12
  • 75
  • 101
AliAhmadUnityDev
  • 31
  • 1
  • 1
  • 3
  • **DO NOT post images of code, data, error messages, etc.** - copy or type the text into the question. [ask] – Rob Jan 15 '21 at 11:41

4 Answers4

4

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.
hardartcore
  • 16,886
  • 12
  • 75
  • 101
  • Hi @hardartcore I have seen your reply but let me tell you something that Unity 2018 Editor versions doesn't allows to select Target API Level greater than 28 so our hands are tied to select this API Level. Can you please guide me if we can change the API level by some other means in unity because we cannot always export the project to Android Studio. – AliAhmadUnityDev Jan 12 '21 at 10:37
  • Can you show your player settings? It should work with API Level 28 too. – hardartcore Jan 12 '21 at 10:39
  • Hi, Sorry I just reconfirmed that Unity 2018.4.30 LTS show API level 30 too but some previous versions doesn't show this dropdown for API level 28 and 30. But still the problem exists, I have selected 30 API level from player setting as Target API level. I am sharing the Screenshot too: https://drive.google.com/file/d/14OEOBBHq_KEDXBl9GgL9CpnEAm18RDF3/view?usp=sharing – AliAhmadUnityDev Jan 12 '21 at 10:51
  • As described in the answer select lower API level than the latest 30. API Level 29 for example and try to build. – hardartcore Jan 12 '21 at 10:53
  • I got your point and tried with API level 29 and also with 28 but no luck, still getting same error: https://drive.google.com/file/d/1kKznqUgdCNEAQMFwl0M10Whwtc0xL_Z2/view?usp=sharing – AliAhmadUnityDev Jan 12 '21 at 11:08
  • Can you validate that it's still the same error, not something else? – hardartcore Jan 12 '21 at 11:13
  • Here is the complete Console Error Details, I can confirm that its same error again: https://drive.google.com/file/d/15sBalQ8QA0VYIUwMyvu7fEH24lQZkNRZ/view?usp=sharing – AliAhmadUnityDev Jan 12 '21 at 11:20
  • Can you check your AndroidManifest.xml files in your project and see in which one you can find that tag: `` – hardartcore Jan 12 '21 at 12:15
  • Here is the Attached AndroidManifest.xml and it is the only manifest file in project. https://drive.google.com/file/d/1s5QGXeK_PJ-lWdVM1cq3z9G4aoZu62vO/view?usp=sharing – AliAhmadUnityDev Jan 12 '21 at 12:24
  • I guess `queries` tag comes from some of the native libraries. I've checked with the same libraries in a sample project and have no issues when target is set to API level 29. The apk builds without any issues. I would suggest maybe to update Unity to 2019 LTS and try with it if it's not a big project. 2018 is quite old even though it still received updates (only bug fixes). – hardartcore Jan 12 '21 at 13:02
  • I already mentioned in my actual question that if I use only one SDK (Google mobile Ads sdk OR Facebook Audience Network sdk) then the build is successful however my problem is occurring when i am using both of these sdks simultaneously in a project. Can you please reconfirm me that you have used both of these SDKs or not? Also i am open to share my sample project if it can be helpful to track the issue. – AliAhmadUnityDev Jan 12 '21 at 13:44
  • Yes, I've tested with both sdk's installed in a project. – hardartcore Jan 12 '21 at 13:45
  • 1
    Check out this page, it's kind of related to your issue with queues (it has guidance how to deal with `` tag in AndroidManifest.xml in Unity): https://developers.google.com/ar/develop/unity/android-11-build – obywan Jan 12 '21 at 15:11
  • I am sharing the Project complete files for you all to go through it and check it if required: https://drive.google.com/file/d/1OnkUjRQcKUqHuEthhd3yN9Yi08vh4QQp/view?usp=sharing – AliAhmadUnityDev Jan 13 '21 at 05:51
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.

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

I hope, this will solve your problem.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
0

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

Amir Khavari
  • 21
  • 1
  • 5
0

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

emrettc
  • 1
  • 1