InterstitialAd's broken Android Studio 4.1.1


New-ish android dev, 15 year experience C, C++, Java, script language dev.

Working with Android Studio 4.1.1 and trying to work out a basic scenario. I've built my main activity with just a button that feeds to a second activity that's a google admob interstitial ad.

The admob activity is just out of the box. I've not modified it from the template other than to give it a name.

Out the door it's using what I understand to be the old library:


Which no longer exists. It should be...


Once I compile I get 8 errors. I'm assuming updates to the admob framework make this old template obsolete. I'm not sure what needs to be done to correct this. Is there an updated template I can snag, something that's communal knowledge, or does someone know what's missing from the outdated OOTB template that will get me working?

Here's the code, but I shouldn't need it as we're talking OOTB stuff.

package com.example.testapp

import android.widget.Button
import android.widget.TextView

import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast

// Remove the line below after defining your own ad unit ID.
private const val TOAST_TEXT = "Test ads are being shown. " +
        "To show live ads, replace the ad unit ID in res/values/strings.xml " +
        "with your own ad unit ID."
private const val START_LEVEL = 1

class ad1PostButtonPush : AppCompatActivity() {

    private var currentLevel: Int = 0
    private var interstitialAd: InterstitialAd? = null
    private lateinit var nextLevelButton: Button
    private lateinit var levelTextView: TextView

    override fun onCreate(savedInstanceState: Bundle?) {

        // Create the next level button, which tries to show an interstitial when clicked.
        nextLevelButton = findViewById(
        nextLevelButton.isEnabled = false
        nextLevelButton.setOnClickListener { showInterstitial() }

        levelTextView = findViewById(
        // Create the text view to show the level number.
        currentLevel = START_LEVEL

        // Create the InterstitialAd and set the adUnitId (defined in values/strings.xml).
        interstitialAd = newInterstitialAd()

        // Toasts the test ad message on the screen. Remove this after defining your own ad unit ID.
        Toast.makeText(this, TOAST_TEXT, Toast.LENGTH_LONG).show()

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        // Inflate the menu; this adds items to the action bar if it is present.
        menuInflater.inflate(, menu)
        return true

    override fun onOptionsItemSelected(item: MenuItem) =
            when (item.itemId) {
       -> true
                else -> super.onOptionsItemSelected(item)

    private fun newInterstitialAd(): InterstitialAd {
        return InterstitialAd().apply {
            adUnitId = getString(R.string.interstitial_ad_unit_id)
            adListener = object : AdListener() {
                override fun onAdLoaded() {
                    nextLevelButton.isEnabled = true

                override fun onAdFailedToLoad(errorCode: Int) {
                    nextLevelButton.isEnabled = true

                override fun onAdClosed() {
                    // Proceed to the next level.

    private fun showInterstitial() {
        // Show the ad if it"s ready. Otherwise toast and reload the ad.
        if (interstitialAd?.isLoaded == true) {
        } else {
            Toast.makeText(this, "Ad did not load", Toast.LENGTH_SHORT).show()

    private fun loadInterstitial() {
        // Disable the next level button and load the ad.
        nextLevelButton.isEnabled = false
        val adRequest = AdRequest.Builder()

    private fun goToNextLevel() {
        // Show the next level and reload the ad to prepare for the level after.
        levelTextView.text = "Level " + (++currentLevel)
        interstitialAd = newInterstitialAd()

Here are the errors

...testapp\ad1PostButtonPush.kt: (62, 16): Cannot create an instance of an abstract class
...testapp\ad1PostButtonPush.kt: (63, 13): Val cannot be reassigned
...testapp\ad1PostButtonPush.kt: (64, 13): Unresolved reference: adListener
...testapp\ad1PostButtonPush.kt: (69, 17): 'onAdFailedToLoad' overrides nothing
...testapp\ad1PostButtonPush.kt: (83, 29): Unresolved reference: isLoaded
...testapp\ad1PostButtonPush.kt: (84, 34): No value passed for parameter 'p0'
...testapp\ad1PostButtonPush.kt: (97, 25): Unresolved reference: loadAd