question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

🐛 Native Ads randomly failing to load on hot restart or running the app

See original GitHub issue

Bug report

Describe the bug Every time I hot restart or run my app some native ads randomly fail to load for some reason.

Errors:

I/Ads     (18470): Received log message: <Google:HTML> Incorrect native ad response. Click actions 
were not properly specified
I/Ads     (18470): Ad failed to load : 0
I/flutter (18470): NativeAd failedToLoad: LoadAdError(code: 0, domain: com.google.android.gms.ads, 
message: Internal error.)
W/ImageReader_JNI(18470): Unable to acquire a buffer item, very likely client tried to acquire more than maxImages buffers
I/flutter (18470): NativeAd failedToLoad: LoadAdError(code: 0, domain: com.google.android.gms.ads, message: Internal error.)
I/yl.app(18470): NativeAlloc concurrent copying GC freed 15902(1395KB) AllocSpace objects, 24(2152KB) LOS objects, 49% free, 5374KB/10MB, paused 1.580ms total 477.969ms
W/ImageReader_JNI(18470): Unable to acquire a buffer item, very likely client tried to acquire more than maxImages buffers

Steps to reproduce

Steps to reproduce the behavior:

  1. Create a column full of some native ads
  2. Run your flutter app
  3. See error or incorrect behavior

Expected behavior

All native ads load properly.

Additional Context

I am using multiple native ads in a column.

Code:

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';

class NativeAdWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => NativeAdState();
}

class NativeAdState extends State<NativeAdWidget> {
  NativeAd _nativeAd;
  final Completer<NativeAd> nativeAdCompleter = Completer<NativeAd>();

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    _nativeAd = NativeAd(
      adUnitId: myAdId,
      request: AdRequest(),
      factoryId: 'listTile',
      listener: AdListener(
        onAdLoaded: (Ad ad) {
          print('$NativeAd loaded.');
          nativeAdCompleter.complete(ad as NativeAd);
        },
        onAdFailedToLoad: (Ad ad, LoadAdError error) {
          print('$NativeAd failedToLoad: $error');
          _nativeAd?.dispose();
          _nativeAd = null;
          nativeAdCompleter.completeError(null);
        },
        onAdOpened: (Ad ad) => print('$NativeAd onAdOpened.'),
        onAdClosed: (Ad ad) => print('$NativeAd onAdClosed.'),
        onApplicationExit: (Ad ad) => print('$NativeAd onApplicationExit.'),
      ),
    );
    Future<void>.delayed(Duration(seconds: 1), () => _nativeAd?.load());
  }

  @override
  void dispose() {
    super.dispose();
    _nativeAd?.dispose();
    _nativeAd = null;
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder<NativeAd>(
      future: nativeAdCompleter.future,
      builder: (BuildContext context, AsyncSnapshot<NativeAd> snapshot) {
        Widget child;

        switch (snapshot.connectionState) {
          case ConnectionState.none:
          case ConnectionState.waiting:
          case ConnectionState.active:
            child = Container();
            break;
          case ConnectionState.done:
            if (snapshot.hasData) {
              child = AdWidget(ad: _nativeAd);
            } else {
              child = Text('Error loading $NativeAd');
            }
        }

        return Padding(
          padding: const EdgeInsets.only(bottom: 5.0),
          child: Container(
            height: 80,
            child: child,
            color: Color(0xff23272A),
          ),
        );
      },
    );
  }
}

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.19042.867], locale en-US)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[!] Android Studio (version 4.1.0)
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
[√] VS Code (version 1.54.3)
[√] Connected device (1 available)

! Doctor found issues in 1 category.

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand
Dart SDK 2.10.5
Flutter SDK 1.22.6
discord_bots 2.2.0

dependencies:
- cached_network_image 2.5.0 [flutter flutter_cache_manager octo_image]
- cupertino_icons 1.0.0
- custom_navigator 0.2.0 [flutter]
- data_connection_checker 0.3.4
- easy_localization 3.0.0-dev.1 [flutter intl shared_preferences args path flutter_localizations]
- easy_localization_loader 0.0.2 [http csv yaml xml flutter]
- emoji_flag_converter 1.0.0 [flutter]
- firebase_analytics 7.0.1 [meta flutter firebase_core firebase_analytics_web firebase_analytics_platform_interface]
- firebase_core 0.7.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- firebase_crashlytics 0.4.0+1 [flutter stack_trace firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_form_builder 4.2.0 [flutter flutter_localizations date_range_picker datetime_picker_formfield dropdown_search flutter_colorpicker flutter_chips_input flutter_datetime_picker flutter_touch_spin flutter_typeahead intl rating_bar signature validators]
- flutter_localizations 0.0.0 [flutter intl characters collection meta path typed_data vector_math]
- flutter_markdown 0.5.2 [flutter markdown meta path]
- flutter_phoenix 0.1.0 [flutter]
- flutter_secure_storage 3.3.5 [meta flutter]
- google_fonts 1.1.2 [flutter http path_provider crypto]
- google_mobile_ads 0.11.0+4 [meta flutter]
- in_app_purchase 0.3.5+1 [async collection flutter json_annotation meta]
- provider 4.3.3 [collection flutter nested]
- rate_my_app 0.7.2 [shared_preferences smooth_star_rating pedantic flutter]
- sentry_flutter 4.0.6 [flutter flutter_web_plugins sentry package_info]
- shared_preferences 0.5.12+4 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows]    
- shimmer 1.1.2 [flutter]
- url_launcher 5.7.10 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos url_launcher_windows]
- visa 1.0.3 [flutter hexcolor http webview_flutter]

dev dependencies:
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]

transitive dependencies:
- archive 2.0.13 [crypto args path]
- args 1.6.0
- async 2.5.0-nullsafety.1 [collection]
- basic_utils 2.7.1 [http logging json_annotation pointycastle convert crypto]
- boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner]
- characters 1.1.0-nullsafety.3
- charcode 1.2.0-nullsafety.1
- clock 1.1.0-nullsafety.1
- collection 1.15.0-nullsafety.3
- convert 2.1.1 [charcode typed_data]
- crypto 2.1.5 [collection convert typed_data]
- csv 4.1.0
- date_range_picker 1.0.6 [flutter]
- datetime_picker_formfield 1.0.0 [flutter intl]
- dropdown_search 0.4.9 [flutter]
- fake_async 1.2.0-nullsafety.1 [clock collection]
- ffi 0.1.3
- file 5.2.1 [intl meta path]
- firebase 7.3.3 [http http_parser js]
- firebase_analytics_platform_interface 1.0.3 [flutter meta]
- firebase_analytics_web 0.1.1 [flutter flutter_web_plugins firebase firebase_analytics_platform_interface meta]
- firebase_core_platform_interface 3.0.1 [flutter meta plugin_platform_interface quiver]
- firebase_core_web 0.2.1+3 [firebase_core_platform_interface flutter flutter_web_plugins meta js]
- firebase_crashlytics_platform_interface 1.1.6 [flutter meta collection firebase_core plugin_platform_interface]
- flutter_blurhash 0.5.0 [flutter meta]
- flutter_cache_manager 2.1.1 [flutter path_provider uuid http path sqflite pedantic clock file rxdart image]
- flutter_chips_input 1.9.5 [flutter]
- flutter_colorpicker 0.3.5 [flutter]
- flutter_datetime_picker 1.5.0 [flutter]
- flutter_keyboard_visibility 4.0.4 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_web flutter]
- flutter_keyboard_visibility_platform_interface 1.0.1 [flutter meta plugin_platform_interface]
- flutter_keyboard_visibility_web 1.0.1 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter]
- flutter_touch_spin 1.0.1 [flutter intl]
- flutter_typeahead 1.9.3 [flutter flutter_keyboard_visibility]
- flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math]
- hexcolor 1.0.6 [flutter flutter_web_plugins]
- http 0.12.2 [http_parser path pedantic]
- http_parser 3.1.4 [charcode collection source_span string_scanner typed_data]
- image 2.1.19 [archive xml meta]
- intl 0.16.1 [path]
- js 0.6.2
- json_annotation 3.1.1
- logging 0.11.4
- markdown 3.0.0 [args charcode meta]
- matcher 0.12.10-nullsafety.1 [stack_trace]
- meta 1.3.0-nullsafety.3
- nested 0.0.4 [flutter]
- octo_image 0.3.0 [flutter flutter_blurhash]
- package_info 0.4.3+4 [flutter]
- path 1.8.0-nullsafety.1
- path_provider 1.6.27 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_macos 0.0.4+8 [flutter]
- path_provider_platform_interface 1.0.4 [flutter meta platform plugin_platform_interface]
- path_provider_windows 0.0.4+3 [path_provider_platform_interface meta path flutter ffi win32]
- pedantic 1.9.2 [meta]
- petitparser 3.1.0 [meta]
- platform 2.2.1
- plugin_platform_interface 1.0.3 [meta]
- pointycastle 2.0.1
- process 3.0.13 [file intl meta path platform]
- quiver 2.1.5 [matcher meta]
- random_string 2.1.0
- rating_bar 0.2.0 [flutter]
- rxdart 0.25.0
- sentry 4.0.6 [http meta stack_trace uuid]
- shared_preferences_linux 0.0.2+4 [file flutter meta path path_provider_linux shared_preferences_platform_interface]
- shared_preferences_macos 0.0.1+11 [shared_preferences_platform_interface flutter]
- shared_preferences_platform_interface 1.0.4 [meta flutter]
- shared_preferences_web 0.1.2+7 [shared_preferences_platform_interface flutter flutter_web_plugins meta]
- shared_preferences_windows 0.0.2+3 [shared_preferences_platform_interface flutter file meta path path_provider_platform_interface path_provider_windows]
- signature 3.2.1 [flutter image]
- sky_engine 0.0.99
- smooth_star_rating 1.1.1 [flutter]
- source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph]
- sqflite 1.3.2+3 [flutter sqflite_common path]
- sqflite_common 1.0.3+1 [synchronized path meta]
- stack_trace 1.10.0-nullsafety.1 [path]
- stream_channel 2.1.0-nullsafety.1 [async]
- string_scanner 1.1.0-nullsafety.1 [charcode source_span]
- synchronized 2.2.0+2
- term_glyph 1.2.0-nullsafety.1
- test_api 0.2.19-nullsafety.2 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.0-nullsafety.3 [collection]
- url_launcher_linux 0.0.1+4 [flutter]
- url_launcher_macos 0.0.1+9 [flutter]
- url_launcher_platform_interface 1.0.9 [flutter meta plugin_platform_interface]
- url_launcher_web 0.1.5+3 [url_launcher_platform_interface flutter flutter_web_plugins meta]
- url_launcher_windows 0.0.1+3 [flutter]
- uuid 2.2.2 [crypto convert]
- validators 2.0.1 [vin_decoder]
- vector_math 2.1.0-nullsafety.3
- vin_decoder 0.1.3 [meta basic_utils http random_string]
- webview_flutter 1.0.7 [flutter]
- win32 1.7.4+1 [ffi]
- xdg_directories 0.1.2 [meta path process]
- xml 4.5.1 [collection convert meta petitparser]
- yaml 2.2.1 [charcode collection string_scanner source_span]

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Tetracylcommented, Mar 29, 2021

I’ve only tried it on an emulator. I’ll try it on a real device soon and get back to you.

0reactions
maheshmnjcommented, Sep 20, 2021

Labeled this issue as fixed considering this is no longer reproducible.

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to load Native ad: 0 Error - Stack Overflow
But when I replace with my id its not showing ad and execute onAdFailedToLoad method and got Failed to load native ad: 0...
Read more >
Why do my apps keep crashing on Android, How to fix it
To restart the device, press and hold the power button. Now tap on restart. Some phones may not have the restart option, in...
Read more >
Common reasons for ads not showing - Google AdMob Help
Use the following guide to understand common reasons why apps show few or no ads. If you're still having issues, use the Can't...
Read more >
Common Flutter errors
Introduction. This page explains several frequently-encountered Flutter framework errors and gives suggestions on how to resolve them.
Read more >
Known issues with Android Studio and Android Gradle Plugin
This issue is a sticky problem that continues to happen even if you stop and restart the debugger. To fix this problem, delete...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found