5

Error on iOS:

Cannot find 'kGADAdSizeBanner' in scope

Line:

private var adSize: GADAdSize = kGADAdSizeBanner

Package:

native_admob_flutter

Extra info:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.0, on macOS 11.6.2 20G314 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.62.0)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

• No issues found!

Android works. Official Flutter package for ads (google_mobile_ads) is totally dead so changing to that one is not an option anymore.

Dani
  • 3,128
  • 2
  • 43
  • 91
  • Some part of this answer would be helpful for you > https://github.com/flutter/flutter/issues/8098 – Nitin Vatsya Feb 08 '22 at 15:01
  • but it says "This issue is now specifically about Native Ads from Facebook and AdMob." – Dani Feb 09 '22 at 21:52
  • I just came across the exact issue, I forked the repo and did some minor migration so it can fit the latest Mobile Ads SDK (iOS). Hope it helps: https://github.com/nathan1658/native_admob_flutter – nathan1658 Mar 27 '22 at 16:29

2 Answers2

12

See docs , you just need to remove the 'k' at the beginning because they update it for the iOS SDK. From: kGADAdSizeBanner to GADAdSizeBanner.

Hen Shabat
  • 519
  • 1
  • 6
  • 19
2

Not sure if this will help but I faced this same issue. So I looked at the Banner-Ad size section from their documentation, and just made a custom GADAdsize var.

For example if you wanted a Large Banner(kGADAdSizeLargeBanner), then the documentation shows that the size in points (Width x Height) is 320x100.

Size for whatever reason we can't access the variable kGADAdSizeLargeBanner (or kGADAdSizeBanner in your case) we can just create our own.

let adSize = GADAdSizeFromCGSize(CGSize(width: 320, height: 100))

Then using this adSize variable we can initialize a banner view.

let bannerView: GADBannerView = GADBannerView(adSize: adSize)

More detailed info about GADAdSizeFromCGSize can be found at this link.

  • for my case I use that package that should covers already that implementation. I don't create the banner, like that, only call the method to import them – Dani Feb 08 '22 at 22:17