Crash admob sdk Targeting S+ (version 31 and above)

2,458 views
Skip to first unread message

Robot Android

unread,
Sep 12, 2021, 8:41:25 PM9/12/21
to Google Mobile Ads SDK Developers
compileSdkVersion 31
implementation 'com.google.android.gms:play-services-ads:20.3.0'

java.lang.IllegalArgumentException: com.exampl.alldubstepradio: 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.c(:174)
        at androidx.work.impl.utils.ForceStopRunnable.d(:108)
        at androidx.work.impl.utils.ForceStopRunnable.run(:86)
        at d0.f$a.run(:75)
        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)

Mobile Ads SDK Forum Advisor

unread,
Sep 13, 2021, 4:35:04 AM9/13/21
to dejan...@gmail.com, google-adm...@googlegroups.com
Hi Kirill,

Thank you for reporting this to us.

I've tried our sample app with the same setup as you provided, and I wasn't able to reproduce the behavior on my end. Instead, the app successfully build and I was able to display test ads (please see attached screenshot). With this, could you please check if you were able to reproduce the reported issue on our sample app? If so, please provide it to us by uploading it to Google Drive, then provide the shareable link to us via Reply privately to author option (or send it directly to mobileads...@gmail.com, then inform us on this thread if you sent it directly to the email provided).

Regards,
Google Logo
Teejay Wennie Pimentel
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2NTX5q:ref
Screen Shot 2021-09-13 at 3.30.55 PM.png

Robot Android

unread,
Sep 13, 2021, 6:02:14 AM9/13/21
to Google Mobile Ads SDK Developers
Add
buildToolsVersion '31.0.0'
targetSdkVersion 31


понедельник, 13 сентября 2021 г. в 15:35:04 UTC+7, mobileadssdk:

Robot Android

unread,
Sep 13, 2021, 6:02:24 AM9/13/21
to Google Mobile Ads SDK Developers
ad.png

Mobile Ads SDK Forum Advisor

unread,
Sep 13, 2021, 2:27:56 PM9/13/21
to dejan...@gmail.com, google-adm...@googlegroups.com
Hi Robot Android,

Thank you for the additional information. Can you send us a zip with the sample app that you have gettening this error? I would like to compare it to what we are seeing here. When taking the information that you gave us, I am getting the SDK is corrupted error and would like to compare this to what you are seeing.

Regards,
Google Logo
William Pescherine
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2NTX5q:ref

Bastiaan

unread,
Sep 13, 2021, 5:11:57 PM9/13/21
to Google Mobile Ads SDK Developers
Hi,

The same issue has already been discussed in this thread. Does this means that the current mobile ads SDK (20.3.0) is still not compatible with Android S (31)? While the discussion about this issue dates back to February 19th 2021?? Meanwhile, the Android S beta.5 version has just been released, and the stable release is expected in a couple of weeks. 

I would very much like to start targeting sdk version 31 for all my apps, without a hack that includes an unstable version as described in the last comment of the thread I mentioned. Can you please tell when the mobile ads SDK is expected to be compatible with Android S (sdk 31)?

Thanks,
Bas


Robot Android

unread,
Sep 14, 2021, 12:55:18 AM9/14/21
to Google Mobile Ads SDK Developers
New workmanager Version 2.7.0 is required for apps targeting Android 12 (S).
implementation 'androidx.work:work-runtime:2.7.0-beta01'

ww0.png
ww.png

Mobile Ads SDK Forum Advisor

unread,
Sep 14, 2021, 4:04:48 AM9/14/21
to b.a.van...@gmail.com, google-adm...@googlegroups.com

Hello Bastian,

Thank you for reaching out to us.

For us to further investigate this, could you please provide us with a sample app with your implementation of SDK 20.3.0 with targeted V31 via Reply privately to author option or send it directly to mobileads...@gmail.com? Kindly inform us on this thread if you sent it directly to the email provided.

Regards,

Google Logo
Princess Pamela Pineda
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2NTX5q:ref

Mobile Ads SDK Forum Advisor

unread,
Sep 14, 2021, 4:04:52 AM9/14/21
to dejan...@gmail.com, google-adm...@googlegroups.com

Hello Robot,

Thank you for your response.

As far as we know, there is no need for workmanager dependency when using Mobile Ads SDK. But since this is an android requirement, that's why it's probably working when adding the workmanager dependency.

Regards,

Google Logo
Princess Pamela Pineda
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2NTX5q:ref

Robot Android

unread,
Sep 14, 2021, 9:15:59 AM9/14/21
to Google Mobile Ads SDK Developers
Then why does the Admob sdk add the old version of workmanager to the manifest?

вторник, 14 сентября 2021 г. в 15:04:52 UTC+7, mobileadssdk:

Mobile Ads SDK Forum Advisor

unread,
Sep 14, 2021, 8:06:03 PM9/14/21
to dejan...@gmail.com, google-adm...@googlegroups.com
Hi Robot Android,

Thank you for the additional information., I was attempting to get our sample app to run with the changes you suggested. But was unable to get it to work. As such let me bring this to my team and see what feedback we get. Also they can maybe offer more information on Android 31 and its compatibility.

Regards,
Google Logo
William Pescherine
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2NTX5q:ref

Mobile Ads SDK Forum Advisor

unread,
Sep 20, 2021, 2:23:23 PM9/20/21
to dejan...@gmail.com, google-adm...@googlegroups.com

Hi Kirill Buriko,

I was unable to replicate this issue. Here is how I modified the AdMob Banner Java sample  :

- TargetSdkVersion 31

- Targeted play-services-ads 20.3.0.

- Added androidx.work:work-runtime:2.7.0-beta01

If you could reply back with a minimal sample app or steps to modify the sample app to demonstrating this problem, I will be able to continue troubleshooting this for you.



ref:_00D1U1174p._5004Q2NTX5q:ref

Robot Android

unread,
Sep 21, 2021, 1:49:21 AM9/21/21
to Google Mobile Ads SDK Developers
The sdk should work without the additional androidx. work:work-runtime:2.7.0-beta01


вторник, 21 сентября 2021 г. в 01:23:23 UTC+7, mobileadssdk:

Mobile Ads SDK Forum Advisor

unread,
Sep 22, 2021, 4:43:44 PM9/22/21
to dejan...@gmail.com, google-adm...@googlegroups.com

Hi Robert,

 

We are unable to replicate this error on our end. Our sample worked without error targeting sdk 31 and the work-runtime 2.7.

Could you try removing ads from your application and seeing if the problem persists?

 

Thanks, Nick



ref:_00D1U1174p._5004Q2NTX5q:ref

Robot Android

unread,
Sep 22, 2021, 9:41:46 PM9/22/21
to Google Mobile Ads SDK Developers
The application works fine with work-runtime 2.7.0
We want work-runtime 2.7.0 to be embedded in admob sdk without adding a separate implementation 'androidx. work:work-runtime:2.7.0-beta01'
Update the version work:work-runtime included in admob from 2.1.0 to 2.7.0
ww.png

Mobile Ads SDK Forum Advisor

unread,
Sep 23, 2021, 3:18:59 PM9/23/21
to dejan...@gmail.com, google-adm...@googlegroups.com

Hi Robert,

 

I understand your concern, and will  continue to look into a long term solution.

In the interim, is it correct to say that the work around of importing `work-runtime 2.7.0' solves your immediate issue? If not, please feel free to reach out.

Robot Android

unread,
Sep 24, 2021, 1:17:24 AM9/24/21
to Google Mobile Ads SDK Developers
Yes, adding work-runtime 2.7.0 fixes the problem, but testing on real devices is required.

Mobile Ads SDK Forum Advisor

unread,
Oct 6, 2021, 4:23:03 PM10/6/21
to dejan...@gmail.com, google-adm...@googlegroups.com

Hi Robot Android, 

 

I am glad that adding work-runtime 2.7.0 fixes the problem. I have let the engineering team know about the issue, and they will consider further changes.

If you need additional support, please feel free to reach out.

Bastiaan

unread,
Oct 18, 2021, 5:08:50 AM10/18/21
to Google Mobile Ads SDK Developers
Hi,

Could you please let us know when we can expect a mobile ads SDK update that uses work-runtime 2.7.0? In other words, when can we expect a mobile ads SDK that is compatible with Android 12?

I would rather not use the mentioned workaround in production, because even though the app runs if I you use that workaround, how can I be sure that the SDK works properly with work-runtime 2.7.0? Has this been tested at all?

Kind regards,
Bas

Mobile Ads SDK Forum Advisor

unread,
Oct 18, 2021, 1:27:46 PM10/18/21
to b.a.van...@gmail.com, google-adm...@googlegroups.com

Hello Bastiaan,

Thank you for reaching out. I understand your concern about implementing a work around in production.

That said, the issue has been reported to engineering and is under review, but I can not give an estimate on to when the solution will be approved and implement.

Please let me know if you run into any further issues.

- Nick



ref:_00D1U1174p._5004Q2NTX5q:ref

Assaf Cohen

unread,
Oct 31, 2021, 7:42:34 PM10/31/21
to Google Mobile Ads SDK Developers
Hi,
Is there any workaround we can implement for Unity? 
We're getting the same crash on Pixel devices that got the Android 12 update this week.

Thanks.

Mobile Ads SDK Forum Advisor

unread,
Nov 1, 2021, 6:56:39 PM11/1/21
to zkof...@gmail.com, google-adm...@googlegroups.com

Hello Assaf Cohen,

Thank you for reaching out. I understand your concern.

The issue has been reported to engineering and a fix is in progress.



Please let me know if you run into any further issues,

rootBerz LLC

unread,
Nov 1, 2021, 7:06:46 PM11/1/21
to Google Mobile Ads SDK Developers
I am having the same issue. Here are my steps to reproduce. Note that the crash happens when deployed to a device running Android 12. I have a Pixel XL 3a running Android 12.

STEPS:

Create a new Android Studio project with an Empty Activity. Android Studio will create its own Manifest and Gradle, etc...

Add to Manifest:
<!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>


GRADLE:
plugins {
    id 'com.android.application'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.testing.admobissuee"
        minSdk 21
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.google.firebase:firebase-ads:20.4.0'   // THE PROJECT WILL DEPLOY TO YOUR DEVICE IF THIS LINE IS REMOVED
}

Deploy app to a device running Android 12.

ERROR will be:
2021-11-01 11:50:56.416 1642-1709/com.rootberz.admobissuee E/AndroidRuntime: FATAL EXCEPTION: pool-3-thread-1
    Process: com.rootberz.admobissuee, PID: 1642
    java.lang.IllegalArgumentException: com.rootberz.admobissuee: 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.getPendingIntent(ForceStopRunnable.java:174)
        at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:108)
        at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:86)
        at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:75)
        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)

Mobile Ads SDK Forum Advisor

unread,
Nov 2, 2021, 7:35:16 PM11/2/21
to rootb...@gmail.com, google-adm...@googlegroups.com

Hi rootBerz,

 

Can you please try adding 'work-runtime 2.7.0' implementation to your build.gradle? This solved the issue for the previous publisher, and reason it should work for you as well.

 

implementation 'com.google.android.gms:play-services-ads:20.4.0'

// For apps targeting Android 12, add the following

constraints {

  implementation('androidx.work:work-runtime:2.7.0')

}

Thanks,

Bastiaan

unread,
Nov 5, 2021, 3:50:25 PM11/5/21
to Google Mobile Ads SDK Developers
Hi,

I see that the fix is now also included in the v20.4.0 release notes (https://developers.google.com/admob/android/rel-notes), does this mean that this fix is thoroughly tested and can be used in production?

Can you give any indication when we can expect a mobile ads SDK version for which this fix is no longer needed?

Thanks!
Bas

Mobile Ads SDK Forum Advisor

unread,
Nov 11, 2021, 1:38:43 PM11/11/21
to b.a.van...@gmail.com, google-adm...@googlegroups.com

Hi Bastian,

 

That is correct. The fix requires modifying the AndroidManifest.xml by adding the AD_ID declaration. I have included a code sample below for your convenience. 
 

 <application>
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>

        <!-- Required permissions for GMA SDK version 20.3.0 or lower to work on Android S devices -->
        <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

    </application>
</manifest>

Bastiaan

unread,
Nov 11, 2021, 1:55:56 PM11/11/21
to Google Mobile Ads SDK Developers
Sorry, I was referring to the fix that is discussed in this thread, and which is now also published in your release notes:

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

Is that fix tested? Can we use it in production? 

Mobile Ads SDK Forum Advisor

unread,
Nov 15, 2021, 1:34:54 PM11/15/21
to b.a.van...@gmail.com, google-adm...@googlegroups.com

Hi Bastiaan,

 

Yes, this fix is tested and good for production.

 

Cheers,

Reply all
Reply to author
Forward
0 new messages