After updating Google Ads SDK to 19.0.0 gives a deprecated warning message for addTestDevice(), while I searched this link for resolving the issue but not succeed. how can I resolve it?

Here my code

mAdView.loadAd(new RequestConfiguration.Builder        .setTestDeviceIds(AdRequest.DEVICE_ID_EMULATOR) // show error        .setTestDeviceIds(DEV_ID) // show error        .build()); 

and developer site suggestion

Deprecated AdRequest.Builder.addTestDevice(). Use RequestConfiguration.Builder.setTestDeviceIds() instead.

Tag:google-ads-api, admob, android, google-play-services

11 comments.

  1. hata

    I did like this:

    List<String> testDevices = new ArrayList<>(); testDevices.add(AdRequest.DEVICE_ID_EMULATOR); RequestConfiguration requestConfiguration = new RequestConfiguration.Builder() .setTestDeviceIds(testDevices) .build(); MobileAds.setRequestConfiguration(requestConfiguration); AdView adView = new AdView(context); // ... invoke some methods of adView ... adView.loadAd(new AdRequest.Builder().build());

    The official reference says that a RequestConfiguration is the global configuration that will be used for every AdRequest. In my understanding, once you have setRequestConfiguration(), your AdRequests individually don't need to set test devices anymore.

    1. Attaullah

      is RequestConfiguration is required in every Activity?

    2. hata

      @Attaullah Yes, I think so. Because AdView's argument is Activity's Context. But I have no idea about the word 'Global' explicitly means either an Activity-wide or an Application-wide.

    3. TimWeb

      If I true understand the RequestConfiguration is required once in the first Activity.

    4. Armando Marques da S Sobrinho

      Notice that according the Developers Page: "Android emulators are automatically configured as test devices.""

    5. maniek099

      I used this configuration at MainActivity and all ads in different activties now have a black "Test Ad" box. So this configuration can be set only once.

  2. Mohamed Ben Romdhane

    If you use Android Emulators there is no need to setTestDeviceIds() method because emulators are automatically configured as test devices .

    But if you use a real devices or other emulators as a test device you must use it

    List<String> testDeviceIds = Arrays.asList("33BE2250B43518CCDA7DE426D04EE231"); RequestConfiguration configuration = new RequestConfiguration.Builder().setTestDeviceIds(testDeviceIds).build(); MobileAds.setRequestConfiguration(configuration);

    To get the Device ID Check the logcat output for a message that looks like the one below, which shows you your device ID and how to add it as a test device:

    I/Ads: Use RequestConfiguration.Builder.setTestDeviceIds(Arrays.asList("33BE2250B43518CCDA7DE426D04EE231")) to get test ads on this device."

    Source :

  3. Jim

    I do it like this in my MainActivity's onCreate function:

    val testDeviceIds = listOf("MY DEVICE ID") val config = RequestConfiguration.Builder().setTestDeviceIds(testDeviceIds).build() MobileAds.setRequestConfiguration(config) MobileAds.initialize(this)
    1. Billyjoker

      Do you know if ConsentInformation.getInstance(applicationContext).addTestDevice("xxx") do the same?

    2. android developer

      Is it possible to add the current device and that's it? Without putting a fixed string of it?

  4. Aashif Ahamed
    String testDeviceId = "xxx"; final RequestConfiguration.Builder requestConfigurationBuilder = new RequestConfiguration.Builder(); requestConfigurationBuilder.setTestDeviceIds(Collections.singletonList(testDeviceId)).build(); final RequestConfiguration requestConfiguration = requestConfigurationBuilder.build(); MobileAds.setRequestConfiguration(requestConfiguration); adLoader.loadAd(new AdRequest.Builder().build());

Add a new comment.