Hello, I'm trying to load a sample native ad into my own app using the Google Ads SDK (`com.google.android.gms:play-services-ads:22.2.0`) but every attempt to load an ad results in the "No fill." error (error code 3).
Here is the setup in my own codebase, politely borrowed from the sample codebase above for testing purposes:
---------------- Android manifest file
<application
...>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-9939518381636264~1092563270" />
<activity
....
android:exported="true"
android:launchMode="singleTask" ...
---------------- /manifest
------------------ MainActivity.kt
...
private fun refreshAd() {
val builder = AdLoader.Builder(this, "/6499/example/native")
builder.forNativeAd { nativeAd ->
// If this callback occurs after the activity is destroyed, you must call
// destroy and return or you may get a memory leak.
var activityDestroyed = false
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
activityDestroyed = isDestroyed
}
if (activityDestroyed || isFinishing || isChangingConfigurations) {
nativeAd.destroy()
return@forNativeAd
}
}
val videoOptions =
VideoOptions.Builder().setStartMuted(false).build()
val adOptions = NativeAdOptions.Builder().setVideoOptions(videoOptions).build()
builder.withNativeAdOptions(adOptions)
val adLoader =
builder
.withAdListener(
object : AdListener() {
override fun onAdFailedToLoad(loadAdError: LoadAdError) {
val error =
""""
domain: ${loadAdError.domain}, code: ${loadAdError.code}, message: ${loadAdError.message}
"""
Toast.makeText(
this@MainActivity,
"Failed to load native ad with error $error",
Toast.LENGTH_SHORT
)
.show()
}
}
)
.build()
adLoader.loadAd(AdManagerAdRequest.Builder().build())
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
MobileAds.initialize(this) { }
refreshAd()
...
------------------ /MainActivity.kt
I have also tried both setting my device to "test" mode and not setting my device to "test" mode, both with the same error noted above. Is there something I may have missed that would always result in a "No fill." error when loading the test ads?