diff --git a/AdMobAdapter/build.gradle.kts b/AdMobAdapter/build.gradle.kts index ac4a232..59a89db 100644 --- a/AdMobAdapter/build.gradle.kts +++ b/AdMobAdapter/build.gradle.kts @@ -34,7 +34,7 @@ android { minSdk = 21 targetSdk = 33 // If you touch the following line, don't forget to update scripts/get_rc_version.zsh - android.defaultConfig.versionName = System.getenv("VERSION_OVERRIDE") ?: "4.22.3.0.3" + android.defaultConfig.versionName = System.getenv("VERSION_OVERRIDE") ?: "4.22.3.0.4" buildConfigField( "String", diff --git a/AdMobAdapter/src/main/java/com/chartboost/mediation/admobadapter/AdMobAdapter.kt b/AdMobAdapter/src/main/java/com/chartboost/mediation/admobadapter/AdMobAdapter.kt index 12ad7e5..861daa0 100644 --- a/AdMobAdapter/src/main/java/com/chartboost/mediation/admobadapter/AdMobAdapter.kt +++ b/AdMobAdapter/src/main/java/com/chartboost/mediation/admobadapter/AdMobAdapter.kt @@ -27,6 +27,7 @@ import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.launch import kotlinx.coroutines.suspendCancellableCoroutine @@ -49,9 +50,13 @@ class AdMobAdapter : PartnerAdapter { else value.joinToString() }" ) - MobileAds.setRequestConfiguration( - RequestConfiguration.Builder().setTestDeviceIds(value).build() - ) + + // There have been known ANRs when calling setRequestConfiguration() on the main thread. + CoroutineScope(IO).launch { + MobileAds.setRequestConfiguration( + RequestConfiguration.Builder().setTestDeviceIds(value).build() + ) + } } /** @@ -211,16 +216,19 @@ class AdMobAdapter : PartnerAdapter { else COPPA_NOT_SUBJECT ) - MobileAds.setRequestConfiguration( - MobileAds.getRequestConfiguration().toBuilder() - .setTagForChildDirectedTreatment( - if (isSubjectToCoppa) { - RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE - } else { - RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE - } - ).build() - ) + // There have been known ANRs when calling setRequestConfiguration() on the main thread. + CoroutineScope(IO).launch { + MobileAds.setRequestConfiguration( + MobileAds.getRequestConfiguration().toBuilder() + .setTagForChildDirectedTreatment( + if (isSubjectToCoppa) { + RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE + } else { + RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE + } + ).build() + ) + } } /** diff --git a/CHANGELOG.md b/CHANGELOG.md index f173e70..38b8b58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ Note the first digit of every adapter version corresponds to the major version of the Chartboost Mediation SDK compatible with that adapter. Adapters are compatible with any Chartboost Mediation SDK version within that major version. +### 4.22.3.0.4 +- Offload `setRequestConfiguration()` calls to background threads to avoid ANRs. + ### 4.22.3.0.3 - Add support for adaptive banner sizes. diff --git a/README.md b/README.md index fbff01c..4133405 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The Chartboost Mediation AdMob adapter mediates AdMob via the Chartboost Mediati In your `build.gradle`, add the following entry: ``` - implementation "com.chartboost:chartboost-mediation-adapter-admob:4.22.3.0.3" + implementation "com.chartboost:chartboost-mediation-adapter-admob:4.22.3.0.4" ``` ## Contributions