Admob banner ad not loading in android P

前端 未结 2 1399
南笙
南笙 2021-01-01 01:12

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.         


        
相关标签:
2条回答
  • 2021-01-01 01:51

    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)
        }
    
    0 讨论(0)
  • 2021-01-01 02:08

    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.

    0 讨论(0)
提交回复
热议问题