Using WebView from more than one process at once with the same data directory is not supported.
I faced above issue when launching app, its a Native Android app having integrated Flutter code. Below I explain the details and fix for the issue.
To integrate in Flutter app in to Android Native app. I have write below code in
public class ExampleApp extends Application {
@Override
public void onCreate() {
super.onCreate();
mFlutterEngineDefault = new FlutterEngine(this);
mFlutterEngineDefault.getNavigationChannel().setInitialRoute("route");
// Start executing Dart code in the FlutterEngine.
mFlutterEngineDefault.getDartExecutor().executeDartEntrypoint(
DartExecutor.DartEntrypoint.createDefault()
);
}
}
When running app, I got below error, when instantiating FlutterEngine
2022-02-08 10:59:24.101 28505-28505/com.example.app.beta E/GeneratedPluginRegistrant: Error registering plugin flutter_inappwebview, com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin
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.example.app.beta:remote (pid 28505), lock owner com.example.app.beta (pid 26599)
at org.chromium.android_webview.AwDataDirLock.b(chromium-TrichromeWebViewGoogle.aab-stable-475808733:27)
at org.chromium.android_webview.AwBrowserProcess.i(chromium-TrichromeWebViewGoogle.aab-stable-475808733:5)
at com.android.webview.chromium.b1.d(chromium-TrichromeWebViewGoogle.aab-stable-475808733:46)
at com.android.webview.chromium.b1.b(chromium-TrichromeWebViewGoogle.aab-stable-475808733:18)
at com.android.webview.chromium.WebViewChromiumFactoryProvider.getWebStorage(chromium-TrichromeWebViewGoogle.aab-stable-475808733:4)
at android.webkit.WebStorage.getInstance(WebStorage.java:194)
at com.pichillilorenzo.flutter_inappwebview.MyWebStorage.<init>(MyWebStorage.java:29)
at com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin.onAttachedToEngine(InAppWebViewFlutterPlugin.java:89)
at com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin.onAttachedToEngine(InAppWebViewFlutterPlugin.java:68)
at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.add(FlutterEngineConnectionRegistry.java:143)
at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:66)
at java.lang.reflect.Method.invoke(Native Method)
at io.flutter.embedding.engine.plugins.util.GeneratedPluginRegister.registerGeneratedPlugins(GeneratedPluginRegister.java:80)
at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:354)
at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:262)
at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:242)
at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:162)
at io.flutter.embedding.engine.FlutterEngine.<init>(FlutterEngine.java:153)
at com.example.app.utils.ExampleApp.onCreate(ExampleApp.java:68)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1190)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6562)
at android.app.ActivityThread.access$1400(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1886)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:221)
at android.app.ActivityThread.main(ActivityThread.java:7542)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
To fix this issue I have used below code, before initializing FlutterEngine
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
String process = getProcessName();
if ( !BuildConfig.APPLICATION_ID.equals(process))
WebView.setDataDirectorySuffix(process);
}
mFlutterEngineDefault = new FlutterEngine(this);
Solved the issue.
Hope it helps ๐
One thought on “Using WebView from more than one process”
Exactly.