invertase / react-native-google-mobile-ads

React Native Google Mobile Ads enables you to monetize your app with AdMob.
https://docs.page/invertase/react-native-google-mobile-ads
Other
625 stars 121 forks source link

[🐛] Internal error googleMobileAds #562

Closed aedoardo closed 1 month ago

aedoardo commented 2 months ago

What happened?

Hi everyone, I'm trying to figure out the issue that I'm facing, and I hope someone can help me because I'm getting crazy :)

So, first of all, I have my app in the "ready" status in AdMob.

I initialize the mobileAds in the main app file (App.tsx in my case):

mobileAds().initialize().then(adapterStatuses => {
      console.log(adapterStatuses);
});

In this case, the console.log produces this output: [{"description": "", "name": "com.google.android.gms.ads.MobileAds", "state": 1}]. I guess it's okay.

Now, I'm trying to run just a simple Interstitial in this way:

const ad = InterstitialAd.createForAdRequest(TestIds.INTERSTITIAL);
ad.load();
ad.addAdEventsListener(({ type, payload }) => {
    console.log('Ad event: ', type, payload);
});

Just a note: I pasted the ad with the test id in this example, but I'm facing the same problem with a valid unit id. However, when I run this code I have this error: Ad event: error [Error: [googleMobileAds/internal-error] Internal error.], without any other information. Trying to understand further details, I checked the adb logcat, and I can see two logs related to the ad:

04-01 20:35:23.408 11767 11958 I Ads     : This request is sent from a test device.
..... unrelated logs
04-01 20:35:23.481 11767 11767 I Ads     : Ad failed to load : 0
04-01 20:35:23.510 11767 11846 I ReactNativeJS: 'Ad event: ', 'error', [Error: [googleMobileAds/internal-error] Internal error.]

From here, I have no idea what the problem might be.

Sometimes, in the logs, I have also these two logs:

04-01 21:02:08.966 14245 14514 W Ads     : Invoke Firebase method getInstance error.
04-01 21:02:08.967 14245 14514 W Ads     : The Google Mobile Ads SDK will not integrate with Firebase. Admob/Firebase integration requires the latest Firebase SDK jar, but Firebase SDK is either missing or out of date
04-01 21:02:09.007 14245 14245 I Ads     : Ad failed to load : 0

I want to add another information: I tested even on my smartphone, but it happens the same thing: the ad doesn't load, and I can't show it (it produces an error since it wasn't loaded). However, the logs are from a "Pixel 3 XL API R Android 11.0 (Google APIs)" emulator.

I am hoping someone can give me some suggestions; I thank you in advance :)

Platforms

Android, but have not tested behavior on iOS

React Native Info

/

Are your using Typescript?

package.json

{
  "name": "AppName",
  "version": "1.0.2",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@react-native-async-storage/async-storage": "^1.23.1",
    "@react-native-community/cli-platform-android": "^13.6.3",
    "@react-native-community/netinfo": "^11.3.1",
    "@react-native-firebase/app": "^19.1.1",
    "@react-native-firebase/crashlytics": "^19.1.1",
    "@react-navigation/bottom-tabs": "^6.5.20",
    "@react-navigation/native": "^6.1.17",
    "@react-navigation/native-stack": "^6.9.26",
    "lottie-react-native": "^6.7.0",
    "react": "18.2.0",
    "react-native": "0.73.6",
    "react-native-animatable": "^1.4.0",
    "react-native-animateable-text": "^0.11.1",
    "react-native-device-info": "^10.13.1",
    "react-native-gesture-handler": "^2.16.0",
    "react-native-google-mobile-ads": "^13.1.0",
    "react-native-gradle-plugin": "^0.71.19",
    "react-native-prompt-android": "^1.1.0",
    "react-native-reanimated": "^3.8.1",
    "react-native-safe-area-context": "^4.9.0",
    "react-native-screens": "^3.29.0",
    "react-native-svg": "^15.1.0",
    "react-native-vector-icons": "^10.0.3",
    "react-native-walkthrough-tooltip": "^1.6.0",
    "rn-tourguide": "^3.3.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.73.21",
    "@react-native/eslint-config": "0.73.2",
    "@react-native/metro-config": "0.73.5",
    "@react-native/typescript-config": "0.73.1",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "obfuscator-io-metro-plugin": "^2.1.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  }
}

app.json

{
  "name": "AppName",
  "displayName": "AppName",
  "react-native-google-mobile-ads": {
    "android_app_id": "my-app-pub-id",
    "ios_app_id": ""
  }
}

ios/Podfile

No response

android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 21
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "25.1.8937393"
        kotlinVersion = "1.8.0"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
        classpath("com.google.gms:google-services:4.4.1")
        classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.9")
    }
}

apply plugin: "com.facebook.react.rootproject"

android/app/build.gradle

apply plugin: "com.android.application"
apply plugin: "com.google.gms.google-services" // apply after this line
apply plugin: "com.google.firebase.crashlytics"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"

react {

}

def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+'

android {
    ndkVersion rootProject.ext.ndkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    compileSdk rootProject.ext.compileSdkVersion

    namespace "com.appname"
    defaultConfig {
        applicationId "com.appname"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 3
        versionName "1.0.2"
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            // signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
}

dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")
    implementation("com.facebook.react:flipper-integration")
    //implementation("com.google.android.gms:play-services-ads:22.6.0")
    //implementation(platform("com.google.firebase:firebase-bom:32.8.0"))

    // Add the dependencies for the Crashlytics and Analytics libraries
    // When using the BoM, you don't specify versions in Firebase library dependencies
    //implementation("com.google.firebase:firebase-crashlytics")
    //implementation("com.google.firebase:firebase-analytics")

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle")

android/settings.gradle

rootProject.name = 'AppName'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')

AndroidManifest.xml

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE"/>
     <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
    </application>
</manifest>
aedoardo commented 2 months ago

Just an update: today it seems to work on a physical device. I didn't change anything.

aedoardo commented 2 months ago

Just another update: it is working on physical devices, but it is not working (neither with the TestIds) in the emulator, even if I added the device's adsid in the admob settings.

github-actions[bot] commented 1 month ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.