react-native-webview / react-native-webview

React Native Cross-Platform WebView
https://github.com/react-native-community/discussions-and-proposals/pull/3
MIT License
6.54k stars 2.99k forks source link

Using WebView from more than one process at once with the same data directory is not supported #968

Closed mahavirvataliya closed 4 years ago

mahavirvataliya commented 5 years ago

Bug description: I am getting this error in Android 9 Samsung Galaxy Note10+ devices with following traces

java.lang.RuntimeException: Using WebView from more than one process at once with the same data directory is not supported. https://crbug.com/558377

Stack traces

org.chromium.android_webview.AwBrowserProcess.b PG:12 in.m PG:33 hn.run PG:2 org.chromium.base.task.TaskRunnerImpl.g PG:11 vJ0.run android.os.Handler.handleCallback Handler.java:873 android.os.Handler.dispatchMessage Handler.java:99 android.os.Looper.loop Looper.java:216 android.app.ActivityThread.main ActivityThread.java:7263 java.lang.reflect.Method.invoke Method.java com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:494 com.android.internal.os.ZygoteInit.main ZygoteInit.java:975

Environment:

ekling commented 5 years ago

Experiencing the same issue for Galaxy devices on Android 9

hweister commented 4 years ago

Experiencing the same issue for nubia devices on Android 9

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 com.android.webview.chromium.WebViewChromiumAwInit.startChromiumLocked + 63(WebViewChromiumAwInit.java:63) at com.android.webview.chromium.WebViewChromiumAwInitForP.startChromiumLocked + 3(WebViewChromiumAwInitForP.java:3) at com.android.webview.chromium.WebViewChromiumAwInit$3.run + 3(WebViewChromiumAwInit.java:3) at android.os.Handler.handleCallback + 873(Handler.java:873) at android.os.Handler.dispatchMessage + 99(Handler.java:99) at android.os.Looper.loop + 215(Looper.java:215) at android.app.ActivityThread.main + 7376(ActivityThread.java:7376) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 500(RuntimeInit.java:500) at com.android.internal.os.ZygoteInit.main + 865(ZygoteInit.java:865)

vovkind commented 4 years ago

Same issue for Galaxy S10e on Android 9 Same RN version: 0.59.10 Same react-native-webview version: 5.10.0

hweister commented 4 years ago

Android 9 prohibit sharing WebView data directory among multiple processes add below code in your mainApplication file

public void onCreate() {
        ...
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            String processName = getProcessName(this);
            String packageName = this.getPackageName();
            if (!packageName.equals(processName)) {
                WebView.setDataDirectorySuffix(processName);
            }
        }
}

private String getProcessName(Context context) {
        if (context == null) return null;
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
            if (processInfo.pid == android.os.Process.myPid()) {
                return processInfo.processName;
            }
        }
        return null;
    }
bashen1 commented 4 years ago

Same issue

cmcrcruces commented 4 years ago

I'm having the same issue...

Android-yang commented 4 years ago

I'm having the same issue...

dmarkowski commented 4 years ago

Same issue here on Samsung Galaxy S9+ SM-G965F

rgoksu91 commented 4 years ago

same issue..

johnjoshuadablo commented 4 years ago

+1

Daha62 commented 4 years ago

same

thesourav123 commented 4 years ago

same

mianaliasjad commented 4 years ago

Android 9 prohibit sharing WebView data directory among multiple processes add below code in your mainApplication file

public void onCreate() {
        ...
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            String processName = getProcessName(this);
            String packageName = this.getPackageName();
            if (!packageName.equals(processName)) {
                WebView.setDataDirectorySuffix(processName);
            }
        }
}

private String getProcessName(Context context) {
        if (context == null) return null;
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
            if (processInfo.pid == android.os.Process.myPid()) {
                return processInfo.processName;
            }
        }
        return null;
    }

API 28 onwards there is a new api to get process name which is more performant. Check [here](https://developer.android.com/reference/android/app/Application.html#getProcessName())

Alyssa-McKee-Copart2 commented 4 years ago

can anyone confirm or deny if @hweister 's suggestion works?

Seeing this issue in our production application in crashlytics, but I'm unable to get my hands on any devices where its happening. It seems to be happening only on certain new Samsung devices on android 9 and 10. Samsung Galaxy Note10+, S10+, S10, Note9, S9. No reports of it happening on any other devices running android 9 or 10, Nor can I reproduce on any device i have available.

edit: To my knowledge, we are not using multiple processes in the application? It seems odd to me that we would only see it on Samsung.

relevant packages including all libraries that reference importing from android.webkit:

react-native: 0.59.10,
wix/react-native-navigation, // [v1] of the library
react-native-webview,
react-native-device-info,
react-native-fs,
react-native-image-picker,
MadeinFrance commented 4 years ago

Same bug on OnePlus 7 Pro - Android 10.

Unfortunately the suggestion of @hweister did not work.

dev071089 commented 4 years ago

Same bug on Oppo device too...

And yes the suggestion of @hweister did not work for me as well.

github-actions[bot] commented 4 years ago

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

ivorsmorenburg commented 4 years ago

This issue still happening, can we reopen it?

ghost commented 4 years ago

Having the same problem with android 10

songxiaoliang commented 4 years ago

Having the same problem.

jenthone commented 4 years ago

We can refer from this: https://bugs.chromium.org/p/chromium/issues/detail?id=558377#c126

Go-Jeon-Pa commented 4 years ago

Is this a WebView bug?

ehqwang commented 4 years ago

Experiencing the same issue for xiaomi Max devices on Android 10 Question details: Main thread Background process

Duna commented 3 years ago
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 : Current process com.dunatv.photosafe (pid 10634), lock owner com.dunatv.foregroundservice (pid 10308)
       at org.chromium.android_webview.AwDataDirLock.b(AwDataDirLock.java:28)
       at hv.i(hv.java:31)
       at gv.run(gv.java:2)
       at android.os.Handler.handleCallback(Handler.java:907)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:216)
       at android.app.ActivityThread.main(ActivityThread.java:7625)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

Android 9 Honor 9i

Noltibus commented 3 years ago
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 : Current process com.dunatv.photosafe (pid 10634), lock owner com.dunatv.foregroundservice (pid 10308)
       at org.chromium.android_webview.AwDataDirLock.b(AwDataDirLock.java:28)
       at hv.i(hv.java:31)
       at gv.run(gv.java:2)
       at android.os.Handler.handleCallback(Handler.java:907)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:216)
       at android.app.ActivityThread.main(ActivityThread.java:7625)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

Android 9 Honor 9i

Have the exact same issue, while using react but no WebView explicitly

Jennyxiav2 commented 3 years ago

can anyone confirm or deny if @hweister 's suggestion works?

Seeing this issue in our production application in crashlytics, but I'm unable to get my hands on any devices where its happening. It seems to be happening only on certain new Samsung devices on android 9 and 10. Samsung Galaxy Note10+, S10+, S10, Note9, S9. No reports of it happening on any other devices running android 9 or 10, Nor can I reproduce on any device i have available.

edit: To my knowledge, we are not using multiple processes in the application? It seems odd to me that we would only see it on Samsung.

relevant packages including all libraries that reference importing from android.webkit:

react-native: 0.59.10,
wix/react-native-navigation, // [v1] of the library
react-native-webview,
react-native-device-info,
react-native-fs,
react-native-image-picker,

Did you find anything useful? I'm facing the same issue on Samsung... We are not using multiple processes either, so I don't think 'setDataDirectorySuffix' is a good way to solve it.

ysxlmk commented 3 years ago

Having the same problem.

parasgupta93 commented 3 years ago

Anyone got the solution ??

wuyan93 commented 3 years ago

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 org.chromium.androidwebview.AwBrowserProcess.a(PG:40) at ku.c(PG:90) at ky.run(PG:3) at org.chromium.base.task.TaskRunnerImpl.d(PG:50) at EQ.run(Unknown Source:2) at android.os.Handler.handleCallback(Handler.java:907) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:216) at android.app.ActivityThread.main(ActivityThread.java:7625) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

Android 10,level 29 HuaWei/EMOTION

bunny-pu commented 3 years ago

Having the same problem

kaichunlin commented 3 years ago

I had encountered the same issue in my previous work, where the app runs on a Cordova derivative. My solution was very similar to @hweister except that:

The crashes mostly stopped after releasing this necessary hack.

himanshu-tiwari commented 3 years ago

Any solution to this? Encountered the same issue on Samsung devices

qusai95 commented 2 years ago

you can show this link to get more details https://blog.katastros.com/a?ID=01600-3fade614-39a4-4b34-bd09-da94047b1e0d

ralesiupgrade commented 2 years ago

Android 9 prohibit sharing WebView data directory among multiple processes add below code in your mainApplication file

public void onCreate() {
        ...
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            String processName = getProcessName(this);
            String packageName = this.getPackageName();
            if (!packageName.equals(processName)) {
                WebView.setDataDirectorySuffix(processName);
            }
        }
}

private String getProcessName(Context context) {
        if (context == null) return null;
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
            if (processInfo.pid == android.os.Process.myPid()) {
                return processInfo.processName;
            }
        }
        return null;
    }

This worked for me, but i had to make sure it was the first thing called in onCreate, once i moved it around in the method it worked fine. Thanks

baptistecassar commented 2 years ago

Hi, I am facing with the same issue. If you have a proper work around could you provide us a snippet in your documentation ? Thanks

nihp commented 2 years ago

I am also facing the same error

justindi15 commented 2 years ago

Having same error still

maxymczech commented 2 years ago

Same here. This error started happenning after adding react-native-background-geolocation.

P. S. Solution provided by @hweister solved the problem. Thank you very much, I apologize for reopening the issue.

jackkinsella commented 2 years ago

Same issue today when using

    "react-native-webview": "^11.23.1",
     "react-native": "0.68.2",

Maybe this is relevant: https://bugs.chromium.org/p/chromium/issues/detail?id=558377

This exception was thrown within 2 seconds of booting the app, perhaps indicating that a previous run's WebView had not been fully shut down by the OS (e.g. due to idling). According to the link above, this has a 3s grace period in total.

The full exception was

org.chromium.android_webview.AwDataDirLock in b at line 106
org.chromium.android_webview.AwBrowserProcess in j at line 143
com.android.webview.chromium.b1 in d at line 204
com.android.webview.chromium.b1 in b at line 322
com.android.webview.chromium.WebViewChromiumFactoryProvider in n at line 297
com.android.webview.chromium.WebViewChromium in init at line 302
android.webkit.WebView in <init> at line 429
android.webkit.WebView in <init> at line 353
android.webkit.WebView in <init> at line 336
android.webkit.WebView in <init> at line 323
android.webkit.WebView in <init> at line 313
com.reactnativecommunity.webview.RNCWebViewManager$RNCWebView in <init> at line 1529
com.reactnativecommunity.webview.RNCWebViewManager in createRNCWebViewInstance at line 186
com.reactnativecommunity.webview.RNCWebViewManager in createViewInstance at line 192
com.reactnativecommunity.webview.RNCWebViewManager in createViewInstance at line 130
com.facebook.react.uimanager.ViewManager in createViewInstance at line 139
com.facebook.react.uimanager.ViewManager in createView at line 76
com.facebook.react.uimanager.NativeViewHierarchyManager in createView at line 281
com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation in execute at line 194
com.facebook.react.uimanager.UIViewOperationQueue$1 in run at line 909
com.facebook.react.uimanager.UIViewOperationQueue in flushPendingBatches at line 1026
com.facebook.react.uimanager.UIViewOperationQueue in access$2600 at line 47
com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback in doFrameGuarded at line 1086
com.facebook.react.uimanager.GuardedFrameCallback in doFrame at line 29
com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher in doFrame at line 175
com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1 in doFrame at line 85
android.view.Choreographer$CallbackRecord in run at line 997
android.view.Choreographer in doCallbacks at line 797
android.view.Choreographer in doFrame at line 728
android.view.Choreographer$FrameDisplayEventReceiver in run at line 984
android.os.Handler in handleCallback at line 883
android.os.Handler in dispatchMessage at line 100
android.os.Looper in loop at line 237
android.app.ActivityThread in main at line 8016
java.lang.reflect.Method in invoke
com.android.internal.os.RuntimeInit$MethodAndArgsCaller in run at line 493
com.android.internal.os.ZygoteInit in main at line 1076

The device was a Samsung SM-G988B running android 10.

Sumit-Budhiraja commented 1 year ago

Still facing this issue again.? Anyone got any fixes on this one.?

Fatih120 commented 1 year ago

No clue what this is but I hate it so much. I want to use my apps.

AkshayOptimumbrew commented 7 months ago

I am facing the same issue with Android. Device: Huawei Y9 Prime 2019 Android OS: 10 image

DisciplineBK commented 6 months ago

me too, I have same issue on my service

스크린샷 2024-04-05 오후 2 14 28

maxymczech commented 6 months ago

@hweister Would you be so king to rewrite your fix in Kotlin? 😅 I am trying to upgrade an app I am working on to RN 0.73, the Upgrade Helper tells me to convert MainActivity from Java to Kotlin, and this fix of yours is the last missing piece. Thank you in advance.