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
698 stars 142 forks source link

[🐛] BannerAd is not showing from version 11.3.0 #427

Closed las-nhith closed 1 year ago

las-nhith commented 1 year ago

What happened?

Google BannerAd is not showing from version 11.3.0. Everything work perfect when I use version below 11.3.0

Platforms

iOS, but have not tested behavior on Android

React Native Info

System:
  OS: macOS 13.5
  CPU: (8) arm64 Apple M1 Pro
  Memory: 85.66 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.12.1
    path: ~/.asdf/installs/nodejs/18.12.1/bin/node
  Yarn:
    version: 3.4.1
    path: ~/.asdf/installs/nodejs/18.12.1/bin/yarn
  npm:
    version: 8.19.2
    path: ~/.asdf/plugins/nodejs/shims/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.12.1
    path: /Users/username/.asdf/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK:
    API Levels:
      - "28"
      - "29"
      - "30"
      - "31"
      - "32"
      - "33"
    Build Tools:
      - 28.0.3
      - 29.0.2
      - 29.0.3
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 32.0.0
      - 33.0.0
    System Images:
      - android-28 | Google ARM64-V8a Play ARM 64 v8a
      - android-29 | Google APIs ARM 64 v8a
      - android-30 | Google APIs ARM 64 v8a
      - android-30 | Google Play ARM 64 v8a
      - android-31 | Android TV ARM 64 v8a
      - android-31 | Google Play ARM 64 v8a
      - android-32 | Google APIs ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2022.2 AI-222.4459.24.2221.10121639
  Xcode:
    version: 14.3.1/14E300c
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.15
    path: /Users/username/.asdf/shims/javac
  Ruby:
    version: 2.7.5
    path: /Users/username/.asdf/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.3
    wanted: 0.72.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: false
  newArchEnabled: false

Are your using Typescript?

package.json

{
  "name": "ads",
  "version": "0.0.1",
  "private": true,
  "main": "src/ads/index.tsx",
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest",
    "postinstall": "react-native setup-ios-permissions"
  },
  "dependencies": {
    "@notifee/react-native": "^7.8.0",
    "@react-native-async-storage/async-storage": "^1.19.0",
    "@react-native-community/netinfo": "^9.4.1",
    "@react-navigation/native": "^6.1.7",
    "@react-navigation/native-stack": "^6.9.13",
    "axios": "^1.4.0",
    "react": "18.2.0",
    "react-native": "0.72.3",
    "react-native-admob-native-ads": "^0.6.6",
    "react-native-applovin-max": "^5.5.3",
    "react-native-device-info": "^10.8.0",
    "react-native-get-random-values": "^1.9.0",
    "react-native-google-mobile-ads": "11.3.0",
    "react-native-permissions": "^3.8.4",
    "react-native-safe-area-context": "^4.7.1",
    "react-native-screens": "^3.22.1",
    "react-native-vector-icons": "^9.2.0",
    "swr": "^2.2.0",
    "uuid": "^9.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/eslint-config": "^0.72.2",
    "@react-native/metro-config": "^0.72.9",
    "@tsconfig/react-native": "^3.0.0",
    "@types/react": "^18.0.24",
    "@types/react-native-vector-icons": "^6.4.13",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.76.7",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  },
  "reactNativePermissionsIOS": [
    "AppTrackingTransparency"
  ],
  "engines": {
    "node": ">=16"
  }
}

app.json

{
  "name": "ads",
  "displayName": "ads",
  "react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-3940256099942544~1458002511",
    "ios_app_id": "ca-app-pub-3940256099942544~1458002511",
    "user_tracking_usage_description": "This identifier will be used to deliver personalized ads to you."
  }
}

ios/Podfile

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!

# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
# To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
# 
# module.exports = {
#   dependencies: {
#     ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# 
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'ads' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    # Hermes is now enabled by default. Disable by setting this flag to false.
    :hermes_enabled => false,
    :fabric_enabled => flags[:fabric_enabled],
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    :flipper_configuration => flipper_config,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  pod 'AppLovinSDK'
  pod 'AppLovinMediationAdColonyAdapter'
  pod 'AppLovinMediationGoogleAdapter'
  pod 'AppLovinMediationIronSourceAdapter'
  pod 'AppLovinMediationVungleAdapter'
  pod 'AppLovinMediationUnityAdsAdapter'

  target 'adsTests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

android/build.gradle

No response

android/app/build.gradle

No response

android/settings.gradle

No response

AndroidManifest.xml

No response

dylancom commented 1 year ago

Working fine in our example app, please compare. (also while using rn 0.72.3)

Scherm­afbeelding 2023-08-05 om 09 43 44

npx react-native run-ios --simulator="iPhone 14 Pro"

saravanakumargn commented 1 year ago

@dylancom are you using Expo? banner ad not working in both ios and Android. my version is

    "react-native-google-mobile-ads": "^11.6.4",
    "react-native": "0.72.3",
    "expo": "~49.0.6",

If i pass requestOptions it's working.

Working

return (
    <BannerAd unitId={TestIds.BANNER}
      size={BannerAdSize.ANCHORED_ADAPTIVE_BANNER}
      requestOptions={{
        // requestNonPersonalizedAdsOnly: true,
      }}
    />
  )

not Working

return (
    <BannerAd unitId={TestIds.BANNER}
      size={BannerAdSize.ANCHORED_ADAPTIVE_BANNER}
    />
  )
dylancom commented 1 year ago

@saravanakumargn great catch, indeed not rendering when requestOptions isn't provided.

mikehardy commented 1 year ago

:tada: This issue has been resolved in version 11.6.5 :tada:

The release is available on:

Your semantic-release bot :package::rocket: