Caqil / wireguard_flutter

wireguard_flutter
https://pub.dev/packages/wireguard_flutter
MIT License
20 stars 20 forks source link

MacOS support? #19

Closed robbysneller closed 2 months ago

robbysneller commented 4 months ago

Does this work on MacOS?

I have been trying to get the project in the example directory working for some time and I have had no luck. I have renamed and double checked the bundle identifiers throughout the project and entitlements and they seem to be fine. I changed the path for the external build tool to my own downloaded copy of wireguard-apple sources vs the hardcoded path. and even tried recreating the WGExtension as a system extension vs an app extension after reading that could be an issue. It is still not working.

I can build the app and initialize "successfully" but I am just getting logs like this every time I try and connect where it does nothing and there is no error output. I am able to connect to the wireguard server using the macOS client without issue.

flutter: status changed VpnStage.disconnected
2024-03-14 14:48:34.798 example_flutter[49429:4784548] Starting the tunnel
flutter: status changed VpnStage.connecting
flutter: status changed VpnStage.connecting
flutter: status changed VpnStage.disconnected
flutter: status changed VpnStage.disconnected

I added an override to the init of the PacketTunnelProvider to log when it is initialized and it never prints so I am thinking that is my issue but I'm not sure how to deal with that.

I am very new to macOS/iOS development so if I am missing some basic setup steps that are not mentioned in the readme or wireguard-apple repo, please let me know

SudipZluck commented 3 months ago

Does this work on MacOS?

I have been trying to get the project in the example directory working for some time and I have had no luck. I have renamed and double checked the bundle identifiers throughout the project and entitlements and they seem to be fine. I changed the path for the external build tool to my own downloaded copy of wireguard-apple sources vs the hardcoded path. and even tried recreating the WGExtension as a system extension vs an app extension after reading that could be an issue. It is still not working.

I can build the app and initialize "successfully" but I am just getting logs like this every time I try and connect where it does nothing and there is no error output. I am able to connect to the wireguard server using the macOS client without issue.

flutter: status changed VpnStage.disconnected
2024-03-14 14:48:34.798 example_flutter[49429:4784548] Starting the tunnel
flutter: status changed VpnStage.connecting
flutter: status changed VpnStage.connecting
flutter: status changed VpnStage.disconnected
flutter: status changed VpnStage.disconnected

I added an override to the init of the PacketTunnelProvider to log when it is initialized and it never prints so I am thinking that is my issue but I'm not sure how to deal with that.

I am very new to macOS/iOS development so if I am missing some basic setup steps that are not mentioned in the readme or wireguard-apple repo, please let me know

Same issue

Caqil commented 3 months ago

please double check providerBundleIdentifier same like in xcode extension

robbysneller commented 2 months ago

by the way, for anyone in the future looking at this library, I got both the macOS and iOS examples both working and will be closing the issue although . I understand it is not the job of this library to teach Mac or iOS development but I think some documentation on the readme on setting up macOS and iOS would be helpful based on the number of issues similar to mine that have been posted. Anyways, thank you for the library! After getting the examples working I was able to integrate it into my own app that now works on Mac/iOS.

a few things people having issues could try

  1. you will need to download the wireguard-apple sources (https://github.com/WireGuard/wireguard-apple) edit the external build tool "tun" under the info section the directory to point to the newly downloaded location of WireGuardKitGo. it will currently be set to an incorrect hardcoded path

  2. you will need to download a version of go and make sure that it is accessible by the build. I have gotten it working with golang version 1.20.2 installed using asdf. others may work or be preferred but this is just what I did.

  3. probably a fairly obvious step for anyone familiar with Xcode development (I was/am not) but after opening the project in Xcode (open Runner.xcworkspace under macOS and/or iOS) under the Runner and WGExtension targets, under the signing and capabilities section, you will need to update the signing team and signing certificate to your own valid developer account

  4. I would recommend setting the exact version of the WireGuardKit package dependency to 1.0.17 instead of next major version. There is a newer version (1.1.0) that I think was causing a compilation error inside of the PacketTunnelProvider.swift. This may be a simple fix but I am very unfamiliar with macOS development so I was not able to get it working despite "fixing" the compilation error.

  5. as mentioned in lots of these issues, ensure that your provider bundle identifier is updated throughout your project. I believe you will have to change it from what comes in the example. honestly I don't exactly know how all the works (again, macOS noob) but when you update your bundle identifiers make sure you don't miss any spots. Your runner and the extension will have the same bundleIdentifier except the extension will end in WGExtension (ie com.example.wireguard for the Runner and com.example.wireguard.WGExtension for the WGExtension) Make sure that your flutter startVpn call references the EXTENSION bundle identifier and all different spots throughout your Xcode project are updated to use the new bundle identifier.

cmaxdev commented 2 months ago

Hi, @robbysneller, I met same issue using this flutter package. I installed this package and working good for android but it is not working for macos and ios. It is first time to using wireguard so I am not sure how solve this issue. Could you explain about 1 more detail? Thanks for your suport.

robbysneller commented 2 months ago

yes, sorry I should have made this more clear in my comment. I was explaining how to get the example macOS/iOS app in the repository working. if you are integrating it into your own, you will need to create the external build system target and the wireguard extension target yourself. I figured this out by opening the example and trying to set it up the same way in my own project

robbysneller commented 2 months ago

when integrating into your own project you will need to add the extension, the build system, the same capabilities under the signing and capabilities section of the runner and extension target (equivalent to permissions on android) as the example project, add the package dependency for the passepartoutvpn/wireguard-apple under the Runner project and then add the WireGuardKit framework under your new extension and runner target in Xcode.

Sorry if I forgot any steps but like I said, I would suggest cloning the wireguard_flutter repo and opening the macOS project under the example folder and then try and copy the configuration when working with your own project.

If you are unfamiliar with Xcode and Mac/iOS development like I am, it may be a painful process, but I can promise you it will work if you set it up right! good luck!

robbysneller commented 2 months ago

sorry for the spam of comments, but to be even more clear, this library will NOT work out of the box for iOS/macOS as it does for android. there are many manual steps you must take in Xcode to get things working after adding the flutter dependency to your existing project. I suspect based on all these issues that many flutter devs like me are not very familiar with traditional iOS/macOS development and thus it is confusing when things do not work right away as it does in android.

I have documented some of the steps here in this thread but I am not promising the instructions are complete. I messed with this for quite a while to get it working and tried many things. Maybe one day if I have time and there are still no updated instructions, I will start from scratch and document all of the steps needed to get it working and submit a pull request with the example.

Until then, I would suggest for anyone wanting to integrate into their own app to clone the example and have it open in Xcode side by side with your own project and update your own project until the configuration matches. These are all things I wish I had known weeks ago so hopefully you will find it helpful

cmaxdev commented 2 months ago

Thanks for your support. It will be helpful for me. You saved my time. Thank you

cmaxdev commented 2 months ago

Hi, @robbysneller I did all but It is not working yet. I just checked my PacketTunnelProvider.swift in WGExtension and example's file but these are different. It means not compiled correctly yet? or Should I copy code in PacketTunnelProvider.swift manually? Thank you

robbysneller commented 1 month ago

@cmaxdev hi, sorry for the late response. yes, you will need to manually copy the code in PacketTunnelProvider.swift from the example

talkbiz commented 1 month ago

Hello @robbysneller, After copying the PacketTunnelProvider.swift from the example, i got this error

`Running Xcode build... Xcode build done. 36.8s Failed to build iOS app Could not build the precompiled application for the device. Swift Compiler Error (Xcode): No such module 'WireGuardKit' /Users/username/ClientProjects/vpnName/ios/WGExtension/PacketTunnelProvider.swift:15:7

Error launching application on iPhone.`

SpaceXM commented 4 weeks ago

i have a strange issue with this, i can run and build all from VS code with "flutter run/build macos" command but i cannot build the app using Xcode, using just vs code i'm able to run the app and the tunnel is completely working

The error is caused by tun and the error output from Xcode is:

make: *** [/Users/test/Library/Developer/Xcode/DerivedData/Runner-haoarerbfrgaeaflntisbxzkvalk/Build/Intermediates.noindex/ArchiveIntermediates/Runner/IntermediateBuildFilesPath/Runner.build/Release/wireguard-go-bridge/goroot/.prepared] Error 1 Command ExternalBuildToolExecution failed with a nonzero exit code

robbysneller commented 2 days ago

@talkbiz did you follow the other steps to download the wireguard sources, and add the package dependency for WireGuardKit? it seems like you may have missed some steps.

@SpaceXM I have the same issue. my app will not run in Xcode but I am able to run it in the terminal. not sure why, but I haven't tried to trouble shoot it since I don't really have a need to run the app in Xcode. but you are not alone :)

talkbiz commented 2 days ago

@talkbiz did you follow the other steps to download the wireguard sources, and add the package dependency for WireGuardKit? it seems like you may have missed some steps.

@SpaceXM I have the same issue. my app will not run in Xcode but I am able to run it in the terminal. not sure why, but I haven't tried to trouble shoot it since I don't really have a need to run the app in Xcode. but you are not alone :)

Thanks, I’ve been able to fix it by calmly going through your messages again.

SpaceXM commented 2 days ago

Yes i can confirm that is possibile to run the package using Xcode, Unfortunately, I had to drop VPN support in my app due to Apple's strict rules for individual developers not allowing the use of VPNs in any way