diff --git a/.gitignore b/.gitignore index 37e1713..59d1dcb 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ build/ .flutter-plugins .flutter-plugins-dependencies + +android/src/main/jniLibs/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..01500a7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "src/serai"] + path = src/serai + url = https://github.com/kayabaNerve/serai diff --git a/README.md b/README.md index 4982e83..834c8f5 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,13 @@ # frostdart -A new Flutter project. +Dart interface to the Serai FROST multisig implementation -## Getting Started +## Building -This project is a starting point for a Flutter -[FFI plugin](https://docs.flutter.dev/development/platform-integration/c-interop), -a specialized package that includes native code directly invoked with Dart FFI. - -## Project structure - -This template uses the following structure: - -* `src`: Contains the native source code, and a CmakeFile.txt file for building - that source code into a dynamic library. - -* `lib`: Contains the Dart code that defines the API of the plugin, and which - calls into the native code using `dart:ffi`. - -* platform folders (`android`, `ios`, `windows`, etc.): Contains the build files - for building and bundling the native code library with the platform application. - -## Building and bundling native code - -The `pubspec.yaml` specifies FFI plugins as follows: - -```yaml - plugin: - platforms: - some_platform: - ffiPlugin: true -``` - -This configuration invokes the native build for the various target platforms -and bundles the binaries in Flutter applications using these FFI plugins. - -This can be combined with dartPluginClass, such as when FFI is used for the -implementation of one platform in a federated plugin: - -```yaml - plugin: - implements: some_other_plugin - platforms: - some_platform: - dartPluginClass: SomeClass - ffiPlugin: true ``` - -A plugin can have both FFI and method channels: - -```yaml - plugin: - platforms: - some_platform: - pluginClass: SomeName - ffiPlugin: true +git clone https://www.github.com/cypherstack/frostdart +cd frostdart +git submodule update --init --recursive +cd scripts/[platform] +./build_all.sh ``` - -The native build systems that are invoked by FFI (and method channel) plugins are: - -* For Android: Gradle, which invokes the Android NDK for native builds. - * See the documentation in android/build.gradle. -* For iOS and MacOS: Xcode, via CocoaPods. - * See the documentation in ios/frostdart.podspec. - * See the documentation in macos/frostdart.podspec. -* For Linux and Windows: CMake. - * See the documentation in linux/CMakeLists.txt. - * See the documentation in windows/CMakeLists.txt. - -## Binding to native code - -To use the native code, bindings in Dart are needed. -To avoid writing these by hand, they are generated from the header file -(`src/frostdart.h`) by `package:ffigen`. -Regenerate the bindings by running `flutter pub run ffigen --config ffigen.yaml`. - -## Invoking native code - -Very short-running native functions can be directly invoked from any isolate. -For example, see `sum` in `lib/frostdart.dart`. - -Longer-running functions should be invoked on a helper isolate to avoid -dropping frames in Flutter applications. -For example, see `sumAsync` in `lib/frostdart.dart`. - -## Flutter help - -For help getting started with Flutter, view our -[online documentation](https://flutter.dev/docs), which offers tutorials, -samples, guidance on mobile development, and a full API reference. - diff --git a/android/build.gradle b/android/build.gradle index 4ef4c96..c65296e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -4,14 +4,15 @@ group 'com.example.frostdart' version '1.0' buildscript { + ext.kotlin_version = '1.7.10' repositories { google() mavenCentral() } dependencies { - // The Android Gradle Plugin knows how to build native code with the NDK. classpath 'com.android.tools.build:gradle:7.3.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -23,37 +24,31 @@ rootProject.allprojects { } apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' android { // Bumping the plugin compileSdkVersion requires all clients of this plugin // to bump the version in their app. compileSdkVersion 31 - // Bumping the plugin ndkVersion requires all clients of this plugin to bump - // the version in their app and to download a newer version of the NDK. - ndkVersion "23.1.7779620" - - // Invoke the shared CMake build with the Android Gradle Plugin. - externalNativeBuild { - cmake { - path "../src/CMakeLists.txt" - - // The default CMake version for the Android Gradle Plugin is 3.10.2. - // https://developer.android.com/studio/projects/install-ndk#vanilla_cmake - // - // The Flutter tooling requires that developers have CMake 3.10 or later - // installed. You should not increase this version, as doing so will cause - // the plugin to fail to compile for some customers of the plugin. - // version "3.10.2" - } - } - compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + kotlinOptions { + jvmTarget = '1.8' + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + defaultConfig { minSdkVersion 16 } } + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} diff --git a/android/src/main/kotlin/com/example/frostdart/FrostdartPlugin.kt b/android/src/main/kotlin/com/example/frostdart/FrostdartPlugin.kt new file mode 100644 index 0000000..cf19261 --- /dev/null +++ b/android/src/main/kotlin/com/example/frostdart/FrostdartPlugin.kt @@ -0,0 +1,35 @@ +package com.example.flutter_libepiccash + +import androidx.annotation.NonNull + +import io.flutter.embedding.engine.plugins.FlutterPlugin +import io.flutter.plugin.common.MethodCall +import io.flutter.plugin.common.MethodChannel +import io.flutter.plugin.common.MethodChannel.MethodCallHandler +import io.flutter.plugin.common.MethodChannel.Result + +/** FlutterLibepiccashPlugin */ +class FrostdartPlugin: FlutterPlugin, MethodCallHandler { + /// The MethodChannel that will the communication between Flutter and native Android + /// + /// 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 + + override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { + channel = MethodChannel(flutterPluginBinding.binaryMessenger, "frostdart") + 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() + } + } + + override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { + channel.setMethodCallHandler(null) + } +} diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml index 399f698..ab4c41f 100644 --- a/example/android/app/src/debug/AndroidManifest.xml +++ b/example/android/app/src/debug/AndroidManifest.xml @@ -1,4 +1,5 @@ - +