Reputation: 371
1.When I in Fragment onCreateView method inflater.inflate(webview_layout, container, false) on Android 9 may Crash with blow log:
Fatal Exception: java.lang.RuntimeException:Using WebView from more than one process at once with the same data directory is not supported. https://crbug.com/558377 at jO.b(PG:102) at jQ.run(PG:3) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:226) at android.app.ActivityThread.main(ActivityThread.java:7210) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:499) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:961)
2.I try add blow code in Application onCreate method
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
String processName = getProcessName();
if (!MAIN_PROCESS.equals(processName)) {
WebView.setDataDirectorySuffix(getProcessName() + ".webview");
}
}
but some Android mobile phone alse Crash with same reason,and I don't use webview with multi process, then I try add this code in Fragment onCreateView before inflater.inflate(webview_layout, container, false)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
String processName = getProcessName();
try {
WebView.setDataDirectorySuffix(processName);
} catch (Throwable e) {
// ignore
}
}
But I also get some the same crash report in PCAM10\PCEM00\PCAT10... and I can't reappear this crash local.
Is also some other reason with this Crash?
Upvotes: 37
Views: 19993
Reputation: 1
Build version: 2.4.0 Current date: 2024-11-08 19:47:54 Device: Vivo V2237 OS version: Android 14 (SDK 34)
Stack trace:
java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. https://crbug.com/558377 : Current process com.zenhub.gfx (pid 20575), lock owner unknown
at org.chromium.android_webview.AwDataDirLock.b(chromium-TrichromeWebViewGoogle6432.aab-stable-672308633:202)
at org.chromium.android_webview.AwBrowserProcess.j(chromium-TrichromeWebViewGoogle6432.aab-stable-672308633:16)
at com.android.webview.chromium.N.e(chromium-TrichromeWebViewGoogle6432.aab-stable-672308633:207)
at WV.rY.run(chromium-TrichromeWebViewGoogle6432.aab-stable-672308633:11)
at android.os.Handler.handleCallback(Handler.java:1013)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:328)
at android.app.ActivityThread.main(ActivityThread.java:9188)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAn**
**dArgsCaller.run(RuntimeInit.java:594) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
Upvotes: 0
Reputation: 1
[Android] Below code help to solve this issue. I add process id in suffix directory name
private fun setupWebView() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
getAppProcessName()?.let {
WebView.setDataDirectorySuffix(it)
}
}
}
private fun getAppProcessName(): String? {
val pid = Process.myPid()
val manager = getSystemService(Context.ACTIVITY_SERVICE) as? ActivityManager
return manager?.runningAppProcesses?.filterNotNull()?.firstOrNull { it.pid == pid }?.processName + pid
}
Upvotes: 0
Reputation: 6175
If you have two or more different processes for your app and services then you could just disable WebView usage in the process which doesnt intend to use WebView WebView.disableWebView()
public void onCreate() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WebView.disableWebView();
}
...
}
In that case exception will be thrown if a WebView is created or any other methods in the android.webkit package are used by process. But the "java.lang.RuntimeException:Using WebView from more than one process...." exception will gone
Upvotes: 1
Reputation: 1992
using this code in Application class before initializing Admob solve my problem:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val process = getProcessName()
if (packageName != process) WebView.setDataDirectorySuffix(process)
}
MobileAds.initialize(this)
Upvotes: 14
Reputation: 31
There is a new effective API to get process name for API 28 onwards. [https://developer.android.com/reference/android/app/Application.html#getProcessName()][1]
As mentioned in google documentation, from API 28, it's clear that WebView running in multiprocess can not share the same data directory.
This means that different processes in the same application cannot directly share WebView-related data, since the data directories must be distinct.
Another thing, please check if you are initializing any process in the Application class or not. Reference link : Android Pie (9.0) WebView in multi-process
Upvotes: 3