Flutter-“Failed to load dynamic library” at test.

When I was doing unit tests using a package called openpgp, I got the error “Invalid argument (s): Failed to load dynamic library’libopenpgp_bridge.dll’: error code 126”.

at first

I wanted to use PGP, I downloaded and used OpenPGP, but when I tried to test a class that used this package, I got “Invalid argument (s): Failed to load dynamic library’libopenpgp_bridge.dll’: I got the error “error code 126” and couldn’t unit test.

It worked in the application.

Development is done on Visual Studio Code on Windows 11.

Cause

It seems that the unit test of Dart / Flutter does not build the package used.

Error Testing in Flutter plugin · Issue #39 · dart-archive/ffi
Is it possible to write foreign function test in dart for a flutter plugin? I use ffi to import rust functions, and they...

The OpenPGP used this time was a mechanism that uses a native DLL using dynamic loading (dart: ffi) in the Windows version.
Not building the above package seems to mean that the dll required by OpenPGP is not placed in the location of the test executable format.

The execution format for testing is located under “Flutterbin cache artifacts engine”.
Looking at this location, the DLL is not placed. Therefore, the DLL loading has failed.

Later, when I looked at the modification date in the file under this folder, it was a little old date, not the date when I ran the test, so I wonder what the VM for testing is.

There was a DLL that seemed to be for OpenPGP under the folder where the package was built.

If nothing is done, it will not be possible to test classes using OpenPGP.

measures.

There was a DLL in the place where the package was built, so I concluded that if you want to test on Windows, you should add it to your PATH setting.

The path where the DLL is located is “${workspaceRoot}\build\windows\runner\Debug”.

Therefore, the following measures were taken.

Since the test of flutter etc. may be started from the terminal, the path where the DLL is located is additionally specified in the PATH of the terminal.

    "terminal.integrated.env.windows": {
        "PATH":"${workspaceRoot}\build\windows\runner\Debug;${env:PATH}"
    },

launch.json settings

I wanted to run the unit test with debugging, so I added the following items.
This makes it possible to perform debug tests from the source code.

{
  "name": "Path set mode",
  "type": "dart",
   "request": "launch",
   "codeLens": {
       // Types of CodeLens to inject
      "for": [ "run-test", "run-test-file", "debug-test", "debug-test-file" ],
       // Text for CodeLens link (${debugType} will be replaced with "run" or "debug")
       "title": "${debugType} (PATH)"
    },
   "env": { "PATH":"${workspaceRoot}\build\windows\runner\Debug;${env:PATH}" }
 }

Things that could not be dealt with

For this reason, I added the setting of launch.json above, but I could not find the function to change the PATH to Run / Debug that was placed from the beginning and then execute it.

Launch.json for that, adding PATH to the terminal.

Since the execution in the test explorer is in the state where the PATH is not set, it is not possible to confirm the success of all paths in the test explorer.

By adding the PATH of the terminal, it is possible to confirm the success of all paths from the terminal or task.

コメント

Copied title and URL