Admob横幅广告未加载到Android P中

时间:2018-09-03 06:39:02

标签: android admob google-admob android-9.0-pie

我正在多进程中使用AdMob横幅广告。在低于29的API版本上运行正常,但在android-P上却出现此错误。

 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

我已经在应用程序类中初始化了MobileAds。我还尝试在其他使用广告但没有运气的过程中进行初始化。

2 个答案:

答案 0 :(得分:6)

在您的错误中注意以下行: “ combine<A|B>([isA, isB])

这意味着您的应用程序正在使用2个或更多进程,并且您需要为每个进程设置一个不同的combine目录(主进程已经具有默认文件夹),如我的question and answer here所述。

在Android 9.0 API 28上,在第二个进程运行时调用Caused by: java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported.,然后再使用任何WebView

答案 1 :(得分:0)

如果您要处理广告,请在应用程序类中

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)
    }