Skip to content

Commit

Permalink
Add auto downloader for native lib
Browse files Browse the repository at this point in the history
Update document & changelog
  • Loading branch information
ctrysbita committed Dec 29, 2018
1 parent 354a938 commit 2ccd015
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 10 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
## 0.0.1

No release yet.
Still under development.
Provide simplest IkeV2-eap VPN service.
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,22 @@ Add the service in the `application` part your `AndroidManifest.xml`.
android:permission="android.permission.BIND_VPN_SERVICE"/>
</application>
```

Add native libs inside your `android/app/src/main/libs` .
The native libs can be build from strongswan.
You can also download the prebuild native libs [here](https://github.com/X-dea/Flutter_VPN/releases).
Modify your `app/build.gradle` to use Java 8 and avoid [#22397](https://github.com/flutter/flutter/issues/22397).
```gradle
android {
...
lintOptions {
...
// To avoid error.
checkReleaseBuilds false
}
// Plugin requires Java 8.
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
```
The plugin will automatically download pre-build native libraries from [here](https://github.com/X-dea/Flutter_VPN/releases) if they haven't been downloaded.

24 changes: 23 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,31 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'de.undercouch:gradle-download-task:3.4.3'
}
}

apply plugin: 'de.undercouch.download'

// Download pre-build native libs.
task downloadNaticeLib(type: Download) {
src 'https://github.com/X-dea/Flutter_VPN/releases/download/v0.0.1/strongswan_libs_v5.7.2.zip'
dest "$buildDir/native.zip"
}

task getNativeFile(dependsOn: downloadNaticeLib, type: Copy) {
from zipTree("$buildDir/native.zip")
into "src/main/libs"
}

// Automatically download native libs before build when doesn't exist.
tasks.whenTaskAdded {
task ->
if (task.name == "preBuild" && !(file('./src/main/libs').exists())) {
preBuild.dependsOn getNativeFile
}
}

rootProject.allprojects {
repositories {
google()
Expand All @@ -34,7 +56,7 @@ android {
}

defaultConfig {
minSdkVersion 19
minSdkVersion 16
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class _MyAppState extends State<MyApp> {
),
RaisedButton(
child: Text('Connect'),
onPressed: () => FlutterVpn.connect(
onPressed: () => FlutterVpn.simpleConnect(
_addressController.text,
_usernameController.text,
_passwordController.text,
Expand Down
12 changes: 11 additions & 1 deletion lib/flutter_vpn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,26 @@ import 'package:flutter/services.dart';
class FlutterVpn {
static const MethodChannel _channel = const MethodChannel('flutter_vpn');

/// Prepare for vpn connection.
///
/// For first connection it will show a dialog to ask for permission.
/// When your connection was interrupted by another VPN connection,
/// you should prepare again before reconnection.
static Future<bool> prepare() async {
return await _channel.invokeMethod('prepare');
}

static Future<Null> connect(
/// Connect to VPN.
///
/// Use given credentials to connect VPN (ikev2-eap).
/// This will create a background VPN service.
static Future<Null> simpleConnect(
String address, String username, String password) async {
await _channel.invokeMethod('connect',
{'address': address, 'username': username, 'password': password});
}

/// Disconnect will stop current VPN service.
static Future<Null> disconnect() async {
await _channel.invokeMethod('disconnect');
}
Expand Down

0 comments on commit 2ccd015

Please sign in to comment.