add cwtch.aar and make sure is included in apk build from gradle (minor gradle fixes). Start restructuring main.dart to handle gomobile cwtch as well (but not done)

This commit is contained in:
Dan Ballard 2021-01-09 23:22:31 -08:00
parent 258093903f
commit 8d202cfaeb
13 changed files with 188 additions and 4 deletions

View File

@ -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')
}

View File

@ -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
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,2 @@
configurations.maybeCreate("default")
artifacts.add("default", file('cwtch.aar'))

BIN
android/cwtch/cwtch.aar Normal file

Binary file not shown.

View File

@ -1,4 +1,4 @@
include ':app'
include ':app', ':cwtch'
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()

View File

@ -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<Utf8> str, Int32 length);
typedef StartCwtchFn = void Function(Pointer<Utf8> dir, int len);
typedef access_cwtch_eventbus_function = Void Function();
typedef NextEventFn = void Function();
typedef get_json_blob_void_function = Pointer<Utf8> Function();
typedef GetJsonBlobVoidFn = Pointer<Utf8> Function();
typedef get_json_blob_string_function = Pointer<Utf8> Function(Pointer<Utf8> str, Int32 length);
typedef GetJsonBlobStringFn = Pointer<Utf8> Function(Pointer<Utf8> str,int len);
void main() => runApp(Flwtch());
@ -20,16 +41,56 @@ class FlwtchState extends State<Flwtch> {
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<String, String> 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<NativeFunction<start_cwtch_function>>("StartCwtch");
// ignore: non_constant_identifier_names
final StartCwtch = startCwtchC.asFunction<StartCwtchFn>();
var cwtchDir = "/home/sarah/.cwtch/dev/";
var cwtchDir = path.join(home, ".cwtch/dev/");
print("cwtchDir $cwtchDir");
StartCwtch(Utf8.toUtf8(cwtchDir), cwtchDir.length);
return Provider<FlwtchState>(

View File

@ -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"

View File

@ -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: