react-native-admob: Interstitial AD Broken at AdMob Update SDK 20

Not build npx react-native run-android .

image

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 9
  • Comments: 33

Commits related to this issue

Most upvoted comments

If you need to work around this problem, you can change the following row in the build.gradle file of the react-native-admob project implementation 'com.google.android.gms:play-services-ads:+' to implementation 'com.google.android.gms:play-services-ads:19.6.0'.

The changes the the SDK were made in version 19.7.0 and finalized in 20.0.0. This is not a long-term fix, though.

Same issue.

If you need to work around this problem, you can change the following row in the build.gradle file of this project implementation 'com.google.android.gms:play-services-ads:+' to implementation 'com.google.android.gms:play-services-ads:19.6.0'. The changes the the SDK were made in version 19.7.0 and finalized in 20.0.0. This is not a long-term fix, though.

This row wasn’t included in my project. Although I added, nothing has changed

node_modules/react-native-admob/android/build.gradle

line 25

If you need to work around this problem, you can change the following row in the build.gradle file of this project implementation 'com.google.android.gms:play-services-ads:+' to implementation 'com.google.android.gms:play-services-ads:19.6.0'. The changes the the SDK were made in version 19.7.0 and finalized in 20.0.0. This is not a long-term fix, though.

This row wasn’t included in my project. Although I added, nothing has changed

node_modules/react-native-admob/android/build.gradle

line 25

I was looking project’s own build.gradle file. Thanks 😃

This is currently an issue i’m facing and have lost a lot of hours to it.

node_modules/react-native-admob/android/src/main/java/com/sbugert/rnadmob/RNAdMobInterstitialAdModule.java:20: error: cannot find symbol
import com.google.android.gms.ads.InterstitialAd;

  symbol:   class InterstitialAd
  location: package com.google.android.gms.ads

Android Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxxx">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:usesCleartextTraffic="true"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:windowSoftInputMode="stateVisible|adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
      <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID"
          android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    </application>

</manifest>

build.gradle (app) dependencies

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    // implementation project(':react-native-navigation')
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules

    implementation project(':react-native-splash-screen')

    implementation 'com.android.support:multidex:1.0.3'

    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.fbjni'
    }
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }
    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

    implementation "com.android.support:design:${rootProject.ext.supportLibVersion}"
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

build.gradle (project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "29.0.2"
        minSdkVersion = 23
        compileSdkVersion = 29
        targetSdkVersion = 29
        kotlinVersion = "1.3.72"
        RNNKotlinVersion = kotlinVersion
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        mavenLocal()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
        classpath 'com.android.tools.build:gradle:3.5.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        maven { url 'https://jitpack.io' }

    }
}

subprojects { subproject ->
    afterEvaluate {
        if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
            android {
                variantFilter { variant ->
                    def names = variant.flavors*.name
                    if (names.contains("reactNative51") ||
                            names.contains("reactNative55") ||
                            names.contains("reactNative56") ||
                            names.contains("reactNative57") ||
                            names.contains("reactNative57_5") ||
                            names.contains("reactNative60")
                    ) {
                        setIgnore(true)
                    }
                }
            }
        }
    }
}

I followed the instructions to add it to my project. It builds in iOS but won’t build in Android. PLEASE HELP!

It was working on my first try but it doesn’t work anymore (“I applied my solution”) Adsız

If you need to do the workaround patch manually more than a couple of times, you might want to look into automating it with patch-package or creating your own fork. See: https://github.com/ds300/patch-package

I would not expect a permanent fix, as the library does not seem to be actively maintained anymore. Full migration to the v20 SDK seems to be a decent amount of work too. See: https://developers.google.com/admob/android/migration So if you do not want to take that route, you will probably need to look for alternative libraries.

If you need to work around this problem, you can change the following row in the build.gradle file of this project implementation 'com.google.android.gms:play-services-ads:+' to implementation 'com.google.android.gms:play-services-ads:19.6.0'.

The changes the the SDK were made in version 19.7.0 and finalized in 20.0.0. This is not a long-term fix, though.

This row wasn’t included in my project. Although I added, nothing has changed

That error is because maybe the admob account is not ready yet and it doesn’t have ads right now. I recommend you move this convo to the other package’ repo (@react-native-admob/admob) or to an specific forum to avoid spamming this thread.

Ese error es porque a lo mejor la cuenta de admob aun no está lista y no tiene anuncios por ahora. Te recomiendo mover esta conversación al otro repo del package (@react-native-admob/admob) o a un foro específico para evitar spamear este hilo

Saludos 👋

I started to work on new package https://www.npmjs.com/package/@react-native-admob/admob because this package seems to not maintained any more. My package supports new SDK and also support interstitial and rewarded with react hook.

@fernandoVicentei I just switched to this package, maybe you should try it.

I started to work on new package https://www.npmjs.com/package/@react-native-admob/admob because this package seems to not maintained any more. My package supports new SDK and also support interstitial and rewarded with react hook.

I needed to do some extra steps:

  1. Install the library
  2. Opennode_modules/react-native-admob/android/build.gradle
  3. Update the line 25 by adding implementation 'com.google.android.gms:play-services-ads:19.6.0'
  4. patch your changes: npx patch-package react-native-admob
  5. In your project folder, open android/app/build.gradle
  6. Add this to defaultConfig block:
defaultConfig {
    multiDexEnabled true
    ... //other configs
}

now you can run your app. Don’t forget to use a test id in the asUnitID prop like this ca-app-pub-3940256099942544/6300978111 ✌️

If you need to work around this problem, you can change the following row in the build.gradle file of this project implementation 'com.google.android.gms:play-services-ads:+' to implementation 'com.google.android.gms:play-services-ads:19.6.0'. The changes the the SDK were made in version 19.7.0 and finalized in 20.0.0. This is not a long-term fix, though.

I confirm this did break react-native library this temporary fix solved it.Thanks!

It works for me with Rn version 0.63.4 but with version 0.64 my app does not open on my device, does anyone know why?