diff --git a/android/app/build.gradle b/android/app/build.gradle index 7fdfbbb..2a1e29c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -8,7 +8,7 @@ if (localPropertiesFile.exists()) { def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") + throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') @@ -30,6 +30,7 @@ android { sourceSets { main.java.srcDirs += 'src/main/kotlin' + main.jniLibs.srcDirs += 'src/main/libs' } lintOptions { @@ -60,4 +61,5 @@ flutter { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation project(':cwtch') } diff --git a/android/app/src/main/kotlin/com/example/flutter_app/MainActivity.kt b/android/app/src/main/kotlin/com/example/flutter_app/MainActivity.kt index 1ec9b09..4e50ae4 100644 --- a/android/app/src/main/kotlin/com/example/flutter_app/MainActivity.kt +++ b/android/app/src/main/kotlin/com/example/flutter_app/MainActivity.kt @@ -1,6 +1,40 @@ package com.example.flutter_app import io.flutter.embedding.android.FlutterActivity +import androidx.annotation.NonNull +import io.flutter.embedding.engine.FlutterEngine +import io.flutter.plugin.common.MethodChannel +import android.content.pm.PackageManager class MainActivity: FlutterActivity() { + + private val CHANNEL = "test.flutter.dev/applicationInfo" + private val CALL_NATIVE_LIB_DIR = "getNativeLibDir" + + override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) + MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { + // Note: this method is invoked on the main thread. + call, result -> + if (call.method == CALL_NATIVE_LIB_DIR) { + val nativeLibDir = getNativeLibDir() + + if (nativeLibDir != "") { + result.success(nativeLibDir) + } else { + result.error("UNAVAILABLE", "nativeLibDir not available.", null) + } + } else { + result.notImplemented() + } + } + } + + private fun getNativeLibDir(): String { + + val ainfo = this.applicationContext.packageManager.getApplicationInfo( + "com.example.flutter_app", // Must be app name + PackageManager.GET_SHARED_LIBRARY_FILES) + return ainfo.nativeLibraryDir + } } diff --git a/android/app/src/main/libs/arm64-v8a/libtor.so b/android/app/src/main/libs/arm64-v8a/libtor.so new file mode 100755 index 0000000..8c5a5fc Binary files /dev/null and b/android/app/src/main/libs/arm64-v8a/libtor.so differ diff --git a/android/app/src/main/libs/armeabi-v7a/libtor.so b/android/app/src/main/libs/armeabi-v7a/libtor.so new file mode 100755 index 0000000..f1f19c7 Binary files /dev/null and b/android/app/src/main/libs/armeabi-v7a/libtor.so differ diff --git a/android/app/src/main/libs/libCwtch-sources.jar b/android/app/src/main/libs/libCwtch-sources.jar new file mode 100644 index 0000000..e0e1fbb Binary files /dev/null and b/android/app/src/main/libs/libCwtch-sources.jar differ diff --git a/android/app/src/main/libs/libCwtch.aar b/android/app/src/main/libs/libCwtch.aar new file mode 100644 index 0000000..b52b15d Binary files /dev/null and b/android/app/src/main/libs/libCwtch.aar differ diff --git a/android/app/src/main/libs/libCwtch_go.apk b/android/app/src/main/libs/libCwtch_go.apk new file mode 100644 index 0000000..599e80e Binary files /dev/null and b/android/app/src/main/libs/libCwtch_go.apk differ diff --git a/android/cwtch/build.gradle b/android/cwtch/build.gradle new file mode 100644 index 0000000..74cef2b --- /dev/null +++ b/android/cwtch/build.gradle @@ -0,0 +1,2 @@ +configurations.maybeCreate("default") +artifacts.add("default", file('cwtch.aar')) \ No newline at end of file diff --git a/android/cwtch/cwtch.aar b/android/cwtch/cwtch.aar new file mode 100644 index 0000000..8518cd3 Binary files /dev/null and b/android/cwtch/cwtch.aar differ diff --git a/android/settings.gradle b/android/settings.gradle index 44e62bc..f847feb 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,4 +1,4 @@ -include ':app' +include ':app', ':cwtch' def localPropertiesFile = new File(rootProject.projectDir, "local.properties") def properties = new Properties() diff --git a/lib/main.dart b/lib/main.dart index 8aa3a08..8d34ecb 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,27 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'model.dart'; import 'views/profilemgrview.dart'; +import 'package:flutter/services.dart'; +import 'dart:io' show Platform; +import 'package:path/path.dart' as path; +import 'package:path_provider/path_provider.dart'; +import 'model.dart' as model; +import 'dart:collection'; +import 'dart:convert'; +import 'package:flutter/material.dart'; + +typedef start_cwtch_function = Void Function(Pointer str, Int32 length); +typedef StartCwtchFn = void Function(Pointer dir, int len); + +typedef access_cwtch_eventbus_function = Void Function(); +typedef NextEventFn = void Function(); + + +typedef get_json_blob_void_function = Pointer Function(); +typedef GetJsonBlobVoidFn = Pointer Function(); + +typedef get_json_blob_string_function = Pointer Function(Pointer str, Int32 length); +typedef GetJsonBlobStringFn = Pointer Function(Pointer str,int len); void main() => runApp(Flwtch()); @@ -20,16 +41,56 @@ class FlwtchState extends State { DynamicLibrary library; AppModel appStatus; + static const appInfoPlatform = const MethodChannel('test.flutter.dev/applicationInfo'); + var androidLibraryDir = ""; + var androidHomeDirectory = ""; + + @override + initState() { + super.initState(); + + if (Platform.isAndroid) { + getApplicationDocumentsDirectory().then((directory) => + { + setState(() { + print("androidHomeDir = $directory"); + androidHomeDirectory = directory.path; + }) + }); + + appInfoPlatform.invokeMethod('getNativeLibDir').then((value) => + { + setState(() { + print("nativeLibraryDir = $value"); + androidLibraryDir = value; + }) + }); + } + } + @override Widget build(BuildContext context) { library = DynamicLibrary.open("libCwtch.so"); appStatus = AppModel(library: library); + String home = ""; + Map envVars = Platform.environment; + if (Platform.isMacOS) { + home = envVars['HOME']; + } else if (Platform.isLinux) { + home = envVars['HOME']; + } else if (Platform.isWindows) { + home = envVars['UserProfile']; + } else if (Platform.isAndroid) { + home = androidHomeDirectory; + } + var startCwtchC = library.lookup>("StartCwtch"); // ignore: non_constant_identifier_names final StartCwtch = startCwtchC.asFunction(); - var cwtchDir = "/home/sarah/.cwtch/dev/"; + var cwtchDir = path.join(home, ".cwtch/dev/"); + print("cwtchDir $cwtchDir"); StartCwtch(Utf8.toUtf8(cwtchDir), cwtchDir.length); return Provider( diff --git a/pubspec.lock b/pubspec.lock index e31c28e..b0f27a8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -64,6 +64,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.3" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "5.2.1" flutter: dependency: "direct main" description: flutter @@ -74,6 +81,13 @@ packages: description: flutter source: sdk version: "0.0.0" + intl: + dependency: transitive + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.1" matcher: dependency: transitive description: @@ -102,6 +116,62 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0-nullsafety.3" + path_provider: + dependency: "direct main" + description: + name: path_provider + url: "https://pub.dartlang.org" + source: hosted + version: "1.6.27" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+2" + path_provider_macos: + dependency: transitive + description: + name: path_provider_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.4+8" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.4+3" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.13" provider: dependency: "direct main" description: @@ -170,6 +240,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0-nullsafety.5" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "1.7.4" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2" sdks: dart: ">=2.12.0-0.0 <3.0.0" - flutter: ">=1.16.0" + flutter: ">=1.16.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 407f55e..7a47790 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -30,6 +30,7 @@ dependencies: # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.0 ffi: ^0.1.3 + path_provider: ^1.6.27 dev_dependencies: flutter_test: