android flutter plugin

This commit is contained in:
John Smith 2022-01-29 18:50:38 -05:00
parent 32908dd719
commit a5e4e5c908
11 changed files with 147 additions and 20 deletions

63
Cargo.lock generated
View File

@ -77,6 +77,15 @@ dependencies = [
"memchr",
]
[[package]]
name = "allo-isolate"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31644a919a9e4b0188e4569e55bbf5a78b5588ea645acffc15c29240407261bc"
dependencies = [
"atomic",
]
[[package]]
name = "alloc_counter"
version = "0.0.4"
@ -121,6 +130,9 @@ name = "anyhow"
version = "1.0.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0"
dependencies = [
"backtrace",
]
[[package]]
name = "arraydeque"
@ -355,6 +367,15 @@ dependencies = [
"rustc_version",
]
[[package]]
name = "atomic"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c"
dependencies = [
"autocfg",
]
[[package]]
name = "atomic-waker"
version = "1.0.0"
@ -1393,6 +1414,26 @@ dependencies = [
"yansi",
]
[[package]]
name = "flutter_rust_bridge"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39ad509fe9fd3ac5a4d10a30a7de9224b74192c65c22338cc958ab0f93f0c834"
dependencies = [
"allo-isolate",
"anyhow",
"flutter_rust_bridge_macros",
"lazy_static",
"parking_lot 0.11.2",
"threadpool",
]
[[package]]
name = "flutter_rust_bridge_macros"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99a2555456c9c12c5982543c61d79267327d522eaa1490ef4914f5ed87b16fe1"
[[package]]
name = "fnv"
version = "1.0.7"
@ -3583,6 +3624,15 @@ dependencies = [
"syn",
]
[[package]]
name = "threadpool"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa"
dependencies = [
"num_cpus",
]
[[package]]
name = "time"
version = "0.1.43"
@ -3910,6 +3960,19 @@ dependencies = [
"x25519-dalek-ng",
]
[[package]]
name = "veilid-flutter"
version = "0.1.0"
dependencies = [
"anyhow",
"async-std",
"cfg-if 1.0.0",
"flutter_rust_bridge",
"log",
"parking_lot 0.12.0",
"veilid-core",
]
[[package]]
name = "veilid-server"
version = "0.1.0"

View File

@ -3,10 +3,11 @@
members = [
"veilid-core",
"veilid-server",
"veilid-cli"
"veilid-cli",
"veilid-flutter/rust"
]
exclude = [ "./external/keyring-rs", "./external/netlink", "./external/cursive", "./veilid-flutter" ]
exclude = [ "./external/keyring-rs", "./external/netlink", "./external/cursive" ]
[patch.crates-io]
cursive = { path = "./external/cursive/cursive" }

@ -1 +1 @@
Subproject commit 1295d708ec42542f076a13db69eadc448a94f985
Subproject commit 935ca957d7e223ef560a0b20b656730a325e0ba7

View File

@ -6,3 +6,4 @@
.DS_Store
/build
/captures
.cxx

View File

@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.1)
project(cpplink CXX)
add_library(cpplink cpplink.cpp)

View File

@ -1,6 +1,3 @@
group 'com.veilid.veilid'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
@ -14,6 +11,13 @@ buildscript {
}
}
plugins {
id "org.mozilla.rust-android-gradle.rust-android" version "0.9.0"
}
group 'com.veilid.veilid'
version '1.0-SNAPSHOT'
rootProject.allprojects {
repositories {
google()
@ -41,10 +45,60 @@ android {
}
defaultConfig {
minSdkVersion 16
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.0"
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
// Required to copy libc++_shared.so
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
targets "cpplink"
}
}
}
ndkVersion '22.0.7026061'
// Required to copy libc++_shared.so
externalNativeBuild {
cmake {
path file('CMakeLists.txt')
}
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
apply plugin: 'org.mozilla.rust-android-gradle.rust-android'
cargo {
module = "../rust"
libname = "veilid_flutter"
targets = ["arm", "arm64", "x86", "x86_64"]
targetDirectory = "../../target"
prebuiltToolchains = true
profile = gradle.startParameter.taskNames.any{it.toLowerCase().contains("debug")} ? "debug" : "release"
// features {
// defaultAnd("android_tests")
// }
}
afterEvaluate {
// The `cargoBuild` task isn't available until after evaluation.
android.libraryVariants.all { variant ->
def productFlavor = ""
variant.productFlavors.each {
productFlavor += "${it.name.capitalize()}"
}
def buildType = "${variant.buildType.name.capitalize()}"
tasks["generate${productFlavor}${buildType}Assets"].dependsOn(tasks["cargoBuild"])
}
}

View File

View File

@ -14,22 +14,22 @@ class VeilidPlugin: FlutterPlugin, MethodCallHandler {
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private lateinit var channel : MethodChannel
// private lateinit var channel : MethodChannel
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "veilid")
channel.setMethodCallHandler(this)
// channel = MethodChannel(flutterPluginBinding.binaryMessenger, "veilid")
// channel.setMethodCallHandler(this)
}
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if (call.method == "getPlatformVersion") {
result.success("Android ${android.os.Build.VERSION.RELEASE}")
} else {
result.notImplemented()
}
// if (call.method == "getPlatformVersion") {
// result.success("Android ${android.os.Build.VERSION.RELEASE}")
// } else {
result.notImplemented()
// }
}
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
// channel.setMethodCallHandler(null)
}
}

View File

@ -44,8 +44,8 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.veilid.veilid_example"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
minSdkVersion Math.max(flutter.minSdkVersion, 24)
targetSdkVersion Math.max(flutter.targetSdkVersion, 30)
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

View File

@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.veilid.veilid_example">
<application
<application
android:label="veilid_example"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
@ -31,4 +31,9 @@
android:name="flutterEmbedding"
android:value="2" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</manifest>

View File

@ -14,7 +14,7 @@ fn resolve_llvm_path() -> Option<PathBuf> {
// find clang
let d = paths.iter().find_map(|p| {
if p.join("clang").exists() {
if let Ok(real_clang_path) = fs::canonicalize(p.join("clang")) {
if let Ok(real_clang_path) = std::fs::canonicalize(p.join("clang")) {
if let Some(llvmbindir) = real_clang_path.parent() {
if let Some(llvmdir) = llvmbindir.parent() {
return Some(llvmdir.to_owned());