1- Connect OpenVPN service with Flutter, Issues and PRs are very welcome !
1+ Connect to the OpenVPN service using Flutter. Contributions through issues and pull requests are highly appreciated !
22
33## Android Setup
4- ### <b >1. Permission handler</b >
5- #### JAVA
6- Add this to your onActivityResult in MainActivity.java (if you are using Java)
4+
5+ ### 1. Permission Handler
6+
7+ #### Java
8+ Include the following code in the ` onActivityResult ` method of ` MainActivity.java ` (if you are using Java):
79
810``` java
9- OpenVPNFlutterPlugin . connectWhileGranted(requestCode == 24 && resultCode == RESULT_OK );
11+ OpenVPNFlutterPlugin . connectWhileGranted(requestCode == 24 && resultCode == RESULT_OK );
1012```
11- So it look like this
13+
14+ The complete method should look like this:
15+
1216``` java
13- ...
14- import id.laskarmedia.openvpn_flutter.OpenVPNFlutterPlugin ;
15- ...
16-
17- @Override
18- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
19- OpenVPNFlutterPlugin . connectWhileGranted(requestCode == 24 && resultCode == RESULT_OK );
20- super . onActivityResult(requestCode, resultCode, data);
21- }
17+ ...
18+ import id.laskarmedia.openvpn_flutter.OpenVPNFlutterPlugin ;
19+ ...
20+
21+ @Override
22+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
23+ OpenVPNFlutterPlugin . connectWhileGranted(requestCode == 24 && resultCode == RESULT_OK );
24+ super . onActivityResult(requestCode, resultCode, data);
25+ }
2226```
2327
2428#### Kotlin
25- Add this to your onAcivityResult in MainActivity.kt (if you are using Kotlin)
29+ Include the following code in the ` onActivityResult ` method of ` MainActivity.kt ` (if you are using Kotlin):
2630
2731``` kotlin
28- OpenVPNFlutterPlugin .connectWhileGranted(requestCode == 24 && resultCode == RESULT_OK );
32+ OpenVPNFlutterPlugin .connectWhileGranted(requestCode == 24 && resultCode == RESULT_OK );
2933```
30- So it look like this
34+
35+ The complete method should look like this:
36+
3137``` kotlin
32- .. .
33- import id.laskarmedia.openvpn_flutter.OpenVPNFlutterPlugin
34- .. .
35- override fun onActivityResult (requestCode : Int , resultCode : Int , data : Intent ? ) {
36- OpenVPNFlutterPlugin .connectWhileGranted(requestCode == 24 && resultCode == RESULT_OK )
37- super .onActivityResult(requestCode, resultCode, data)
38- }
38+ .. .
39+ import id.laskarmedia.openvpn_flutter.OpenVPNFlutterPlugin
40+ .. .
41+ override fun onActivityResult (requestCode : Int , resultCode : Int , data : Intent ? ) {
42+ OpenVPNFlutterPlugin .connectWhileGranted(requestCode == 24 && resultCode == RESULT_OK )
43+ super .onActivityResult(requestCode, resultCode, data)
44+ }
45+ ```
46+
47+ ### 2. App Bundle Build Not Connecting
48+
49+ If you encounter issues with the app not connecting using the latest Flutter SDK, apply the following quick fix:
50+
51+ Ensure that you include the following attribute within the ` <application> ` tag in your ` AndroidManifest.xml ` file:
52+
53+ ``` xml
54+ <application
55+ ...
56+ android : extractNativeLibs =" true"
57+ ...>
58+ </application >
3959```
4060
4161## iOS Setup
4262
43- ### <b >1. Add Capabillity</b >
44- Add 2 capabillity on Runner's Target, <b >App Groups</b > and <b >Network Extensions</b >, Look at the image below to get clearer details
63+ ### 1. Add Capabilities
64+
65+ Add the ` App Groups ` and ` Network Extensions ` capabilities to the Runner's target. Refer to the image below for detailed instructions:
4566
4667<img src =" https://blogger.googleusercontent.com/img/a/AVvXsEjYWGJ2ug4JM5g8_WslvdRY0Q-UUizOdmoCG8Ybhte9LiIv8_SSYFDHl-PzWApnAxvTA0hdpnBzca7C_zU5pHnyD8NLNoMw1ZOty7Zo6PTF22oIk7liB0aCXQnRAI1R0Zv9XfnuwuHuourtUR6lzf1ztrU_PTa6QFAU8kRPK-4h5MVu7QVzmpVs4Fvl=s600 " />
4768
48- ### <b >2. Add New Target</b >
49- Click + button on bottom left, Choose <b >NETWORK EXTENSION</b >, and follow instruction's image bellow
69+ ### 2. Add New Target
70+
71+ Click the ` + ` button on the bottom left, choose ` NETWORK EXTENSION ` , and follow the instructions in the image below:
5072
5173<img src =" https://blogger.googleusercontent.com/img/a/AVvXsEirvK1MMCqLADbXdtjppE-z1QC_cDPBnCWZ1EPkNLCM7TYyG3c2IGf8zlb1svW6aP6UB4eNOpX3svFwP_e9D0iP9Mb-dlXVtnUsYlg3iIQVqi_mmw4vLH5d8peEt7UGORikSlB3Hy0o1vj4XIBJNv5g8bIellHTXo4Zu4toh7Dt0jw4ZMyWDAoepLp7=s600 " />
5274
53- Add Capabillity on VPNExtension, Do it same like Runner's Capabillitiy
75+ Add the same capabilities to the VPNExtension as you did for the Runner's target:
5476
5577<img src =" https://blogger.googleusercontent.com/img/a/AVvXsEgEj_1oXmgRSaVISGFHutY88enlUG1V8ynqfDHso-uS6vKEBLa-dhhChjZQ12iN7UpNM6thCHLmll3h6p_lW9URAPca-pXkwIN1pmATdfk3NnqnmlYtgUAicbr-zDZmNF7JJ4l4EArFtdrb_IjxH_FpLJGCURkpGO9qBtkw9WYs3k2vRSa3c8ga9b6S=s600 " />
5678
57- ### <b >3. Copy Paste</b >
58- Add the following lines to your Podfile (` ios/Podfile ` )
79+ ### 3. Copy and Paste
80+
81+ Add the following lines to your Podfile (` ios/Podfile ` ):
5982
6083``` dart
6184target 'VPNExtension' do
@@ -64,49 +87,48 @@ target 'VPNExtension' do
6487end
6588```
6689
67- Open VPNExtension > PacketTunnelProvider.swift and copy paste this script < a href = " https://raw.githubusercontent.com/nizwar/openvpn_flutter/master/example/ios/VPNExtension/PacketTunnelProvider.swift " >PacketTunnelProvider.swift</ a >
90+ Open ` VPNExtension > PacketTunnelProvider.swift ` and copy- paste the script from [ PacketTunnelProvider.swift ] ( https://raw.githubusercontent.com/nizwar/openvpn_flutter/master/example/ios/VPNExtension/PacketTunnelProvider.swift ) .
6891
6992<img src =" https://blogger.googleusercontent.com/img/a/AVvXsEhPf7Vl_8LPYMTTCn0UbpR3f3qzaFPFRMikSg8xetWRyfTuViq6o3fdrjU4-jD-xZtkOZV_i2WoNXkcHLn7znHengHZGgtlJlNbNk6vjNYgI2jYg8ToOYIQjR7QBd443ee4GqpEww0FYPrIiIpabUthpur6SakiPJM1dsDNCBW9ROWixuEzrk61aIod=s600 " >
7093
7194## Note
72- You must use iOS Devices instead of Simulator to connect
73-
7495
96+ You must use iOS devices instead of the simulator to connect.
7597
7698## Recipe
7799
78100### Initialize
79- Before start, you have to initialize the OpenVPN plugin.
80101
81- ``` dart
82- late OpenVPN openvpn;
83-
84- @override
85- void initState() {
86- openvpn = OpenVPN(onVpnStatusChanged: _onVpnStatusChanged, onVpnStageChanged: _onVpnStageChanged);
87- openvpn.initialize(
88- groupIdentifier: "GROUP_IDENTIFIER", ///Example 'group.com.laskarmedia.vpn'
89- providerBundleIdentifier: "NETWORK_EXTENSION_IDENTIFIER", ///Example 'id.laskarmedia.openvpnFlutterExample.VPNExtension'
90- localizedDescription: "LOCALIZED_DESCRIPTION" ///Example 'Laskarmedia VPN'
91- );
92- }
102+ Before starting, initialize the OpenVPN plugin:
93103
94- void _onVpnStatusChanged(VPNStatus? vpnStatus){
95- setState((){
96- this.status = vpnStatus;
97- });
98- }
104+ ``` dart
105+ late OpenVPN openvpn;
106+
107+ @override
108+ void initState() {
109+ openvpn = OpenVPN(onVpnStatusChanged: _onVpnStatusChanged, onVpnStageChanged: _onVpnStageChanged);
110+ openvpn.initialize(
111+ groupIdentifier: "GROUP_IDENTIFIER", ///Example 'group.com.laskarmedia.vpn'
112+ providerBundleIdentifier: "NETWORK_EXTENSION_IDENTIFIER", ///Example 'id.laskarmedia.openvpnFlutterExample.VPNExtension'
113+ localizedDescription: "LOCALIZED_DESCRIPTION" ///Example 'Laskarmedia VPN'
114+ );
115+ }
99116
100- void _onVpnStageChanged(VPNStage? stage ){
101- setState((){
102- this.stage = stage ;
103- });
104- }
117+ void _onVpnStatusChanged(VPNStatus? vpnStatus ){
118+ setState((){
119+ this.status = vpnStatus ;
120+ });
121+ }
105122
123+ void _onVpnStageChanged(VPNStage? stage){
124+ setState((){
125+ this.stage = stage;
126+ });
127+ }
106128```
107129
108-
109130### Connect to VPN
131+
110132``` dart
111133void connect() {
112134 openvpn.connect(
@@ -115,36 +137,37 @@ void connect() {
115137 username: username,
116138 password: password,
117139 bypassPackages: [],
118- // In iOS connection can stuck in "connecting" if this flag is "false".
140+ // In iOS connection can get stuck in "connecting" if this flag is "false".
119141 // Solution is to switch it to "true".
120142 certIsRequired: false,
121143 );
122144}
123145```
124146
125- ### Disconnect
147+ ### Disconnect
148+
126149``` dart
127- void disconnect(){
128- openvpn.disconnect();
129- }
150+ void disconnect(){
151+ openvpn.disconnect();
152+ }
130153```
131154
132-
133155# Publishing to Play Store and App Store
156+
134157### Android
135- 1 . You can use appbundle to publish the app
136- 2 . Add this to your files in ` android ` folder (special thanks to https://github.com/nizwar/openvpn_flutter/issues/10 ). Otherwise connection will not be
137- established in some cases and will siliently report "disconnected" when trying to connect. Most likely it's related to some symbols stripping by
138- Google Play.
158+
159+ 1 . You can use app bundles to publish the app.
160+ 2 . Add the following to your files in the ` android ` folder (special thanks to https://github.com/nizwar/openvpn_flutter/issues/10 ). Otherwise, the connection may not be established in some cases and will silently report "disconnected" when trying to connect. This is likely related to some symbols being stripped by Google Play.
161+
139162```
140163gradle.properties > android.bundle.enableUncompressedNativeLibs=false
141- AndroidManifest > android:extractNativeLibs="true" in application tag
164+ AndroidManifest > android:extractNativeLibs="true" in the application tag
142165```
143166
144- app/build.gradle add these inside android tag
145- ``` gradle
167+ Add the following inside the ` android ` tag in ` app/build.gradle ` :
146168
147- android{
169+ ``` gradle
170+ android {
148171 ...
149172 //from here ======
150173 lintOptions {
@@ -175,26 +198,31 @@ android{
175198```
176199
177200#### Notifications
178- As the plugin shows notification for connection status and connection detail, you have to request permission by using 3rd-party packages.
179201
180- Example by using [ permission_handler] ( https://pub.dev/packages/permission_handler )
202+ As the plugin shows notifications for connection status and connection details, you must request permission using third-party packages.
203+
204+ Example using [ permission_handler] ( https://pub.dev/packages/permission_handler ) :
205+
181206``` dart
182- ///Put it anywhere you wish like once you initialize the vpn or pre-connect the server
183- Permission.notification.isGranted.then((_) {
184- if (!_) Permission.notification.request();
185- });
207+ ///Put it anywhere you wish, like once you initialize the VPN or pre-connect to the server
208+ Permission.notification.isGranted.then((_) {
209+ if (!_) Permission.notification.request();
210+ });
186211```
187212
188-
189213### iOS
190- 1 . View [ Apple Guidelines] ( https://developer.apple.com/app-store/review/guidelines/#vpn-apps ) Relating to VPN
191- 2 . This plugin DOES use Encryption BUT, It uses Exempt Encryptions
214+
215+ 1 . View [ Apple Guidelines] ( https://developer.apple.com/app-store/review/guidelines/#vpn-apps ) relating to VPN.
216+ 2 . This plugin DOES use encryption, but it uses exempt encryptions.
192217
193218## Licenses
219+
194220* [ openvpn_flutter] ( https://github.com/nizwar/openvpn_flutter/blob/master/LICENSE ) for this plugin
195- * [ ics-openvpn] ( https://github.com/schwabe/ics-openvpn ) for Android Engine
196- * [ OpenVPNAdapter] ( https://github.com/ss-abramchuk/OpenVPNAdapter ) for iOS Engine
197- # Love my work?
198- Don't forget to give me a 👍   ; or support me with a cup of ☕️
221+ * [ ics-openvpn] ( https://github.com/schwabe/ics-openvpn ) for the Android engine
222+ * [ OpenVPNAdapter] ( https://github.com/ss-abramchuk/OpenVPNAdapter ) for the iOS engine
223+
224+ # Support
225+
226+ If you appreciate my work, don't forget to give a thumbs up or support me with a cup of coffee.
199227
200- <a href =" https://paypal.me/nizwar/ " ><img src =" https://raw.githubusercontent.com/andreostrovsky/donate-with-paypal/master/blue.svg " height =" 40 " ></a >
228+ <a href =" https://paypal.me/nizwar/ " ><img src =" https://raw.githubusercontent.com/andreostrovsky/donate-with-paypal/master/blue.svg " height =" 40 " ></a >
0 commit comments