AdRequest isTestDevice returning false in release build on Android 8

Viewed 666

I'm working on an app that's using admob to display ads. I have added test id's for 3 devices ( 1 running android 6 and 2 running android 8) and they work fine in debug mode being correctly identified as test devices.

AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
// My Phone 
adRequestBuilder.addTestDevice("AD9EA3690D287AA4A5A75279684045A1");
//Phone2 and 3
adRequestBuilder.addTestDevice("8438F5ABA7A67FAC92A26AAED589C8F1");
adRequestBuilder.addTestDevice("ED0430F25A6DA673BF0AA414AFDD7688");
// emulator
adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
AdRequest adRequest = adRequestBuilder.build();
// get whether it's a test device to enable developer functionality.
isTest = adRequest.isTestDevice(this);

Note: codes changed for this post

But in a release build the 2 android 8 phones are returning false in the call to adRequest.isTestDevice(this);. The android 6 phone works perfectly.

How do I overcome this bug in android 8?

1 Answers

I worked it out pretty quickly with a little debugging but I waited to see if anyone would post the reason.

Turns out it's a deliberate change (like most bugs in android these days). The test device code is an md5 hash of Settings.Secure.ANDROID_ID which on android 8 varies per user and per app. https://developer.android.com/about/versions/oreo/android-8.0-changes See the privacy section

Because Debug and Release builds are separate apps they get separate android_id's.

It makes testing admob on release builds very risky.

Hopefully one day they'll update the AdRequest code to compensate for this.

Related