6

I am using AdMob banner ads in multi-process. It is working fine on API version lower than 29 but on android-P, it is giving this error.

 com.google.android.gms.ads.internal.webview.s: Webview initialization failed.
    at com.google.android.gms.ads.internal.webview.o.a(:com.google.android.gms.policy_ads_fdr_dynamite@6000@6000.204543870.204543870:5)
    at com.google.android.gms.ads.internal.i.a(:com.google.android.gms.policy_ads_fdr_dynamite@6000@6000.204543870.204543870:6)
    at com.google.android.gms.ads.internal.y.a(:com.google.android.gms.policy_ads_fdr_dynamite@6000@6000.204543870.204543870:4)
    at com.google.android.gms.ads.internal.l.run(:com.google.android.gms.policy_ads_fdr_dynamite@6000@6000.204543870.204543870:11)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at com.google.android.gms.ads.internal.util.f.dispatchMessage(:com.google.android.gms.policy_ads_fdr_dynamite@6000@6000.204543870.204543870:1)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. https://crbug.com/558377

I have initialized MobileAds in application class. i also tried to initialize in other process in which i am using ads but no luck.

Mateen Chaudhry
  • 631
  • 12
  • 32

2 Answers2

7

Notice this line in your error: " Caused by: java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported."

It means your app is using 2 or more processes and you need to set a different WebView directory for each process (the main process already have the default folder), as explained in my question and answer here.

On Android 9.0 API 28, call WebView.setDataDirectorySuffix("any-folder-name") when the second process is running, before you use any WebView.

Lior Iluz
  • 26,213
  • 16
  • 65
  • 114
  • 3
    This is insanity on steroids... They should have done a better job providing a proper trouble shooting - ie. write something about setDataDirectorySuffix in the log output. If you upgrade and do not test the part of you app with a web view you might never know until it is too late... – slott May 11 '19 at 08:07
  • 1
    And what if you see this bug, but you didn't start any new processes? Where you should put this suffix method? Btw, bug appears mostly on a Samsung devices. – Johnny Five Apr 07 '20 at 11:46
0

in case when you deals with ads, in application class

try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            val process = getProcessName()
            if (packageName != process) WebView.setDataDirectorySuffix(process)
        }

        MobileAds.initialize(this)
        AudienceNetworkAds.initialize(this)

    } catch (e: Error) {
        Timber.e(e)
    } catch (e: Exception) {
        Timber.e(e)
    }
Abdur Rehman
  • 1,247
  • 10
  • 13