-1

I'm building a flutter app on windows, i have tried different packages for in app web view like flutter_inappwebview and webview_cef.

The problem is when the application goes to the webview screen , the application get killed on the tester machine (the app closes unexpectedly).

i don't know why or what i have missed, it's working on my machine but closes on tester machine.

Although the recommended way to initialize the web view is applied within the initiate method of the webview screen :

void initState(){
 super.initState();
 initiate();
}

void initiate()async{
      if (!kIsWeb && defaultTargetPlatform == TargetPlatform.windows) {
        final availableVersion = await WebViewEnvironment.getAvailableVersion();
        assert(availableVersion != null,
            'Failed to find an installed WebView2 runtime or non-stable Microsoft Edge installation.');
    
        webViewEnvironment = await WebViewEnvironment.create(
            settings: WebViewEnvironmentSettings(userDataFolder: 'custom_path'));
      }
    
      if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) {
        await InAppWebViewController.setWebContentsDebuggingEnabled(kDebugMode);
      
 }
}

I was suspecting that the custom_path is the reason, because it's within Program Files folder and this folder isn't writable. read only , so the OS may kill the app, but when changed to system temporary the app still get killed using both packages.

1

1 Answer 1

0

I found it, The problem of working on some windows machines and not on others:

was because the in_app web view packages are natively written in C++ while some machines may have c++ x64 and x86 distributables installed and other may not.

So, the application works on machines which these distibutables are installed and get killed on any machine that doesn't have these distributables.

FIX:

After finishing the development of your flutter app and you are ready to publish a .exe release you have to make sure to bundle the c++ x64 distibutable for 64 bit machines and c++ x86 distributable for 32 bit machines.

Bundling: generally means packaging multiple components together into a single unit.

You have to do this at creating program installer phase, usually i use innosetup program to make exe installers for my flutter apps. you have to make sure you have bundled these c++ distributables within the program files while writing your installation script and install them on user machine if it's not already exist to ensure that your app and the in_app web view will work properly.

the part of the installer script that i'm talking about:

Here are distributables are bundled within app files

[Files]
Source: "VC_redist.x86.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall
Source: "VC_redist.x64.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall

And, the code section just checks for their existance on user machine to decide whether to install them or not.

[Code]

function NeedsVC_X86(): Boolean;
begin
  // Check registry key for VC++ 2015-2022 x86
  Result := not RegKeyExists(HKLM, 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86');
end;

function NeedsVC_X64(): Boolean;
begin
  // Check registry key for VC++ 2015-2022 x64
  Result := not RegKeyExists(HKLM, 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64');
end;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.