flutter-permission-handler
flutter-permission-handler copied to clipboard
Nuget not Found and CMake Error
🐛 Bug Report
Building Permissions Handler on Windows fails due to 2 errors.
- Nuget not installed
- Failed to run cppwinrt.exe
CC @azchohfi
Expected behavior
Building for Windows works.
Nuget.exe not found, trying to download or use cached version.
Argument cannot be null or empty
Parameter name: primarySources
CMake Error at flutter/ephemeral/.plugin_symlinks/permission_handler_windows/windows/CMakeLists.txt:29 (message):
Failed to install nuget package Microsoft.Windows.CppWinRT.2.0.210806.1
Exception: Unable to generate build files
Reproduction steps
- If Nuget is not added to the PATH, Nuget not installed error occurs.
- Run a project with permission_handler on Windows.
Launching lib\main.dart on Windows in debug mode...
Building Windows application...
CMake Error at flutter/ephemeral/.plugin_symlinks/permission_handler_windows/windows/CMakeLists.txt:38 (message):
Failed to run cppwinrt.exe
Exception: Unable to generate build files
This has nothing to do with the download of nuget.exe or the fact that it is not on the PATH. This message is expected if nuget.exe is not on the PATH, but it is only informative, not an error. Nuget.exe is being downloaded and is being executed. The problem seems to be that the "nuget.exe install" command is failing. Seems like a misconfiguration in your Visual Studio, which sets the default nuget sources. Could you please send a screenshot of the NuGet Package Manager tab on VS's Options? It should have the nuget.org option, poiting to the nuget v3.
Thank you for taking a look Alexandre
Do you have multiple installations of VS? This is really weird, and I don't know exactly what is happening. Does it work if you do have nuget.exe on your path?
Unfortunately not, I've added nuget to my path. The installation error disappears but the second error persists.
I did have VS 2019 installed before upgrading to VS 2022 a few weeks ago. But during this testing, I've only had 1 VS installed.
I can't reproduce this, so I don't know what is happening. Can you try to run the full command from the command line?
nuget.exe install Microsoft.Windows.CppWinRT -Version 2.0.210806.1 -OutputDirectory packages
This should be executed from the build folder, so something like:
your_project\build\windows
If this command succeeds, then the build process should work. If not, we can probably at least get some more info into why this is happening.
Succeeds but builds still fail with:
CMake Error at flutter/ephemeral/.plugin_symlinks/permission_handler_windows/windows/CMakeLists.txt:38 (message):
Failed to run cppwinrt.exe
Exception: Unable to generate build files
What happens if you run the cppwinrt command?
./packages/Microsoft.Windows.CppWinRT.2.0.210806.1/bin/cppwinrt.exe -input sdk -output include
Maybe this is a missing SDK?
Hmmm, am I supposed to see anything happen? The cppwinrt.exe file is there. When I run the command, there's no output but it seems to succeed.
This is what is weird then. There might be some issue with your VS's cmake, or something else, since this: https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler_windows/windows/CMakeLists.txt#L34-L38 Is also not running fine, as you mentioned that it failed. I honestly don't know what is happening with your box. Can you try to replicate this in a different machine?
No worries! Let's wait and see if anyone else has this issue. I ran this on another computer and it failed as well.
Facing the same
I have the same issue. Only in windows mode. If I remove permission_handler from pubspec.yaml, it runs ok. Until last Friday, it was ok.
Facing the same
The screenshot you sent is not an issue, just a "warning". It can be safely ignored. Are you having the same other issue when building? If you run the ./packages/Microsoft.Windows.CppWinRT.2.0.210806.1/bin/cppwinrt.exe -input sdk -output include
command, does it succeed?
Same error here before updating Visual Studio: Nuget.exe not found, trying to download or use cached version. CMake Error at flutter/ephemeral/.plugin_symlinks/permission_handler_windows/windows/CMakeLists.txt:29 (message): Failed to install nuget package Microsoft.Windows.CppWinRT.2.0.210806.1
After updating Visual Studio Installer and Visual Studio 2019 the error was gone. The warning (first line) still appears but the application compiles.
same issue, when i ran flutter run -d windows
or flutter build windows
,it never finished.
i am using vs 2022
Same error here before reinstall Visual Studio 2022.
At first,i am using vs 2022
1.Nuget is not added to the PATH,build failed with
Nuget.exe not found, trying to download or use cached version.
;
2.Nuget is added to the PATH,build failed with
CMake Error at flutter/ephemeral/.plugin_symlinks/permission_handler_windows/windows/CMakeLists.txt:38 (message): Failed to run cppwinrt.exe
;
3.reinstall vs 2019 the same problem;
4.reinstall vs 2022 the same problem;
5.install vs 2022 after uninstall vs and use VisualStudioUninstaller,build successed;
I hope this may help you.
Same error here before reinstall Visual Studio 2022.
At first,i am using vs 2022 1.Nuget is not added to the PATH,build failed with
Nuget.exe not found, trying to download or use cached version.
; 2.Nuget is added to the PATH,build failed withCMake Error at flutter/ephemeral/.plugin_symlinks/permission_handler_windows/windows/CMakeLists.txt:38 (message): Failed to run cppwinrt.exe
; 3.reinstall vs 2019 the same problem; 4.reinstall vs 2022 the same problem; 5.install vs 2022 after uninstall vs and use VisualStudioUninstaller,build successed;I hope this may help you.
I had the same problem again today after I executed flutter clean
.
But this time the error message is more detailed,Maybe it's because I have http_proxy|https_proxy configured in path. The following is the error message.
Nuget.exe not found, trying to download or use cached version.
Performing download step (download and verify) for 'nuget-populate'
-- verifying file...
file='G:/Develop/Flutter-Project/map_demo/build/windows/_deps/nuget-subbuild/nuget-populate-prefix/src/nuget.exe'
-- SHA256 hash of
G:/Develop/Flutter-Project/map_demo/build/windows/_deps/nuget-subbuild/nuget-populate-prefix/src/nuget.exe
does not match expected value
expected: '04eb6c4fe4213907e2773e1be1bbbd730e9a655a3c9c58387ce8d4a714a5b9e1'
actual: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
-- File already exists but hash mismatch. Removing...
-- Downloading...
dst='G:/Develop/Flutter-Project/map_demo/build/windows/_deps/nuget-subbuild/nuget-populate-prefix/src/nuget.exe'
timeout='none'
inactivity timeout='none'
-- Using src='https://dist.nuget.org/win-x86-commandline/v6.0.0/nuget.exe'
CMake Error at nuget-subbuild/nuget-populate-prefix/src/nuget-populate-stamp/download-nuget-populate.cmake:170 (message):
Each download failed!
CUSTOMBUILD : error : downloading 'https://dist.nuget.org/win-x86-commandline/v6.0.0/nuget.exe' failed [G:\Develop\Flutter-Project\map_demo\build\windows\_deps\nuget-subbuild\nuget-populate.vcxproj]
status_code: 4
status_string: "A requested feature, protocol or option was not found built-in in this libcurl due to a build-time decision."
log:
--- LOG BEGIN ---
Uses proxy env variable no_proxy == 'localhost,127.0.0.1,::1'
Uses proxy env variable https_proxy == 'https://127.0.0.1:7891'
Unsupported proxy 'https://127.0.0.1:7891', libcurl is built without the
HTTPS-proxy support.
Closing connection -1
--- LOG END ---
I removed this package and related codes when build on windows and add them on mobiles now ...
set no_proxy var !
I download a nuget.exe file and add it to PATH , it can build apps now.
Fixed after downloading Nuget.exe manually and adding it to the PATH
For me helped manual downloading of nuget like in comment https://github.com/Baseflow/flutter-permission-handler/issues/819#issuecomment-1120819084, then adding the https://api.nuget.org/v3/index.json
into NuGet sources through UI on Visual Studio Settings (like at screenshot at https://github.com/Baseflow/flutter-permission-handler/issues/819#issuecomment-1079291883) and then manual running command from https://github.com/Baseflow/flutter-permission-handler/issues/819#issuecomment-1079419482...
May be i'v a little overkill...
This randomly started happening to me today; didn't change anything. Very strange.
Adding to the path manually didn't help But this is just an annoying error. As far as I can see it doesn't interfere at all.
Sometimes this happens to me, sometimes it doesn't. When it does happen, sometimes it recovers, sometimes it crashes out.
I also had the problem building windows desktop. Updated VS2019, added nuget.exe to path, added nuget.org to VS sources, still compile error. Uninstalled VS2019, Installed VS2022 using VS Installer & C++ workloads. Compiles fine.
I also needed to delete the windows directory in my project and had to run flutter create .
again. After that all was fine.
what happend?
➜ nuget.exe install Microsoft.Windows.CppWinRT -Version 2.0.210806.1 -OutputDirectory packages
Feeds used:
Argument cannot be null or empty
参数名: primarySources
This is usually caused by an configuration error regarding NuGet package manager. The permission_handler_windows package makes use of NuGet to download the Microsoft.Windows.CppWinRT
library which contains is used to generate C++ header files to access the Windows native runtime SDK, needed to communicate with the GPS hardware.
I am not really sure what causes the configuration error, however here are some steps that can be verified:
- Make sure the default NuGet configuration file exists at the following path
%appdata%\NuGet\NuGet.Config
. If it doesn't exists create it with the following contents:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
- If the default
NuGet.Config
exists with the appropriate content, verify if you are allowed to connect to thehttps://api.nuget.org/v3/index.json
url. Some organisations are configured behind a firewall or proxy blocking access. - Make sure Visual Studio 2022 (not Visual Studio Code) is installed correctly with the "Desktop development with C++" workload including all default options.
If this all fails please run flutter build windows -v
. The -v
switch will provide verbose information and will give more feedback on why NuGet wasn't able to install the Microsoft.Windows.CppWinRT
library.