StrictMode: Tried to access the API:ViewConfiguration which needs to have proper configuration from a non-UI Context

2,768 views
Skip to first unread message

Oleksii

unread,
Jan 9, 2022, 3:53:38 PM1/9/22
to Google Mobile Ads SDK Developers
Android AdMob version: 20.5.0
Device: Pixel 3a, Android 12

When the StrictMode is enabled with "detectAll" option, I can see the following error messages in logcat when running an Activity with banner.

MobileAds.initialize() is called with application context.

Is there any workaround to resolve this problem?

E/StrictMode: Tried to access the API:ViewConfiguration which needs to have proper configuration from a non-UI Context:com.google.android.gms.ads.internal.webview.aw@ba964b6 The API:ViewConfiguration needs a proper configuration. Use UI contexts such as an activity or a context created via createWindowContext(Display, int, Bundle) or  createConfigurationContext(Configuration) with a proper configuration.
    java.lang.IllegalAccessException: Tried to access the API:ViewConfiguration which needs to have proper configuration from a non-UI Context:com.google.android.gms.ads.internal.webview.aw@ba964b6
        at android.os.StrictMode.assertConfigurationContext(StrictMode.java:2296)
        at android.view.ViewConfiguration.get(ViewConfiguration.java:522)
        at android.view.View.<init>(View.java:5307)
        at android.view.View.<init>(View.java:5452)
        at android.view.ViewGroup.<init>(ViewGroup.java:702)
        at android.view.ViewGroup.<init>(ViewGroup.java:698)
        at android.view.ViewGroup.<init>(ViewGroup.java:694)
        at android.view.ViewGroup.<init>(ViewGroup.java:690)
        at android.widget.FrameLayout.<init>(FrameLayout.java:85)
        at com.google.android.gms.ads.internal.webview.y.<init>(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:1)
        at com.google.android.gms.ads.internal.webview.s.a(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:3)
        at com.google.android.gms.ads.internal.webview.v.a(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:4)
        at com.google.android.gms.ads.nonagon.ad.webview.l.b(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:2)
        at com.google.android.gms.ads.nonagon.render.y.a(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:2)
        at boj.e(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:2)
        at bol.run(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:9)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at auj.a(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:0)
        at com.google.android.gms.ads.internal.util.f.a(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:1)
        at auj.dispatchMessage(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:0)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7842)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/StrictMode: Tried to access the API:ViewConfiguration which needs to have proper configuration from a non-UI Context:com.google.android.gms.ads.internal.webview.aw@ba964b6 The API:ViewConfiguration needs a proper configuration. Use UI contexts such as an activity or a context created via createWindowContext(Display, int, Bundle) or  createConfigurationContext(Configuration) with a proper configuration.
    java.lang.IllegalAccessException: Tried to access the API:ViewConfiguration which needs to have proper configuration from a non-UI Context:com.google.android.gms.ads.internal.webview.aw@ba964b6
        at android.os.StrictMode.assertConfigurationContext(StrictMode.java:2296)
        at android.view.ViewConfiguration.get(ViewConfiguration.java:522)
        at android.view.View.<init>(View.java:5307)
        at android.view.View.<init>(View.java:5452)
        at android.widget.TextView.<init>(TextView.java:1032)
        at android.widget.TextView.<init>(TextView.java:1026)
        at android.widget.TextView.<init>(TextView.java:1022)
        at android.widget.TextView.<init>(TextView.java:1018)
        at com.google.android.gms.ads.internal.webview.y.ac(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:1)
        at com.google.android.gms.ads.nonagon.render.z.run(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:0)
        at com.google.android.gms.ads.internal.util.future.c.execute(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:2)
        at com.google.android.gms.ads.internal.util.future.d.execute(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:0)
        at boh.q(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:1)
        at boh.k(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:8)
        at boh.n(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:0)
        at bqn.n(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:0)
        at com.google.android.gms.ads.internal.util.future.j.e(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:0)
        at com.google.android.gms.ads.nonagon.ad.webview.i.a(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:2)
        at com.google.android.gms.ads.internal.webview.q.d(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:4)
        at com.google.android.gms.ads.internal.webview.q.onPageFinished(:com.google.android.gms.policy_ads_fdr_dynamite@214106404@214106404057.409717972.409717972:11)
        at pC0.b(Unknown Source:10)
        at K9.handleMessage(Unknown Source:280)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7842)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

Mobile Ads SDK Forum Advisor

unread,
Jan 11, 2022, 1:16:27 AM1/11/22
to shom...@gmail.com, google-adm...@googlegroups.com

Hi Oleksii,

Thank you for reaching out to us.

Before we can provide any workaround on this, can you provide us with the following details via Reply privately to author option or send it directly to mobileads...@gmail.com? Kindly inform us on this thread if you sent it directly to the email provided.

  • Sample app project
  • Steps to replicate

Regards,

Google Logo
Princess Pamela Pineda
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2UiCsi:ref

Mobile Ads SDK Forum Advisor

unread,
Jan 17, 2022, 2:36:51 AM1/17/22
to shom...@gmail.com, google-adm...@googlegroups.com
Hi Oleksii,

I work along with Princess. Thank you for providing the requested information privately.

I tried your sample app, and I wasn't able to reproduce the issue on my end (please see attached screenshot). I tested this using Google Pixel 3 API 30 emulator. That said, could you kindly confirm what is the details of the device you were using? Also, is the behavior occurs on emulator or using an actual device?

Regards,
Google Logo
Teejay Wennie Pimentel
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2UiCsi:ref
Screen Shot 2022-01-17 at 3.34.38 PM.png

Oleksii

unread,
Jan 17, 2022, 4:19:36 AM1/17/22
to Google Mobile Ads SDK Developers
This issue is reproducible only on real devices with Android 12 (Pixel 3a and Pixel 3a XL in my case).

Mobile Ads SDK Forum Advisor

unread,
Jan 17, 2022, 8:43:15 AM1/17/22
to shom...@gmail.com, google-adm...@googlegroups.com

Hi Oleksii,

Thank you for your response.

Let me bring this to the rest of the team to further check your concern. Rest assured that one of our team will reach out to you.

Regards,

Google Logo
Princess Pamela Pineda
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2UiCsi:ref

Mobile Ads SDK Forum Advisor

unread,
Feb 14, 2022, 1:40:41 PM2/14/22
to google-adm...@googlegroups.com, shom...@gmail.com
Hello Oleksii,

Thanks for reaching out.

To help with our investigation, would you please also provide a complete stack trace that includes all the threads?

We have been investigating the issue and will let you know once there is an update.


Regards,
Joshua

ref:_00D1U1174p._5004Q2UiCsi:ref

Oleksii

unread,
Feb 14, 2022, 4:23:31 PM2/14/22
to Google Mobile Ads SDK Developers
Can you suggest how to do this?

Oleksii

unread,
Feb 14, 2022, 5:29:03 PM2/14/22
to Google Mobile Ads SDK Developers
So, I've added the following code into my project:

StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
    .detectAll()
    .penaltyLog()
    .penaltyListener(executor, v -> dumpAllThreads("VM policy violation", v))
    .build());

...

private void dumpAllThreads(String title, Violation v) {
    PrintStream ps = MainActivity.ps;
    if (ps == null) {
        return;
    }

    ps.println("--------------------------------");
    ps.println(title);
    ps.print("Timestamp: ");
    ps.println(System.currentTimeMillis());
    v.printStackTrace(ps);
    ps.println("Dump all threads");

    for (Map.Entry<Thread, StackTraceElement[]> e : Thread.getAllStackTraces().entrySet()) {
        ps.println(e.getKey());

        if (e.getValue().length > 0) {
            for (StackTraceElement ste : e.getValue()) {
                ps.print('\t');
                ps.println(ste);
            }
        } else {
            ps.println("\t[no stack trace]");
        }
    }

    ps.println("================================");
    ps.flush();
}


Check out the results in attachment.

On Monday, February 14, 2022 at 8:40:41 PM UTC+2 mobileadssdk wrote:
all_stack_traces.zip

Mobile Ads SDK Forum Advisor

unread,
Feb 28, 2022, 1:29:46 PM2/28/22
to shom...@gmail.com, google-adm...@googlegroups.com
Hello Oleksii,

Thanks for attaching the stack trace.

We are currently looking into it and will get back to you shortly with an update.

Mobile Ads SDK Forum Advisor

unread,
Jul 1, 2022, 2:22:30 PM7/1/22
to shom...@gmail.com, google-adm...@googlegroups.com
Hello Oleksii,

Are you encountering any issue during initialization or ad loading when `MobileAds.initialize()` is called with application context?

I would assume the usage of application context is working as expected in this case. However, StrictMode still logs the violation despite the exemption, but the log is not blocking.

Oleksii

unread,
Jul 1, 2022, 3:48:40 PM7/1/22
to Google Mobile Ads SDK Developers
Hello,

I use application context during MobieAds.initialize().

Did you have chance to test the demo project I've sent previously?

Regards,
Oleksii

Mobile Ads SDK Forum Advisor

unread,
Jul 6, 2022, 2:57:41 AM7/6/22
to shom...@gmail.com, google-adm...@googlegroups.com
Hello Oleksii,

As mentioned in the previous email, passing application context to `MobileAds.initialize()` should work as expected. Please let me know if you are encountering any issue with that.

In this case StrictMode still logs the violation despite the exemption, but the log is not blocking.

If you pass in an activity (see our developer documentation) to `MobileAds.initialize()`, I would expect StrictMode won't log the violation anymore.
Reply all
Reply to author
Forward
0 new messages