diff --git a/.gitignore b/.gitignore
index 4341a5df..08b7dbe9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,7 +9,7 @@
build/
.env
-pubspec.lock
+**/pubspec.lock
rust/target
rust/Cargo.lock
@@ -30,7 +30,6 @@ _main.dart
*.log
*.pyc
*.swp
-.DS_Store
.atom/
.buildlog/
.history
@@ -39,7 +38,6 @@ _main.dart
# IntelliJ related
*.ipr
*.iws
-.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
@@ -47,14 +45,9 @@ _main.dart
#.vscode/
# Flutter/Dart/Pub related
-pubspec.lock
pubspec_overrides.yaml
**/doc/api/
-.dart_tool/
-.packages
-build/
.pub-cache/
-.pub/
.flutter-plugins
.flutter-plugins-dependencies
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 326b990b..d419afc5 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -1,6 +1,8 @@
-include: package:flutter_lints/flutter.yaml
+include: package:lints/recommended.yaml
analyzer:
+ errors:
+ invalid_annotation_target: ignore
exclude:
- 'packages/**/**.g.dart'
- 'packages/**/**.freezed.dart'
diff --git a/melos.yaml b/melos.yaml
index 661a0d9b..060f2754 100644
--- a/melos.yaml
+++ b/melos.yaml
@@ -4,6 +4,9 @@ repository: https://github.com/AstroxNetwork/agent_dart
packages:
- packages/**
+ignore:
+ - 'packages/agent_dart/cargokit/build_tool'
+
ide:
intellij:
enabled: true
diff --git a/packages/agent_dart/agent_dart.iml b/packages/agent_dart/agent_dart.iml
index 8fd214fe..64d7623d 100644
--- a/packages/agent_dart/agent_dart.iml
+++ b/packages/agent_dart/agent_dart.iml
@@ -21,10 +21,13 @@
+
+
+
-
+
\ No newline at end of file
diff --git a/packages/agent_dart/android/CMakeLists.txt b/packages/agent_dart/android/CMakeLists.txt
deleted file mode 100644
index bba01cfa..00000000
--- a/packages/agent_dart/android/CMakeLists.txt
+++ /dev/null
@@ -1,34 +0,0 @@
-set(LibraryVersion "agent_dart-v0.0.0") # generated; do not edit
-
-# Unlike the Windows & Linux CMakeLists.txt, this Android equivalent is just here
-# to download the Android binaries into src/main/jniLibs/ and does not build anything.
-# The binary download/extraction is difficult to do concisely in Groovy/Gradle,
-# at least across host platforms, so we are just reusing our Linux/Windows logic.
-
-# 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.
-cmake_minimum_required(VERSION 3.10)
-
-# Project-level configuration.
-set(PROJECT_NAME "agent_dart") # Should match the name field in the pubspec.yaml.
-project(PROJECT_NAME)
-
-# Download the binaries if they are not already present.
-set(LibRoot "${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs")
-set(ArchivePath "${CMAKE_CURRENT_SOURCE_DIR}/${LibraryVersion}.tar.gz")
-if(NOT EXISTS ${ArchivePath})
- file(DOWNLOAD
- "https://github.com/AstroxNetwork/agent_dart/releases/download/${LibraryVersion}/android.tar.gz"
- ${ArchivePath}
- TLS_VERIFY ON
- )
-endif()
-
-# Extract the binaries, overriding any already present.
-file(REMOVE_RECURSE ${LibRoot})
-file(MAKE_DIRECTORY ${LibRoot})
-execute_process(
- COMMAND ${CMAKE_COMMAND} -E tar xzf ${ArchivePath}
- WORKING_DIRECTORY ${LibRoot}
-)
\ No newline at end of file
diff --git a/packages/agent_dart/android/build.gradle b/packages/agent_dart/android/build.gradle
index a50e5ff2..a1eacec8 100644
--- a/packages/agent_dart/android/build.gradle
+++ b/packages/agent_dart/android/build.gradle
@@ -1,16 +1,17 @@
+// The Android Gradle Plugin builds the native code with the Android NDK.
+
group 'com.astrox.agent_dart'
-version '1.0-SNAPSHOT'
+version '1.0.0-SNAPSHOT'
buildscript {
- ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:7.0.2'
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+ // The Android Gradle Plugin knows how to build native code with the NDK.
+ classpath 'com.android.tools.build:gradle:7.3.0'
}
}
@@ -22,22 +23,37 @@ rootProject.allprojects {
}
apply plugin: 'com.android.library'
-apply plugin: 'kotlin-android'
android {
- compileSdkVersion 31
+ if (project.android.hasProperty("namespace")) {
+ namespace 'com.astrox.agent_dart'
+ }
+
+ // Bumping the plugin compileSdkVersion requires all clients of this plugin
+ // to bump the version in their app.
+ compileSdkVersion 33
defaultConfig {
- minSdkVersion 16
+ minSdkVersion 19
}
- // Trigger the binary download/update over in CMakeLists.txt
- externalNativeBuild {
- cmake {
- path "CMakeLists.txt"
- }
+ // Use the NDK version
+ // declared in /android/app/build.gradle file of the Flutter project.
+ // Replace it with a version number if this plugin requires a specfic NDK version.
+ // (e.g. ndkVersion "23.1.7779620")
+ ndkVersion android.ndkVersion
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
}
+
+apply from: "../cargokit/gradle/plugin.gradle"
+cargokit {
+ manifestDir = "../../agent_dart_ffi/native/agent_dart"
+ libname = "agent_dart"
+}
diff --git a/packages/agent_dart/android/gradle.properties b/packages/agent_dart/android/gradle.properties
deleted file mode 100644
index 94adc3a3..00000000
--- a/packages/agent_dart/android/gradle.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-org.gradle.jvmargs=-Xmx1536M
-android.useAndroidX=true
-android.enableJetifier=true
diff --git a/packages/agent_dart/android/gradle/wrapper/gradle-wrapper.properties b/packages/agent_dart/android/gradle/wrapper/gradle-wrapper.properties
deleted file mode 100644
index 3c9d0852..00000000
--- a/packages/agent_dart/android/gradle/wrapper/gradle-wrapper.properties
+++ /dev/null
@@ -1,5 +0,0 @@
-distributionBase=GRADLE_USER_HOME
-distributionPath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
diff --git a/packages/agent_dart/android/src/main/kotlin/com/astrox/agent_dart/AgentDartPlugin.kt b/packages/agent_dart/android/src/main/kotlin/com/astrox/agent_dart/AgentDartPlugin.kt
deleted file mode 100644
index 29f095db..00000000
--- a/packages/agent_dart/android/src/main/kotlin/com/astrox/agent_dart/AgentDartPlugin.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.astrox.agent_dart
-
-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
-
-/** AgentDartPlugin */
-class AgentDartPlugin: 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, "agent_dart")
- 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/packages/agent_dart/cargokit/.gitignore b/packages/agent_dart/cargokit/.gitignore
new file mode 100644
index 00000000..cf145183
--- /dev/null
+++ b/packages/agent_dart/cargokit/.gitignore
@@ -0,0 +1,3 @@
+target
+.dart_tool
+*.iml
diff --git a/packages/agent_dart/cargokit/LICENSE b/packages/agent_dart/cargokit/LICENSE
new file mode 100644
index 00000000..d33a5fea
--- /dev/null
+++ b/packages/agent_dart/cargokit/LICENSE
@@ -0,0 +1,42 @@
+/// This is copied from Cargokit (which is the official way to use it currently)
+/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
+
+Copyright 2022 Matej Knopp
+
+================================================================================
+
+MIT LICENSE
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+================================================================================
+
+APACHE LICENSE, VERSION 2.0
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
diff --git a/packages/agent_dart/cargokit/README b/packages/agent_dart/cargokit/README
new file mode 100644
index 00000000..398474db
--- /dev/null
+++ b/packages/agent_dart/cargokit/README
@@ -0,0 +1,11 @@
+/// This is copied from Cargokit (which is the official way to use it currently)
+/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
+
+Experimental repository to provide glue for seamlessly integrating cargo build
+with flutter plugins and packages.
+
+See https://matejknopp.com/post/flutter_plugin_in_rust_with_no_prebuilt_binaries/
+for a tutorial on how to use Cargokit.
+
+Example plugin available at https://github.com/irondash/hello_rust_ffi_plugin.
+
diff --git a/packages/agent_dart/cargokit/build_pod.sh b/packages/agent_dart/cargokit/build_pod.sh
new file mode 100644
index 00000000..ed0e0d98
--- /dev/null
+++ b/packages/agent_dart/cargokit/build_pod.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+set -e
+
+BASEDIR=$(dirname "$0")
+
+# Workaround for https://github.com/dart-lang/pub/issues/4010
+BASEDIR=$(cd "$BASEDIR" ; pwd -P)
+
+# Remove XCode SDK from path. Otherwise this breaks tool compilation when building iOS project
+NEW_PATH=`echo $PATH | tr ":" "\n" | grep -v "Contents/Developer/" | tr "\n" ":"`
+
+export PATH=${NEW_PATH%?} # remove trailing :
+
+env
+
+# Platform name (macosx, iphoneos, iphonesimulator)
+export CARGOKIT_DARWIN_PLATFORM_NAME=$PLATFORM_NAME
+
+# Arctive architectures (arm64, armv7, x86_64), space separated.
+export CARGOKIT_DARWIN_ARCHS=$ARCHS
+
+# Current build configuration (Debug, Release)
+export CARGOKIT_CONFIGURATION=$CONFIGURATION
+
+# Path to directory containing Cargo.toml.
+export CARGOKIT_MANIFEST_DIR=$PODS_TARGET_SRCROOT/$1
+
+# Temporary directory for build artifacts.
+export CARGOKIT_TARGET_TEMP_DIR=$TARGET_TEMP_DIR
+
+# Output directory for final artifacts.
+export CARGOKIT_OUTPUT_DIR=$PODS_CONFIGURATION_BUILD_DIR/$PRODUCT_NAME
+
+# Directory to store built tool artifacts.
+export CARGOKIT_TOOL_TEMP_DIR=$TARGET_TEMP_DIR/build_tool
+
+# Directory inside root project. Not necessarily the top level directory of root project.
+export CARGOKIT_ROOT_PROJECT_DIR=$SRCROOT
+
+FLUTTER_EXPORT_BUILD_ENVIRONMENT=(
+ "$PODS_ROOT/../Flutter/ephemeral/flutter_export_environment.sh" # macOS
+ "$PODS_ROOT/../Flutter/flutter_export_environment.sh" # iOS
+)
+
+for path in "${FLUTTER_EXPORT_BUILD_ENVIRONMENT[@]}"
+do
+ if [[ -f "$path" ]]; then
+ source "$path"
+ fi
+done
+
+sh "$BASEDIR/run_build_tool.sh" build-pod "$@"
+
+# Make a symlink from built framework to phony file, which will be used as input to
+# build script. This should force rebuild (podspec currently doesn't support alwaysOutOfDate
+# attribute on custom build phase)
+ln -fs "$OBJROOT/XCBuildData/build.db" "${BUILT_PRODUCTS_DIR}/cargokit_phony"
+ln -fs "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}" "${BUILT_PRODUCTS_DIR}/cargokit_phony_out"
diff --git a/packages/agent_dart/cargokit/build_tool/README.md b/packages/agent_dart/cargokit/build_tool/README.md
new file mode 100644
index 00000000..a878c279
--- /dev/null
+++ b/packages/agent_dart/cargokit/build_tool/README.md
@@ -0,0 +1,5 @@
+/// This is copied from Cargokit (which is the official way to use it currently)
+/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
+
+A sample command-line application with an entrypoint in `bin/`, library code
+in `lib/`, and example unit test in `test/`.
diff --git a/packages/agent_dart/cargokit/build_tool/analysis_options.yaml b/packages/agent_dart/cargokit/build_tool/analysis_options.yaml
new file mode 100644
index 00000000..0e16a8b0
--- /dev/null
+++ b/packages/agent_dart/cargokit/build_tool/analysis_options.yaml
@@ -0,0 +1,34 @@
+# This is copied from Cargokit (which is the official way to use it currently)
+# Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
+
+# This file configures the static analysis results for your project (errors,
+# warnings, and lints).
+#
+# This enables the 'recommended' set of lints from `package:lints`.
+# This set helps identify many issues that may lead to problems when running
+# or consuming Dart code, and enforces writing Dart using a single, idiomatic
+# style and format.
+#
+# If you want a smaller set of lints you can change this to specify
+# 'package:lints/core.yaml'. These are just the most critical lints
+# (the recommended set includes the core lints).
+# The core lints are also what is used by pub.dev for scoring packages.
+
+include: package:lints/recommended.yaml
+
+# Uncomment the following section to specify additional rules.
+
+linter:
+ rules:
+ - prefer_relative_imports
+ - directives_ordering
+
+# analyzer:
+# exclude:
+# - path/to/excluded/files/**
+
+# For more information about the core and recommended set of lints, see
+# https://dart.dev/go/core-lints
+
+# For additional information about configuring this file, see
+# https://dart.dev/guides/language/analysis-options
diff --git a/packages/agent_dart/cargokit/build_tool/bin/build_tool.dart b/packages/agent_dart/cargokit/build_tool/bin/build_tool.dart
new file mode 100644
index 00000000..268eb524
--- /dev/null
+++ b/packages/agent_dart/cargokit/build_tool/bin/build_tool.dart
@@ -0,0 +1,8 @@
+/// This is copied from Cargokit (which is the official way to use it currently)
+/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
+
+import 'package:build_tool/build_tool.dart' as build_tool;
+
+void main(List arguments) {
+ build_tool.runMain(arguments);
+}
diff --git a/packages/agent_dart/cargokit/build_tool/lib/build_tool.dart b/packages/agent_dart/cargokit/build_tool/lib/build_tool.dart
new file mode 100644
index 00000000..7c1bb750
--- /dev/null
+++ b/packages/agent_dart/cargokit/build_tool/lib/build_tool.dart
@@ -0,0 +1,8 @@
+/// This is copied from Cargokit (which is the official way to use it currently)
+/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
+
+import 'src/build_tool.dart' as build_tool;
+
+Future runMain(List args) async {
+ return build_tool.runMain(args);
+}
diff --git a/packages/agent_dart/cargokit/build_tool/lib/src/android_environment.dart b/packages/agent_dart/cargokit/build_tool/lib/src/android_environment.dart
new file mode 100644
index 00000000..15fc9eed
--- /dev/null
+++ b/packages/agent_dart/cargokit/build_tool/lib/src/android_environment.dart
@@ -0,0 +1,195 @@
+/// This is copied from Cargokit (which is the official way to use it currently)
+/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
+
+import 'dart:io';
+import 'dart:isolate';
+import 'dart:math' as math;
+
+import 'package:collection/collection.dart';
+import 'package:path/path.dart' as path;
+import 'package:version/version.dart';
+
+import 'target.dart';
+import 'util.dart';
+
+class AndroidEnvironment {
+ AndroidEnvironment({
+ required this.sdkPath,
+ required this.ndkVersion,
+ required this.minSdkVersion,
+ required this.targetTempDir,
+ required this.target,
+ });
+
+ static void clangLinkerWrapper(List args) {
+ final clang = Platform.environment['_CARGOKIT_NDK_LINK_CLANG'];
+ if (clang == null) {
+ throw Exception(
+ "cargo-ndk rustc linker: didn't find _CARGOKIT_NDK_LINK_CLANG env var");
+ }
+ final target = Platform.environment['_CARGOKIT_NDK_LINK_TARGET'];
+ if (target == null) {
+ throw Exception(
+ "cargo-ndk rustc linker: didn't find _CARGOKIT_NDK_LINK_TARGET env var");
+ }
+
+ runCommand(clang, [
+ target,
+ ...args,
+ ]);
+ }
+
+ /// Full path to Android SDK.
+ final String sdkPath;
+
+ /// Full version of Android NDK.
+ final String ndkVersion;
+
+ /// Minimum supported SDK version.
+ final int minSdkVersion;
+
+ /// Target directory for build artifacts.
+ final String targetTempDir;
+
+ /// Target being built.
+ final Target target;
+
+ bool ndkIsInstalled() {
+ final ndkPath = path.join(sdkPath, 'ndk', ndkVersion);
+ final ndkPackageXml = File(path.join(ndkPath, 'package.xml'));
+ return ndkPackageXml.existsSync();
+ }
+
+ void installNdk({
+ required String javaHome,
+ }) {
+ final sdkManagerExtension = Platform.isWindows ? '.bat' : '';
+ final sdkManager = path.join(
+ sdkPath,
+ 'cmdline-tools',
+ 'latest',
+ 'bin',
+ 'sdkmanager$sdkManagerExtension',
+ );
+
+ log.info('Installing NDK $ndkVersion');
+ runCommand(sdkManager, [
+ '--install',
+ 'ndk;$ndkVersion',
+ ], environment: {
+ 'JAVA_HOME': javaHome,
+ });
+ }
+
+ Future