invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.69k stars 2.21k forks source link

🔥 Interstitials only work once on debug but never on release #2157

Closed rochapablo closed 5 years ago

rochapablo commented 5 years ago

Issue

Interstitial shows up only once while running on debug mode (Android) and never shows up on release.

Banner class

import firebase from 'react-native-firebase';

export default class Interstitial {
  public advert: any; // firebase.admob().interstitial
  public onAdOpened: any;
  public onAdClosed: any;

  constructor(args: any) {
    this.onAdLoaded = this.onAdLoaded.bind(this);
    this.onAdFailedToLoad = this.onAdFailedToLoad.bind(this);
    this.onAdOpened = args.onAdOpened;
    this.onAdClosed = args.onAdClosed;
    this.mount();
  }

  public onAdLoaded() {
    // console.log('Advert ready to show.');
  }

  public onAdFailedToLoad(error: any) {
    console.log(error);
  }

  public render(): void {
    if (this.advert.isLoaded()) {
      this.advert.show();
      return;
    }
  }

  private mount() {
    // @ts-ignore
    this.advert = firebase.admob().interstitial('...');

    // @ts-ignore
    const request = new firebase.admob.AdRequest();
    this.advert.loadAd(request.build());

    // https://rnfirebase.io/docs/v5.x.x/admob/reference/Interstitial#on
    this.advert.on('onAdClosed', this.onAdClosed);
    this.advert.on('onAdFailedToLoad', this.onAdFailedToLoad);
    this.advert.on('onAdLoaded', this.onAdLoaded);
    this.advert.on('onAdOpened', this.onAdOpened);
  }
}

Calling the banner

const banner = new Interstitial({
    onAdClosed: () => {
        //
    },
    onAdOpened: () => {
        props.navigation.push('MyView');
    },
});

banner.render();

Project Files

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # N/A ``` #### `AppDelegate.m`: ```objc // N/A ```


Android

Click To Expand

#### `android/build.gradle`: ```groovy // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "28.0.3" minSdkVersion = 24 compileSdkVersion = 28 targetSdkVersion = 26 supportLibVersion = "28.0.0" } repositories { google() jcenter() maven { url 'https://maven.fabric.io/public' } maven { url 'https://plugins.gradle.org/m2/' } } dependencies { classpath 'com.android.tools.build:gradle:3.4.0' classpath 'io.fabric.tools:gradle:1.+' classpath 'com.google.gms:google-services:4.2.0' classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { mavenLocal() google() jcenter() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } // maven { url "http://nexus.hands.com.br/nexus/repository/maven-repository/" } } } wrapper { gradleVersion = '4.7' distributionUrl = distributionUrl.replace("bin", "all") } ``` #### `android/app/build.gradle`: ```groovy apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin' apply plugin: "com.android.application" import com.android.build.OutputFile /** * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets * and bundleReleaseJsAndAssets). * These basically call `react-native bundle` with the correct arguments during the Android build * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the * bundle directly from the development server. Below you can see all the possible configurations * and their defaults. If you decide to add a configuration block, make sure to add it before the * `apply from: "../../node_modules/react-native/react.gradle"` line. * * project.ext.react = [ * // the name of the generated asset file containing your JS bundle * bundleAssetName: "index.android.bundle", * * // the entry file for bundle generation * entryFile: "index.android.js", * * // whether to bundle JS and assets in debug mode * bundleInDebug: false, * * // whether to bundle JS and assets in release mode * bundleInRelease: true, * * // whether to bundle JS and assets in another build variant (if configured). * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants * // The configuration property can be in the following formats * // 'bundleIn${productFlavor}${buildType}' * // 'bundleIn${buildType}' * // bundleInFreeDebug: true, * // bundleInPaidRelease: true, * // bundleInBeta: true, * * // whether to disable dev mode in custom build variants (by default only disabled in release) * // for example: to disable dev mode in the staging build type (if configured) * devDisabledInStaging: true, * // The configuration property can be in the following formats * // 'devDisabledIn${productFlavor}${buildType}' * // 'devDisabledIn${buildType}' * * // the root of your project, i.e. where "package.json" lives * root: "../../", * * // where to put the JS bundle asset in debug mode * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", * * // where to put the JS bundle asset in release mode * jsBundleDirRelease: "$buildDir/intermediates/assets/release", * * // where to put drawable resources / React Native assets, e.g. the ones you use via * // require('./image.png')), in debug mode * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", * * // where to put drawable resources / React Native assets, e.g. the ones you use via * // require('./image.png')), in release mode * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", * * // by default the gradle tasks are skipped if none of the JS files or assets change; this means * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to * // date; if you have any other folders that you want to ignore for performance reasons (gradle * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ * // for example, you might want to remove it from here. * inputExcludes: ["android/**", "ios/**"], * * // override which node gets called and with what additional arguments * nodeExecutableAndArgs: ["node"], * * // supply additional arguments to the packager * extraPackagerArgs: [] * ] */ project.ext.react = [ entryFile: "index.js" ] // apply from: "../../node_modules/react-native/react.gradle" project.ext.envConfigFiles = [ debug: ".env", release: ".env.production" ] apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" apply plugin: 'io.fabric' repositories { maven { url 'https://maven.fabric.io/public' } } /** * Set this to true to create two separate APKs instead of one: * - An APK that only works on ARM devices * - An APK that only works on x86 devices * The advantage is the size of the APK is reduced by about 4MB. * Upload all the APKs to the Play Store and people will download * the correct one based on the CPU architecture of their device. */ def enableSeparateBuildPerCPUArchitecture = false /** * Run Proguard to shrink the Java bytecode in release builds. */ def enableProguardInReleaseBuilds = false android { compileSdkVersion rootProject.ext.compileSdkVersion defaultConfig { applicationId "com.myapp" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 49 versionName "0.1.49" // Enabling multidex support. multiDexEnabled true manifestPlaceholders = [ onesignal_app_id: '...', onesignal_google_project_number: 'REMOTE' ] } splits { abi { reset() enable enableSeparateBuildPerCPUArchitecture universalApk false // If true, also generate a universal APK include "armeabi-v7a", "x86", "arm64-v8a" } } buildTypes { release { minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } } // applicationVariants are e.g. debug, release applicationVariants.all { variant -> variant.outputs.each { output -> // For each separate APK per architecture, set a unique version code as described here: // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3] def abi = output.getFilter(OutputFile.ABI) if (abi != null) { // null for the universal-debug, universal-release variants output.versionCodeOverride = versionCodes.get(abi) * 1048576 + defaultConfig.versionCode } } } } dependencies { implementation project(':react-native-firebase') implementation project(':react-native-fabric') implementation project(':react-native-onesignal') implementation project(':react-native-reanimated') implementation project(':react-native-vector-icons') implementation project(':react-native-splash-screen') implementation project(':react-native-gesture-handler') implementation 'com.google.android.gms:play-services-base:16.1.0' implementation 'com.google.firebase:firebase-core:16.0.8' implementation 'com.google.firebase:firebase-ads:15.0.1' implementation project(':react-native-fast-image') implementation project(':react-native-config') implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" implementation "com.facebook.react:react-native:+" // From node_modules implementation('com.crashlytics.sdk.android:crashlytics:2.10.0@aar') { transitive = true; } // implementation "br.com.hands.mdm.libs.android:mdm-bundle:3.3.0" } // Run this once to be able to run the application with BUCK // puts all compile dependencies into folder libs for BUCK to use task copyDownloadableDepsToLibs(type: Copy) { from configurations.compile into 'libs' } apply plugin: 'com.google.gms.google-services' // The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[15.0.1,15.0.1]], but resolves to 16.0.1. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies. com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true ``` #### `android/settings.gradle`: ```groovy rootProject.name = 'myapp' include ':react-native-firebase' project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android') include ':react-native-fabric' project(':react-native-fabric').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fabric/android') include ':react-native-onesignal' project(':react-native-onesignal').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-onesignal/android') include ':react-native-reanimated' project(':react-native-reanimated').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-reanimated/android') include ':react-native-vector-icons' project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android') include ':react-native-splash-screen' project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android') include ':react-native-gesture-handler' project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android') include ':react-native-fast-image' project(':react-native-fast-image').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fast-image/android') include ':react-native-config' project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android') include ':app' ``` #### `MainApplication.java`: ```java public class MainApplication extends Application implements ReactApplication { private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; } @Override protected List getPackages() { return Arrays.asList( new MainReactPackage(), new RNFirebasePackage(), new RNFirebaseAdMobPackage(), new FabricPackage(), new ReactNativeOneSignalPackage(), new ReanimatedPackage(), new VectorIconsPackage(), new SplashScreenReactPackage(), new RNGestureHandlerPackage(), new FastImageViewPackage(), new ReactNativeConfigPackage() ); } @Override protected String getJSMainModuleName() { return "index"; } }; @Override public ReactNativeHost getReactNativeHost() { return mReactNativeHost; } @Override public void onCreate() { super.onCreate(); Fabric.with(this, new Crashlytics()); SoLoader.init(this, /* native exopackage */ false); } } ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` $ react-native info info React Native Environment Info: System: OS: macOS 10.14.4 CPU: (4) x64 Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz Memory: 1000.02 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.15.0 - /usr/local/bin/node Yarn: 1.15.2 - /usr/local/bin/yarn npm: 6.9.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2 IDEs: Android Studio: 3.4 AI-183.5429.30.34.5452501 Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild npmPackages: react: 16.8.6 => 16.8.6 react-native: ^0.59.8 => 0.59.8 npmGlobalPackages: react-native-cli: 2.0.1 react-native-create-library: 3.1.2 ``` - **Platform that you're experiencing the issue on**: - [ ] iOS - [x] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`Firebase` module(s) you're using that has the issue:** - `RNFirebaseAdMobPackage` - **Are you using `TypeScript`?** - `Y`

"react": "16.8.6",
"react-native": "^0.59.8",
"react-native-firebase": "^5.3.1",

https://github.com/invertase/react-native-firebase/issues/2013


Think react-native-firebase is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]

stale[bot] commented 5 years 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 the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

rochapablo commented 5 years ago

it still require the community's attention.

stale[bot] commented 5 years 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 the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

rochapablo commented 5 years ago

it still require the community's attention.

stale[bot] commented 5 years 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 the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

Ehesp commented 5 years ago

Can you try to use v6?

rochapablo commented 5 years ago

Yes, let me see here and I get back.

rochapablo commented 5 years ago

It seems that migration it's not work...

// Cannot find module '@react-native-firebase/admob'.ts(2307)
import { firebase } from '@react-native-firebase/admob';

I'm just following the doc: https://invertase.io/oss/react-native-firebase/v6/admob/reference

https://github.com/invertase/react-native-firebase/issues/2025#issuecomment-517911411

rochapablo commented 5 years ago

Oops, I forgot that it's separated libraries

npm i @react-native-firebase/admob --save

be right back...

rochapablo commented 5 years ago

@Ehesp, v6 it's just not working out for me.

After install and try to run what was already working, I'm getting

undefined is not a constructor (evaluating 'new _admob.default.AdRequest()')

I understand that this is from the v5, but I can't find nothing on documentation that exemplify the new way to create my banner.

This is what was working and should be migrate to v6

import admob from '@react-native-firebase/admob';
const AdMobBanner = admob.AdMobBanner;

const request = new admob.AdRequest();
request.setContentUrl(this.props.contentUrl);
return request.build();

<AdMobBanner...

but I can't figure it out how to migrate.

https://invertase.io/oss/react-native-firebase/v6/admob/reference/mobilead

stale[bot] commented 5 years 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 the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

Ehesp commented 5 years ago

The latest release now includes AdMob with a BannerAd. Please give it a try!