Android 12 App crashes on startup due to error with PendingIntent (Google Mobile Ads plugin used)

My unity project uses Google Ad Mob Unity Plugin v6.1.2 which is the latest version.
Target api level is 31.
The game runs fine on devices that run Android 8.0 to 11.0.
Using Unity 2020.3.25f1.

I am running an android emulator through Android Studio that uses a Pixel3a android api level 31 (Android 12) to run my unity game and this is what Logcat spits back at me upon launching the app (Take a look at line 4 & line 5):

2021-12-22 21:42:27.599 9019-9038/? E/AndroidRuntime: FATAL EXCEPTION: pool-3-thread-1
    Process: com.Guambo.GooRunner, PID: 9019
    java.lang.IllegalArgumentException: com.Guambo.GooRunner: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
    Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
        at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
        at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
        at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
        at androidx.work.impl.utils.ForceStopRunnable.a(Unknown Source:5)
        at androidx.work.impl.utils.ForceStopRunnable.a(Unknown Source:4)
        at androidx.work.impl.utils.ForceStopRunnable.run(Unknown Source:52)
        at androidx.work.impl.utils.f$a.run(Unknown Source:2)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:920)

After scouring the web I found this stackoverflow answer and tried to add this WorkManager dependency to the mainTemplate.gradle file in Unity (In Unity, set the following checkbox to true to create a custom main gradle template file called mainTemplate.gradle: ProjectSettings>PlayerSettings>PublishingSettings>Build>Custom Main Gradle Template).

However, even after adding this dependency to the projects gradle file, I still encounter the error above.
So I am thinking that somewhere through the use of the Google Mobile Ads Unity Plugin, they are creating an object of type PendingIntent and not specifing FLAG_IMMUTABLE or FLAG_MUTABLE.

The type of Ad that I am running is a rewarded ad. Here is all Google Mobile Ad related code in my unity project:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using GoogleMobileAds.Api;
using System;

// https://developers.google.com/admob/unity/quick-start
// Rewarded Ads - https://developers.google.com/admob/unity/rewarded
// Sample Impl - https://github.com/googleads/googleads-mobile-unity/blob/master/samples/HelloWorld/Assets/Scripts/GoogleAdMobController.cs
public class GoogleAdsController : MonoBehaviour
{
    private RewardedAd rewardedAd;
    public UnityEvent OnAdLoadedEvent;
    public UnityEvent OnAdFailedToLoadEvent;
    public UnityEvent OnUserEarnedRewardEvent;
    public UnityEvent OnAdClosedEvent;

    void Start()
    {
        // Make sure to set ads to be kid friendly
        RequestConfiguration requestConfiguration =
            new RequestConfiguration.Builder()
            .SetTagForChildDirectedTreatment(TagForChildDirectedTreatment.True)
            .SetMaxAdContentRating(MaxAdContentRating.G)
            .build();
        MobileAds.SetRequestConfiguration(requestConfiguration);

        // Initialize the Google Mobile Ads SDK
        MobileAds.Initialize(initStatus => { });

        // Load an Ad
        rewardedAd = RequestAndLoadRewardedAd();
    }
    // Load an rewarded Ad
    public RewardedAd RequestAndLoadRewardedAd()
    {
        // The following adUnitId is a test ad, in my actual game build I am using a valid adUnitId
        // I just changed it for the unity forum post 
        string adUnitId = "ca-app-pub-3940256099942544/5224354917";

        // Create new rewarded ad instance
        RewardedAd rewardedAd = new RewardedAd(adUnitId);

        // Add Event Handlers (https://docs.unity3d.com/ScriptReference/Events.UnityEvent.html)
        rewardedAd.OnAdLoaded += (sender, args) => OnAdLoadedEvent.Invoke();
        rewardedAd.OnAdFailedToLoad += (sender, args) => OnAdFailedToLoadEvent.Invoke();
        rewardedAd.OnUserEarnedReward += (sender, args) => OnUserEarnedRewardEvent.Invoke();
        rewardedAd.OnAdClosed += (sender, args) => OnAdClosedEvent.Invoke();

        // Create empty ad request
        rewardedAd.LoadAd(CreateAdRequest());
        // Return rewarded ad
        return rewardedAd;
    }
   
    // Show the rewarded Ad
    public void ShowRewardedAd()
    {
        if (rewardedAd != null)
        {
            if (rewardedAd.IsLoaded())
                rewardedAd.Show();
        }
    }

    private AdRequest CreateAdRequest()
    {
        return new AdRequest.Builder()
            .AddExtra("max_ad_content_rating", "G")
            .AddExtra("is_designed_for_families", "true")
            .Build();
    }

    // On Closed
    public void OnAdClosed()
    {
        // Debug.Log("Loading new ad");
        // Load up a new ad
        rewardedAd = RequestAndLoadRewardedAd();
    }
}

I am not running any other plugins, I am not making a notification calls. So I have no idea where else a PendingIntent could be made other than through the Google Mobile Ads internal code.

1 Like

Starting Android 12, any Pending Intents creation needs Mutability flags. Look if any updates published for those plugins to get it resolved.

1 Like

Found the official release notes to fix this issue if anyone happens to stumble upon this thread:

Basically, in unity you need to edit the mainTemplate.gradle file to include the dependencies mentioned in the above link.

  1. In Unity, set the following checkbox to true to create a custom main gradle template file called mainTemplate.gradle: ProjectSettings>PlayerSettings>PublishingSettings>Build>Custom Main Gradle Template
  2. In mainTemplate.gradle go to the dependencies section and change it to this:
dependencies {
  implementation 'com.google.android.gms:play-services-ads:20.4.0'

  // For apps targeting Android 12, add WorkManager dependency.
  constraints {
   implementation('androidx.work:work-runtime:2.7.0') {
     because '''androidx.work:work-runtime:2.1.0 pulled from
     play-services-ads has a bug using PendingIntent without
     FLAG_IMMUTABLE or FLAG_MUTABLE and will fail in Apps
     targeting S+.'''
   }
  }
}
8 Likes

This worked for me! Thank you very much.

1 Like

I can’t get this to work, where am I supposed to paste it? I’m having issues with Google AdMob and/or Yodo1

Hello brother. Would you like to send me your current manifest, gradle Templete and gradle properties template if any. i actually tried this but now build is not being generated sadly

@Guambo1 , thank you very much that worked for me.

@partimejobnaveed , below is my gradle template dependencies.

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.android.gms:play-services-ads:20.4.0'
    constraints {
        implementation('androidx.work:work-runtime:2.7.0') {
            because '''androidx.work:work-runtime:2.1.0 pulled from
            play-services-ads has a bug using PendingIntent without
            FLAG_IMMUTABLE or FLAG_MUTABLE and will fail in Apps
            targeting S+.'''
        }
    }
// Android Resolver Dependencies End
**DEPS**
}

But please note, when I applied it, it was failing to build. Additionally I had to add below to my gradleTemplate.properties

android.useAndroidX=true
android.enableJetifier=true

I hope this will help you.

Edit: Apparently something reverted my gradle template. I made correction on that part.

3 Likes

//Thank you so much dude. I’ll definitely try this again. Thanks again :slight_smile:

1- Update Firebase if you have.
2- Update Admob.
3- Delete all file “il2cpp”
A -Go to your project path /Library/il2cpp_android_arm64-v8a
B- Delete ~/Library/il2cpp_android_armeabi-v7a
C- Delete ~/Library//Il2cppBuildCache
4- Before Enable mainTemplate.gradle you must Enable “Custom Gradle properties Template” first.
5- You must know what is your admob version before copy this line

implementation 'com.google.android.gms:play-services-ads:20.4.0'
    constraints {
        implementation('androidx.work:work-runtime:2.7.0') {
            because '''androidx.work:work-runtime:2.1.0 pulled from
           play-services-ads has a bug using PendingIntent without
           FLAG_IMMUTABLE or FLAG_MUTABLE and will fail in Apps
           targeting S+.'''
        }
    }

You Can found your admob version from “mainTemplate.gradle”
For me like that :

  implementation 'com.google.android.gms:play-services-ads:20.6.0'
    constraints {
        implementation('androidx.work:work-runtime:2.7.0') {
            because '''androidx.work:work-runtime:2.1.0 pulled from
           play-services-ads has a bug using PendingIntent without
           FLAG_IMMUTABLE or FLAG_MUTABLE and will fail in Apps
           targeting S+.'''
        }
    }

6- for me “Api Compatibility Level” .Net 4.x "I’m not sure if will affect "
7- Be patient
8- Be patient
9- Be patient
10- Say I hate Android
11- Say thank you for @Guambo1
Thank you Guambo1

4 Likes

Thanks @Guambo1

one more thing you should use your admob ad version in first line instead of “20…6.0” because I was having this issue.

  • implementation ‘com.google.android.gms:play-services-ads:20.6.0’
  • constraints {
  • implementation(‘androidx.work:work-runtime:2.7.0’) {
  • because ‘’'androidx.work:work-runtime:2.1.0 pulled from
  • play-services-ads has a bug using PendingIntent without
  • FLAG_IMMUTABLE or FLAG_MUTABLE and will fail in Apps
  • targeting S+.‘’’
  • }
  • }
1 Like

MY FRIEND YOU ARE A GIFT FROM GOD.

1 Like

not working for me at all. after build it says to many errors.
any other solution?

hi, i’m using (unity 2019.4.40f1 LTS) the solution only worked for me once and when i tried again to build with same (project settings) and (mainTemplate.gradle) and Enabled (Custom Gradle properties Template). it gave 5 errors.
first 3 errors :
error1

Starting a Gradle Daemon, 1 incompatible and 2 stopped Daemons could not be reused, use --status for details

Configure project :launcher
WARNING: The option setting ‘android.bundle.enableUncompressedNativeLibs=false’ is experimental and unsupported.
The current default is ‘true’.

Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\30.0.2\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-29\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-30\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\30.0.2\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-29\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-30\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\package.xml. Probably the SDK is read-only

Configure project :unityLibrary
WARNING: The option setting ‘android.bundle.enableUncompressedNativeLibs=false’ is experimental and unsupported.
The current default is ‘true’.

Configure project :unityLibrary:GoogleMobileAdsPlugin.androidlib
WARNING: The option setting ‘android.bundle.enableUncompressedNativeLibs=false’ is experimental and unsupported.
The current default is ‘true’.

Configure project :unityLibrary:GooglePlayGamesManifest.plugin
WARNING: The option setting ‘android.bundle.enableUncompressedNativeLibs=false’ is experimental and unsupported.
The current default is ‘true’.

UnityEngine.GUIUtility:processEvent (int,intptr)

error2

FAILURE: Build failed with an exception.

  • What went wrong:
    Could not determine the dependencies of task ‘:launcher:preReleaseBuild’.

Could not resolve all task dependencies for configuration ‘:launcher:releaseRuntimeClasspath’.
Could not resolve com.google.android.gms:play-services-ads-base:[19.5.0].
Required by:
project :launcher > project :unityLibrary > com.google.android.gms:play-services-ads:19.5.0
Failed to list versions for com.google.android.gms:play-services-ads-base.
Unable to load Maven meta-data from https://jcenter.bintray.com/com/google/android/gms/play-services-ads-base/maven-metadata.xml.
Could not get resource ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-base/maven-metadata.xml’.
Could not GET ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-base/maven-metadata.xml’. Received status code 403 from server: Forbidden
Failed to list versions for com.google.android.gms:play-services-ads-base.
Unable to load Maven meta-data from https://jcenter.bintray.com/com/google/android/gms/play-services-ads-base/maven-metadata.xml.
Could not get resource ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-base/maven-metadata.xml’.
Could not GET ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-base/maven-metadata.xml’. Received status code 403 from server: Forbidden
Could not resolve com.google.android.gms:play-services-ads-lite:[19.5.0].
Required by:
project :launcher > project :unityLibrary > com.google.android.gms:play-services-ads:19.5.0
Failed to list versions for com.google.android.gms:play-services-ads-lite.
Unable to load Maven meta-data from https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-ads-lite/maven-metadata.xml.
Could not HEAD ‘https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-ads-lite/maven-metadata.xml’.
Remote host closed connection during handshake
Failed to list versions for com.google.android.gms:play-services-ads-lite.
Unable to load Maven meta-data from https://jcenter.bintray.com/com/google/android/gms/play-services-ads-lite/maven-metadata.xml.
Could not get resource ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-lite/maven-metadata.xml’.
Could not GET ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-lite/maven-metadata.xml’. Received status code 403 from server: Forbidden
Failed to list versions for com.google.android.gms:play-services-ads-lite.
Unable to load Maven meta-data from https://maven.google.com/com/google/android/gms/play-services-ads-lite/maven-metadata.xml.
Could not HEAD ‘https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-ads-lite/maven-metadata.xml’.
Remote host closed connection during handshake
Failed to list versions for com.google.android.gms:play-services-ads-lite.
Unable to load Maven meta-data from https://jcenter.bintray.com/com/google/android/gms/play-services-ads-lite/maven-metadata.xml.
Could not get resource ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-lite/maven-metadata.xml’.
Could not GET ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-lite/maven-metadata.xml’. Received status code 403 from server: Forbidden
Could not resolve com.google.android.gms:play-services-gass:[19.5.0].
Required by:
project :launcher > project :unityLibrary > com.google.android.gms:play-services-ads:19.5.0
Failed to list versions for com.google.android.gms:play-services-gass.
Unable to load Maven meta-data from https://jcenter.bintray.com/com/google/android/gms/play-services-gass/maven-metadata.xml.
Could not get resource ‘https://jcenter.bintray.com/com/google/android/gms/play-services-gass/maven-metadata.xml’.
Could not GET ‘https://jcenter.bintray.com/com/google/android/gms/play-services-gass/maven-metadata.xml’. Received status code 403 from server: Forbidden
Failed to list versions for com.google.android.gms:play-services-gass.
Unable to load Maven meta-data from https://jcenter.bintray.com/com/google/android/gms/play-services-gass/maven-metadata.xml.
Could not get resource ‘https://jcenter.bintray.com/com/google/android/gms/play-services-gass/maven-metadata.xml’.
Could not GET ‘https://jcenter.bintray.com/com/google/android/gms/play-services-gass/maven-metadata.xml’. Received status code 403 from server: Forbidden

  • 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 1m 24s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

UnityEngine.GUIUtility:processEvent (int,intptr)

error3

CommandInvokationFailure: Gradle build failed.
C:/Program Files/Unity/Editor/2019.4.40f1/Editor/Data/PlaybackEngines/AndroidPlayer\OpenJDK\bin\java.exe -classpath “C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-5.1.1.jar” org.gradle.launcher.GradleMain “-Dorg.gradle.jvmargs=-Xmx4096m” “bundleRelease”

stderr[

FAILURE: Build failed with an exception.

  • What went wrong:
    Could not determine the dependencies of task ‘:launcher:preReleaseBuild’.

Could not resolve all task dependencies for configuration ‘:launcher:releaseRuntimeClasspath’.
Could not resolve com.google.android.gms:play-services-ads-base:[19.5.0].
Required by:
project :launcher > project :unityLibrary > com.google.android.gms:play-services-ads:19.5.0
Failed to list versions for com.google.android.gms:play-services-ads-base.
Unable to load Maven meta-data from https://jcenter.bintray.com/com/google/android/gms/play-services-ads-base/maven-metadata.xml.
Could not get resource ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-base/maven-metadata.xml’.
Could not GET ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-base/maven-metadata.xml’. Received status code 403 from server: Forbidden
Failed to list versions for com.google.android.gms:play-services-ads-base.
Unable to load Maven meta-data from https://jcenter.bintray.com/com/google/android/gms/play-services-ads-base/maven-metadata.xml.
Could not get resource ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-base/maven-metadata.xml’.
Could not GET ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-base/maven-metadata.xml’. Received status code 403 from server: Forbidden
Could not resolve com.google.android.gms:play-services-ads-lite:[19.5.0].
Required by:
project :launcher > project :unityLibrary > com.google.android.gms:play-services-ads:19.5.0
Failed to list versions for com.google.android.gms:play-services-ads-lite.
Unable to load Maven meta-data from https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-ads-lite/maven-metadata.xml.
Could not HEAD ‘https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-ads-lite/maven-metadata.xml’.
Remote host closed connection during handshake
Failed to list versions for com.google.android.gms:play-services-ads-lite.
Unable to load Maven meta-data from https://jcenter.bintray.com/com/google/android/gms/play-services-ads-lite/maven-metadata.xml.
Could not get resource ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-lite/maven-metadata.xml’.
Could not GET ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-lite/maven-metadata.xml’. Received status code 403 from server: Forbidden
Failed to list versions for com.google.android.gms:play-services-ads-lite.
Unable to load Maven meta-data from https://maven.google.com/com/google/android/gms/play-services-ads-lite/maven-metadata.xml.
Could not HEAD ‘https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-ads-lite/maven-metadata.xml’.
Remote host closed connection during handshake
Failed to list versions for com.google.android.gms:play-services-ads-lite.
Unable to load Maven meta-data from https://jcenter.bintray.com/com/google/android/gms/play-services-ads-lite/maven-metadata.xml.
Could not get resource ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-lite/maven-metadata.xml’.
Could not GET ‘https://jcenter.bintray.com/com/google/android/gms/play-services-ads-lite/maven-metadata.xml’. Received status code 403 from server: Forbidden
Could not resolve com.google.android.gms:play-services-gass:[19.5.0].
Required by:
project :launcher > project :unityLibrary > com.google.android.gms:play-services-ads:19.5.0
Failed to list versions for com.google.android.gms:play-services-gass.
Unable to load Maven meta-data from https://jcenter.bintray.com/com/google/android/gms/play-services-gass/maven-metadata.xml.
Could not get resource ‘https://jcenter.bintray.com/com/google/android/gms/play-services-gass/maven-metadata.xml’.
Could not GET ‘https://jcenter.bintray.com/com/google/android/gms/play-services-gass/maven-metadata.xml’. Received status code 403 from server: Forbidden
Failed to list versions for com.google.android.gms:play-services-gass.
Unable to load Maven meta-data from https://jcenter.bintray.com/com/google/android/gms/play-services-gass/maven-metadata.xml.
Could not get resource ‘https://jcenter.bintray.com/com/google/android/gms/play-services-gass/maven-metadata.xml’.
Could not GET ‘https://jcenter.bintray.com/com/google/android/gms/play-services-gass/maven-metadata.xml’. Received status code 403 from server: Forbidden

  • 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 1m 24s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
]
stdout[
Starting a Gradle Daemon, 1 incompatible and 2 stopped Daemons could not be reused, use --status for details

Configure project :launcher
WARNING: The option setting ‘android.bundle.enableUncompressedNativeLibs=false’ is experimental and unsupported.
The current default is ‘true’.

Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\30.0.2\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-29\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-30\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\30.0.2\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-29\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-30\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Editor\2019.4.40f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\package.xml. Probably the SDK is read-only

Configure project :unityLibrary
WARNING: The option setting ‘android.bundle.enableUncompressedNativeLibs=false’ is experimental and unsupported.
The current default is ‘true’.

Configure project :unityLibrary:GoogleMobileAdsPlugin.androidlib
WARNING: The option setting ‘android.bundle.enableUncompressedNativeLibs=false’ is experimental and unsupported.
The current default is ‘true’.

Configure project :unityLibrary:GooglePlayGamesManifest.plugin
WARNING: The option setting ‘android.bundle.enableUncompressedNativeLibs=false’ is experimental and unsupported.
The current default is ‘true’.

]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at :0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at :0)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at :0)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action1[T] progress, System.String error) (at <dd2e71f8d45046b88d6d3169a8084aec>:0) UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action1[T] progress) (at :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 :0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :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 :0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :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 :0)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at :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 <7105be432fb64891b07085914e6cd5c1>:0)
UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

1 Like

@mahmoud93p I went your step by steps and it worked. thanks

Same errors, in my case updating Firebase and Admob to latest plugin version solve the problem.

After i do those steps i get "AdMob policy violation, type is “Modified ad behavior”, that it’s happened for me after few months.

And i fixed by update admob sdk and i don’t make any change.
** don’t make any change in “Custom Gradle properties Template”

1 Like

Heads up, I fixed this by upgrading play-services-ads. As stated in one of the posts above, an earlier version has this problem.

1 Like

Hey yall just stopping by after having not signed into unity forums in close to a YEAR! Im glad I was able to help everyone with this - took a lot of digging to figure this issue out when I was making an update to my google play game Goo Runner last December. Im glad the most up to date official admob unity sdk patched this issue!

My mainTemplate.gradle (dependencies):

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
// Android Resolver Dependencies Start
    implementation 'androidx.lifecycle:lifecycle-common-java8:2.4.1' // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:12
    implementation 'androidx.lifecycle:lifecycle-process:2.4.1' // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:17
    implementation 'com.google.android.gms:play-services-ads:21.3.0' // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7
    implementation 'com.google.android.gms:play-services-base:18.1.0' // Assets/Firebase/Editor/AppDependencies.xml:17
    implementation 'com.google.firebase:firebase-analytics:21.2.0' // Assets/Firebase/Editor/AppDependencies.xml:15
    implementation 'com.google.firebase:firebase-analytics-unity:10.3.0' // Assets/Firebase/Editor/AnalyticsDependencies.xml:18
    implementation 'com.google.firebase:firebase-app-unity:10.3.0' // Assets/Firebase/Editor/AppDependencies.xml:22
    implementation 'com.google.firebase:firebase-common:20.2.0' // Assets/Firebase/Editor/AppDependencies.xml:13
// Android Resolver Dependencies End
**DEPS**}

Is this the correct version of my code modification?

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
// Android Resolver Dependencies Start
    implementation 'androidx.lifecycle:lifecycle-common-java8:2.4.1' // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:12
    implementation 'androidx.lifecycle:lifecycle-process:2.4.1' // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:17
    implementation 'com.google.android.gms:play-services-ads:21.3.0' // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7
 
    // For apps targeting Android 12, add WorkManager dependency.
    constraints {
        implementation('androidx.work:work-runtime:2.7.0') {
            because '''androidx.work:work-runtime:2.1.0 pulled from
            play-services-ads has a bug using PendingIntent without
            FLAG_IMMUTABLE or FLAG_MUTABLE and will fail in Apps
            targeting S+.'''
        }
    }

    implementation 'com.google.android.gms:play-services-base:18.1.0' // Assets/Firebase/Editor/AppDependencies.xml:17
    implementation 'com.google.firebase:firebase-analytics:21.2.0' // Assets/Firebase/Editor/AppDependencies.xml:15
    implementation 'com.google.firebase:firebase-analytics-unity:10.3.0' // Assets/Firebase/Editor/AnalyticsDependencies.xml:18
    implementation 'com.google.firebase:firebase-app-unity:10.3.0' // Assets/Firebase/Editor/AppDependencies.xml:22
    implementation 'com.google.firebase:firebase-common:20.2.0' // Assets/Firebase/Editor/AppDependencies.xml:13
// Android Resolver Dependencies End
**DEPS**}

Help! I am tormented with this problem.
I tried it in different ways, maybe the fact is that my version
of play-services-ads:21.3.0 and not 20.4.0 like yours?

my unity 2021.3.16f1 my error when running on Android, it only occurs when API >30
But google play only allows downloading from API >30 I can’t update the app in GooglePlay:

2022/12/30 18:21:17.308 25761 25761 Warn UnityMain type=1400 audit(0.0:3400041): avc: denied { search } for name="mqsas" dev="dm-15" ino=566 scontext=u:r:untrusted_app:s0:c113,c257,c512,c768 tcontext=u:object_r:mqsas_data_file:s0 tclass=dir permissive=0 app=com.polygon.BattleSimulator

IT’S DECIDED. The error disappeared when updating unity from 2021.3.16a1 to 2022.2.1a1 everything is perfect!

I have the same problem but can’t find any solution. none of them work for me. unity 2022.3.10f , 2022.3.8f, 2020.3.21f. I deleted all plugins, ExternalDependencyManager, GoogleMobileAds, GooglePlayPlugins folders then updated them but it is keep crashing. then I unchecked “Auto Graphics API” in the Player settings. it is working. thanks to james580.

but keep crashing on Android 13 (SDK 33), Android 12 (SDK 31), Android 14 Beta (SDK 34).

2 Likes