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.

šŸ› testDeviceId's are not working

See original GitHub issue

testDeviceIdā€™s are not working

Description I was trying to set my test device id with the requestConfiguration. For checking whether setup for testdevice is successful, I filtered logcat in android studio with setTestDeviceIds but itā€™s showing me the following log

2021-03-31 04:17:36.907 27185-27185/? I/Ads: Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("xxxxxxxxxxxxxxxxxxx")) to get test ads on this device.

So setting up for test device are not working and I canā€™t test with real ads. As Iā€™m passing testDeviceIdā€™s this log was supposed to not appear. You can see Iā€™m passing testDeviceIdā€™s for both in RequestConfiguration and bannerAd.

Steps to reproduce

Here is my main.dart file

import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:provider/provider.dart';
import 'package:us/global/theme/app_themes.dart';
import 'package:us/utils/ad_helper.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  MobileAds.instance.initialize().then((InitializationStatus status) {
    print('Initialization done: ${status.adapterStatuses}');
    MobileAds.instance
        .updateRequestConfiguration(RequestConfiguration(
        testDeviceIds: AdHelper.allTestDevices));
  });


  runApp(
      MyApp()
  );
}


class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider<ThemeChanger>(
      create: (_) => ThemeChanger(),
      child: new MaterialAppWithTheme(),
    );
  }
}

class MaterialAppWithTheme extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final theme = Provider.of<ThemeChanger>(context);

    return MaterialApp(
      title: 'Const',
      debugShowCheckedModeBanner: false,
      theme: theme.getDarkTheme ? ThemeData.dark():ThemeData.light(),
      home: HomeScreen(),
    );
  }
}

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {

  static final AdRequest request = AdRequest(
    testDevices: AdHelper.allTestDevices,
  );

  BannerAd _bannerAdd;
  bool _isBannerAdLoaded = false;

  Future<InitializationStatus> _initGoogleMobileAds() {
    // TODO: Initialize Google Mobile Ads SDK
    return MobileAds.instance.initialize();
  }

  @override
  void initState() {
    super.initState();


    _bannerAdd = BannerAd(
      adUnitId: AdHelper.homePageBannerAd,
      size: AdSize.banner,
      request: request,
      listener: AdListener(
        onAdLoaded: (_) {  // Future<SharedPrefData> _setDarkMode(bool darkMode) async{
          //   SharedPreferences prefs = await SharedPreferences.getInstance();
          //   log.i('Current dark mode  $darkMode.');
          //   await prefs.setBool('darkmode', darkMode);
          //   log.i('Dark mode toggled successfully');
          //   return await getPersistedData();
          // }
          setState(() {
            _isBannerAdLoaded = true;
          });
        },
        onAdFailedToLoad: (ad, error) {
          // Releases an ad resource when it fails to load
          ad.dispose();

          print('Ad load failed (code=${error.code} message=${error.message})');
        },
      ),
    );

    _bannerAdd.load();

  }
  

  @override
  Widget build(BuildContext context) {

    //this gonna give us total height and with of our device
    return Scaffold(
      // bottomNavigationBar: BottomNavBar(),
      body: Stack(
        children: <Widget>[
          SafeArea(
            child: Padding(
              padding: const EdgeInsets.symmetric(horizontal: 20),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  this._isBannerAdLoaded? Container(
                    margin: EdgeInsets.only(bottom: 35),
                    height: 72.0,
                    alignment: Alignment.center,
                    child: AdWidget(ad: _bannerAdd),
                  ):Text('')
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}



Here is my adhelper.dart file

import 'dart:io';

class AdHelper{

  static String TEST_BANNER_AD = "ca-app-pub-3940256099942544/6300978111";

 static String get homePageBannerAd{
   if(Platform.isAndroid){
     return TEST_BANNER_AD;
   }
   else if(Platform.isIOS){
     return TEST_BANNER_AD;
   }
   else
     throw new UnsupportedError("Platform is not supported..");
 }

 static List<String> get allTestDevices{

       String MY_REDMI_NOTE_9="xxxxxxxxxxx";


   return [MY_REDMI_NOTE_9];
  }

}

Expected behavior

It shouldnā€™t show me this log as Iā€™m setting testDeviceIdā€™s

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, 2.0.1, on Linux, locale en_US.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    āœ— Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.
[āœ“] Chrome - develop for the web
[āœ“] Android Studio (version 3.5)
[āœ“] IntelliJ IDEA Ultimate Edition (version 2020.2)
[āœ“] VS Code (version 1.54.3)
[āœ“] Connected device (2 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.12.0
Flutter SDK 2.0.1
us_constitution 1.0.0+1

dependencies:
- dynamic_text_highlighting 2.2.0 [flutter]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_svg 0.19.3 [flutter meta path_drawing vector_math xml]
- flutter_xlider 3.4.0 [flutter]
- google_mobile_ads 0.11.0+4 [meta flutter]
- logger 1.0.0
- path_provider 2.0.1 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- provider 5.0.0 [collection flutter nested]
- shared_preferences 2.0.5 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows]
- sqflite 1.3.2+4 [flutter sqflite_common path]
- url_launcher 6.0.3 [flutter url_launcher_platform_interface url_launcher_linux url_launcher_macos url_launcher_windows url_launcher_web]

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:
- async 2.5.0 [collection]
- boolean_selector 2.1.0 [source_span string_scanner]
- characters 1.1.0
- charcode 1.2.0
- clock 1.1.0
- collection 1.15.0
- convert 2.1.1 [charcode typed_data]
- fake_async 1.2.0 [clock collection]
- ffi 1.0.0
- file 6.1.0 [meta path]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- js 0.6.3
- matcher 0.12.10 [stack_trace]
- meta 1.3.0
- nested 1.0.0 [flutter]
- path 1.8.0
- path_drawing 0.4.1+1 [vector_math meta path_parsing flutter]
- path_parsing 0.1.4 [vector_math meta]
- path_provider_linux 2.0.0 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_macos 2.0.0 [flutter]
- path_provider_platform_interface 2.0.0 [flutter meta platform plugin_platform_interface]
- path_provider_windows 2.0.0 [path_provider_platform_interface meta path flutter ffi win32]
- petitparser 3.1.0 [meta]
- platform 3.0.0
- plugin_platform_interface 1.0.3 [meta]
- process 4.1.0 [file path platform]
- shared_preferences_linux 2.0.0 [flutter file meta path path_provider_linux shared_preferences_platform_interface]
- shared_preferences_macos 2.0.0 [shared_preferences_platform_interface flutter]
- shared_preferences_platform_interface 2.0.0 [flutter]
- shared_preferences_web 2.0.0 [shared_preferences_platform_interface flutter flutter_web_plugins meta]
- shared_preferences_windows 2.0.0 [shared_preferences_platform_interface flutter file meta path path_provider_platform_interface path_provider_windows]
- sky_engine 0.0.99
- source_span 1.8.0 [charcode collection path term_glyph]
- sqflite_common 1.0.3+1 [synchronized path meta]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- string_scanner 1.1.0 [charcode source_span]
- synchronized 2.2.0+2
- term_glyph 1.2.0
- test_api 0.2.19 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.0 [collection]
- url_launcher_linux 2.0.0 [flutter]
- url_launcher_macos 2.0.0 [flutter]
- url_launcher_platform_interface 2.0.1 [flutter plugin_platform_interface]
- url_launcher_web 2.0.0 [url_launcher_platform_interface meta flutter flutter_web_plugins]
- url_launcher_windows 2.0.0 [flutter]
- vector_math 2.1.0
- win32 2.0.0 [ffi]
- xdg_directories 0.2.0 [meta path process]
- xml 4.5.1 [collection convert meta petitparser]


Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
akinshocommented, Apr 6, 2021

@ShahrearBinAmin I reversed the order of the request and that seemed to have worked i.e. I called updateRequestConfiguration before initialisation and that seems to have worked. Granted it doesnā€™t seem particularly intuitive that way.

0reactions
timothyhoang-googlecommented, Sep 9, 2021

@ShahrearBinAmin, does the solution @jjliu15 mentioned above resolve your issue? If not, could you respond by the end of next week 09/17/21? Otherwise, weā€™ll close this issue. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get device ID for Admob - Stack Overflow
Open any app on your device which shows live ads from Admob: On the connected device, if you have your app downloaded from...
Read more >
Test ads not showing in emulator when using Test Unit IDs
I am able to see test ads in debug mode on the emulator on lower and higher versions of Android. Hope you guys...
Read more >
[firebase_admob] Missing steps in the doc leads to Test ...
While trying to set AdMob along with my own AdUnits, I realized the device IDs are not printed to the console as the...
Read more >
Set up a test device - Google AdMob Help
Click Settings in the sidebar. Ā· Click the Test devices tab. Ā· Click Add test device. Ā· Enter a device name. Ā· Select...
Read more >
When trying test ads , getting onAdFailedToLoad with error ...
Sadly, recently it stopped working, and keeps giving me this error 3 - " No ad config". This happens even if I set...
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