Closed large closed 1 month ago
Hi @large, I'm able to load anchored adaptive banner ads in landscape mode
It's recommended to use final size = await AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize( MediaQuery.sizeOf(context).width.truncate());
to determine the ad size.
Hi @large, I'm able to load anchored adaptive banner ads in landscape mode It's recommended to use
final size = await AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize( MediaQuery.sizeOf(context).width.truncate());
to determine the ad size.
Thank you for the feedback! Quite strange, I have probably used the example to test "widescreen" for Android here, my bad. I had added this into the styles.xml
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
That makes the example fail
Full styles.xml file is like this
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
My production app uses the same setup too, so to get this running I had todo this little modification of the example: https://github.com/googleads/googleads-mobile-flutter/blob/9f989d3ea76b0da9300b4cf9e1926a134edbba4c/samples/admob/banner_example/lib/main.dart#L140-L142 To this:
final scaffoldPadding = MediaQuery.of(context).padding;
// Get an AnchoredAdaptiveBannerAdSize before loading the ad.
final size = await AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
MediaQuery.sizeOf(context).width.truncate() - scaffoldPadding.horizontal.toInt());
I will let this case stay open until someone who owns the package has an opinion if this is a bug or by design.
Is it possible for you replicate this in our Android BannerExample? (e.g. try adding <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
to our sample) If so, that would help confirm if it's working as intended
@malandr2 that is what I did in my description above. I can zip & upload my version if you like?
Hi @large,
All previous references are pointing to the Flutter banner example - I'm asking if the problem can be replicated when isolated to the Android Banner Example in https://github.com/googleads/googleads-mobile-android-examples/tree/main/kotlin/admob/BannerExample/app/src/main/java/com/google/android/gms/example/bannerexample)
@malandr2 I just tested the Android BannerExample on my emulator, without any source code change (mint from repo):
It do show a banner in portrait mode (but it is clipped).
In Landscape it did not load anything and just spit out a "Ad failed to load: 1"
Now with the shortEdges enabled it still throws "Ad failed to load: 1"
I am really bad in java, so I could not get this implemented to get a good text on what is wrong. But this example seems neglected. Works better in Flutter ;)
Hi @large, it's determined this is an Android issue, not something the flutter plugin can control. Please create a new thread in the AdMob Developers Forum for it to be properly triaged. You can include this link in your new thread.
Closing this out. Thanks!
Plugin Version
5.1.0
Steps to Reproduce
Use the banner example: https://github.com/googleads/googleads-mobile-flutter/tree/main/samples/admob/banner_example Compile it for Android emulator and rotate to horizontal.
Screensize setup is like this: Screen width is 891.4 Screen height is 387.4
Trying to load BannerAd() in horizontal mode using adaptive banner size:
Expected results: Ad was loaded using the maximum screen width of 891.
Please note that if you compile and test with an iOS emulator, this works perfectly. This error is only related to Android devices.
Actual results: _Error building request URL: Ad size will not fit on screen. a_w=891, a_h=58, s_w=851, sh=388 Meaning that the GoogleAds screen width was set to 851, where did the last 40 pixels go? Screen height was not truncated but rounded up from 387.4 to 388, another bug on height?
PS: I am running this code on a production app. And it works 100% on iOS so this is only on Android it seems to fail.
Logs
``` I/Ads ( 7900): Ad failed to load : 1 I/flutter ( 7900): BannerAd failedToLoad: LoadAdError(code: 1, domain: com.google.android.gms.ads, message: Error building request URL: Ad size will not fit on screen. a_w=891, a_h=58, s_w=851, s_h=388, responseInfo: ResponseInfo(responseId: null, mediationAdapterClassName: , adapterResponses: [], loadedAdapterResponseInfo: null), responseExtras: {}) ``` ``` Analyzing example... No issues found! (ran in 0.4s) ``` ``` [✓] Flutter (Channel stable, 3.22.3, on macOS 14.5 23F79 darwin-arm64 (Rosetta), locale en-NO) • Flutter version 3.22.3 on channel stable at /Users/large/development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision b0850beeb2 (9 days ago), 2024-07-16 21:43:41 -0700 • Engine revision 235db911ba • Dart version 3.4.4 • DevTools version 2.34.3 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/large/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.4) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15F31d • CocoaPods version 1.13.0 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2024.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314) [✓] Connected device (5 available) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 14 (API 34) (emulator) • iPhone 15 Pro Max (mobile) • A82C2902-7F6A-4187-B717-5A29044BA3F3 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.5 23F79 darwin-arm64 (Rosetta) • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.5 23F79 darwin-arm64 (Rosetta) • Chrome (web) • chrome • web-javascript • Google Chrome 126.0.6478.183 [✓] Network resources • All expected network resources are available. • No issues found! ```