thlorenz / rid

Rust integrated Dart framework providing an easy way to build Flutter apps with Rust.
64 stars 4 forks source link

dll for Windows release mode / only works on dev device #64

Closed enzotar closed 2 years ago

enzotar commented 2 years ago

Release mode for windows only works on development device.

I added the path of the dll generated from bindgen in \target\debug\ to plugin\windows\CmakeList.txt to bundle it in the same folder as the executable.

# List of absolute paths to libraries that should be bundled with the plugin
set(plugin_bundled_libraries
  "absolute_path_to_dll"
  PARENT_SCOPE
)

And updated rid_api.dart to correctly pass the absolute path in dart_ffi.DynamicLibrary.open('absolute_path_to_dll')

And it works well on the development device. I can package it with Msix, submit to the windows store, and install. But on any other device, it cannot open the dll and shows a blank white screen on the app. Debugging with Visual Studio on another device shows Invalid argument(s): Failed to load dynamic library (126) but I can see the paths are correct.

Any ideas?

enzotar commented 2 years ago

Solution found. It is a missing dll.

Windows provides the wrong error message 126, which means file missing/can't be opened. In actuality, the 'missing' file is read and that file in turn points to a missing dll.

You need to run a dependency tracker on the main application dll, the one generated by cargo, to show all dlls that need to be packaged. Flutter and the Msix packager do not bundle all the dlls.

Dumpbin, a tool in VS Studio can provide the list of needed dlls: dumpbin /dependents [absolute_path_to_main_dll]

and can be found in C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\bin\Hostx64\x86