googleads / googleads-mobile-flutter

A Flutter plugin for the Google Mobile Ads SDK
Apache License 2.0
336 stars 276 forks source link

Ad size behavior when <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item> is set #1145

Closed large closed 1 month ago

large commented 1 month ago

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: image Screen width is 891.4 Screen height is 387.4

Trying to load BannerAd() in horizontal mode using adaptive banner size:

AnchoredAdaptiveBannerAdSize? size;
size = await anchoredAdaptiveBannerAdSize(context);
//Or
//  size = await AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
//        MediaQuery.sizeOf(context).width.truncate());

BannerAd(
          adUnitId: testAd,
          request: AdRequest(nonPersonalizedAds: true),
          size: size!,
//Etc (...)

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! ```
malandr2 commented 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.

Screenshot_1722006972

large commented 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.

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 image

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());

image

I will let this case stay open until someone who owns the package has an opinion if this is a bug or by design.

malandr2 commented 1 month ago

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

large commented 1 month ago

@malandr2 that is what I did in my description above. I can zip & upload my version if you like?

malandr2 commented 1 month ago

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)

large commented 1 month ago

@malandr2 I just tested the Android BannerExample on my emulator, without any source code change (mint from repo): image

It do show a banner in portrait mode (but it is clipped). image

Logcat for portrait > 2024-07-31 13:09:50.191 24125-24125 WindowOnBackDispatcher com...oid.gms.example.bannerexample W sendCancelIfRunning: isInProgress=falsecallback=android.view.ViewRootImpl$$ExternalSyntheticLambda17@82c0afb > 2024-07-31 13:09:50.320 24125-24125 MyActivity com...oid.gms.example.bannerexample D Google Mobile Ads SDK Version: 23.2.0 > 2024-07-31 13:09:50.335 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IDFA_freqCapNumViews > 2024-07-31 13:09:50.347 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IABTCF_idfaFlowControl > 2024-07-31 13:09:50.486 24125-24151 OpenGLRenderer com...oid.gms.example.bannerexample E Unable to match the desired swap behavior. > 2024-07-31 13:09:50.508 24125-24135 e.bannerexample com...oid.gms.example.bannerexample I Background young concurrent copying GC freed 102293(4136KB) AllocSpace objects, 18(7392KB) LOS objects, 42% free, 14MB/25MB, paused 9.794ms,32us total 197.445ms > 2024-07-31 13:09:50.578 24125-24170 DynamitePackage com...oid.gms.example.bannerexample D Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl > 2024-07-31 13:09:50.593 24125-24170 Ads com...oid.gms.example.bannerexample I This request is sent from a test device. > 2024-07-31 13:09:50.773 24125-24170 DynamitePackage com...oid.gms.example.bannerexample D Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl > 2024-07-31 13:09:50.812 24125-24170 Ads com...oid.gms.example.bannerexample I This request is sent from a test device. > 2024-07-31 13:09:50.880 24125-24918 ConnectionStatusConfig com...oid.gms.example.bannerexample W Dynamic lookup for intent failed for action: com.google.android.gms.ads.service.START > 2024-07-31 13:09:50.958 24125-24910 Ads com...oid.gms.example.bannerexample W Not retrying to fetch app settings > 2024-07-31 13:09:51.066 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Action[write]: {"IABTCF_gdprApplies":1} > 2024-07-31 13:09:51.066 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Writing to storage: [IABTCF_gdprApplies] 1 > 2024-07-31 13:09:51.254 24125-24125 UserMessagingPlatform com...oid.gms.example.bannerexample D Receive consent action: consent://consent/?action=start_transparency_status_updates > 2024-07-31 13:09:51.255 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Action[start_transparency_status_updates]: {} > 2024-07-31 13:09:51.258 24125-24125 UserMessagingPlatform com...oid.gms.example.bannerexample D Receive consent action: consent://consent/?action=configure_app_assets > 2024-07-31 13:09:51.260 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Action[configure_app_assets]: {} > 2024-07-31 13:09:51.301 24125-24125 UserMessagingPlatform com...oid.gms.example.bannerexample D Wall html loaded. > 2024-07-31 13:09:51.306 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IDFA_freqCapNumViews > 2024-07-31 13:09:51.326 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IABTCF_idfaFlowControl > 2024-07-31 13:09:51.327 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IDFA_freqCapNumViews > 2024-07-31 13:09:51.327 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IABTCF_idfaFlowControl > 2024-07-31 13:09:51.327 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IDFA_freqCapNumViews > 2024-07-31 13:09:51.327 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IABTCF_idfaFlowControl > 2024-07-31 13:09:51.340 24125-24125 UserMessagingPlatform com...oid.gms.example.bannerexample D Receive consent action: consent://consent/?action=load_complete&args=%7B%22status%22%3A%22ok%22%7D > 2024-07-31 13:09:51.341 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Action[load_complete]: {"status":"ok"} > 2024-07-31 13:09:51.604 24125-24125 DynamiteModule com...oid.gms.example.bannerexample I Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:241806202 > 2024-07-31 13:09:51.604 24125-24125 DynamiteModule com...oid.gms.example.bannerexample I Selected remote version of com.google.android.gms.ads.dynamite, version >= 241806202 > 2024-07-31 13:09:51.677 24125-24125 DynamiteModule com...oid.gms.example.bannerexample I Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:241806202 > 2024-07-31 13:09:51.677 24125-24125 DynamiteModule com...oid.gms.example.bannerexample I Selected remote version of com.google.android.gms.ads.dynamite, version >= 241806202

In Landscape it did not load anything and just spit out a "Ad failed to load: 1"

image

Logcat for Landscape > 2024-07-31 13:10:19.909 24125-24125 WindowOnBackDispatcher com...oid.gms.example.bannerexample W sendCancelIfRunning: isInProgress=falsecallback=android.view.ViewRootImpl$$ExternalSyntheticLambda17@45b25ad > 2024-07-31 13:10:20.042 24125-24125 MyActivity com...oid.gms.example.bannerexample D Google Mobile Ads SDK Version: 23.2.0 > 2024-07-31 13:10:20.043 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IDFA_freqCapNumViews > 2024-07-31 13:10:20.045 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IABTCF_idfaFlowControl > 2024-07-31 13:10:20.113 24125-24151 OpenGLRenderer com...oid.gms.example.bannerexample E Unable to match the desired swap behavior. > 2024-07-31 13:10:20.138 24125-24170 DynamitePackage com...oid.gms.example.bannerexample D Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl > 2024-07-31 13:10:20.142 24125-24170 Ads com...oid.gms.example.bannerexample I This request is sent from a test device. > 2024-07-31 13:10:20.324 24125-24170 DynamitePackage com...oid.gms.example.bannerexample D Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl > 2024-07-31 13:10:20.383 24125-24170 Ads com...oid.gms.example.bannerexample I This request is sent from a test device. > 2024-07-31 13:10:20.508 24125-24911 Ads com...oid.gms.example.bannerexample W Not retrying to fetch app settings > 2024-07-31 13:10:20.541 24125-24981 ConnectionStatusConfig com...oid.gms.example.bannerexample W Dynamic lookup for intent failed for action: com.google.android.gms.ads.service.START > 2024-07-31 13:10:20.683 24125-24125 Ads com...oid.gms.example.bannerexample I Ad failed to load : 1 > 2024-07-31 13:10:20.697 24125-24125 Ads com...oid.gms.example.bannerexample I Ad failed to load : 1 > 2024-07-31 13:10:20.758 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Action[write]: {"IABTCF_gdprApplies":1} > 2024-07-31 13:10:20.758 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Writing to storage: [IABTCF_gdprApplies] 1 > 2024-07-31 13:10:20.893 24125-24125 UserMessagingPlatform com...oid.gms.example.bannerexample D Receive consent action: consent://consent/?action=start_transparency_status_updates > 2024-07-31 13:10:20.894 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Action[start_transparency_status_updates]: {} > 2024-07-31 13:10:20.896 24125-24125 UserMessagingPlatform com...oid.gms.example.bannerexample D Receive consent action: consent://consent/?action=configure_app_assets > 2024-07-31 13:10:20.897 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Action[configure_app_assets]: {} > 2024-07-31 13:10:20.906 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IDFA_freqCapNumViews > 2024-07-31 13:10:20.906 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IABTCF_idfaFlowControl > 2024-07-31 13:10:20.906 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IDFA_freqCapNumViews > 2024-07-31 13:10:20.907 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IABTCF_idfaFlowControl > 2024-07-31 13:10:20.907 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IDFA_freqCapNumViews > 2024-07-31 13:10:20.907 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Stored info not exists: IABTCF_idfaFlowControl > 2024-07-31 13:10:20.926 24125-24125 UserMessagingPlatform com...oid.gms.example.bannerexample D Wall html loaded. > 2024-07-31 13:10:20.936 24125-24125 UserMessagingPlatform com...oid.gms.example.bannerexample D Receive consent action: consent://consent/?action=load_complete&args=%7B%22status%22%3A%22ok%22%7D > 2024-07-31 13:10:20.938 24125-24902 UserMessagingPlatform com...oid.gms.example.bannerexample D Action[load_complete]: {"status":"ok"} > 2024-07-31 13:11:20.689 24125-24125 Ads com...oid.gms.example.bannerexample I This request is sent from a test device. > 2024-07-31 13:11:20.731 24125-24125 ConnectionStatusConfig com...oid.gms.example.bannerexample W Dynamic lookup for intent failed for action: com.google.android.gms.ads.service.CACHE > 2024-07-31 13:11:20.759 24125-25038 ConnectionStatusConfig com...oid.gms.example.bannerexample W Dynamic lookup for intent failed for action: com.google.android.gms.ads.service.START > 2024-07-31 13:11:20.805 24125-24125 Ads com...oid.gms.example.bannerexample I Ad failed to load : 1 > 2024-07-31 13:12:20.810 24125-24125 Ads com...oid.gms.example.bannerexample I This request is sent from a test device. > 2024-07-31 13:12:20.907 24125-24125 ConnectionStatusConfig com...oid.gms.example.bannerexample W Dynamic lookup for intent failed for action: com.google.android.gms.ads.service.CACHE > 2024-07-31 13:12:20.930 24125-25081 ConnectionStatusConfig com...oid.gms.example.bannerexample W Dynamic lookup for intent failed for action: com.google.android.gms.ads.service.START > 2024-07-31 13:12:20.994 24125-24125 Ads com...oid.gms.example.bannerexample I Ad failed to load : 1 > 2024-07-31 13:13:21.016 24125-24125 Ads com...oid.gms.example.bannerexample I This request is sent from a test device. > 2024-07-31 13:13:21.057 24125-24125 ConnectionStatusConfig com...oid.gms.example.bannerexample W Dynamic lookup for intent failed for action: com.google.android.gms.ads.service.CACHE > 2024-07-31 13:13:21.075 24125-25127 ConnectionStatusConfig com...oid.gms.example.bannerexample W Dynamic lookup for intent failed for action: com.google.android.gms.ads.service.START > 2024-07-31 13:13:21.135 24125-24125 Ads com...oid.gms.example.bannerexample I Ad failed to load : 1 > 2024-07-31 13:14:21.138 24125-24125 Ads com...oid.gms.example.bannerexample I This request is sent from a test device. > 2024-07-31 13:14:21.183 24125-24125 ConnectionStatusConfig com...oid.gms.example.bannerexample W Dynamic lookup for intent failed for action: com.google.android.gms.ads.service.CACHE > 2024-07-31 13:14:21.210 24125-25171 ConnectionStatusConfig com...oid.gms.example.bannerexample W Dynamic lookup for intent failed for action: com.google.android.gms.ads.service.START > 2024-07-31 13:14:21.271 24125-24125 Ads com...oid.gms.example.bannerexample I Ad failed to load : 1

Now with the shortEdges enabled it still throws "Ad failed to load: 1" image

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 ;)

malandr2 commented 1 month ago

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!