Skip to content

Commit

Permalink
voltron support dynamic library load (#3598)
Browse files Browse the repository at this point in the history
* feat(voltron): voltron support dynamic library load

* feat(voltron): voltron support dynamic library load
  • Loading branch information
lvfen authored Nov 8, 2023
1 parent 7aedc7c commit 3c1ef52
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 17 deletions.
8 changes: 4 additions & 4 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ CMakeLists.txt @ilikethese @etkmao
/framework/ios/ @wwwcg @ruifanyuan

# framework: voltron
/framework/voltron/ @lvfen @skindhu
/framework/voltron/ @lvfen @henryjin0511

# dom: others
/dom/ @etkmao @ilikethese
Expand All @@ -57,17 +57,17 @@ CMakeLists.txt @ilikethese @etkmao
/renderer/tdf/ios/ @wwwcg @ruifanyuan

# renderer: voltron
/renderer/voltron/ @lvfen @skindhu
/renderer/voltron/ @lvfen @henryjin0511

# module: vfs
/modules/vfs/ @etkmao @ilikethese
/modules/vfs/android/ @siguangli @iPel
/modules/vfs/android/**/src/main/cpp/ @etkmao @ilikethese
/modules/vfs/ios/ @wwwcg @ruifanyuan
/modules/vfs/voltron/ @lvfen @skindhu
/modules/vfs/voltron/ @lvfen @henryjin0511

# module: voltron
/modules/voltron/ @lvfen @skindhu
/modules/voltron/ @lvfen @henryjin0511

# module: android
/modules/android/ @siguangli @iPel
Expand Down
4 changes: 4 additions & 0 deletions framework/voltron/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 0.0.34

- support voltron dynamic library load

## 0.0.34

- update voltron_render to 0.0.24 to fix width calculate error and add modal navigator param

## 0.0.33
Expand Down
2 changes: 1 addition & 1 deletion framework/voltron/core/src/bridge/android/bridge_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void BridgeImpl::Destroy(int64_t scope_id,
voltron::EraseObject(footstone::checked_numeric_cast<
int64_t,
uint32_t>(scope_id));
JsDriverUtils::DestroyInstance(engine, scope, [callback](bool ret) {
JsDriverUtils::DestroyInstance(std::move(engine), std::move(scope), [callback](bool ret) {
if (ret) {
callback(INIT_CB_STATE::SUCCESS);
} else {
Expand Down
2 changes: 1 addition & 1 deletion framework/voltron/example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
15 changes: 15 additions & 0 deletions framework/voltron/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:voltron/voltron.dart';

import 'base_voltron_page.dart';

Expand All @@ -35,6 +37,7 @@ void main() {
systemNavigationBarColor: Color(0XFFE5E5E5),
));
}

runApp(MyApp());
}

Expand Down Expand Up @@ -89,6 +92,18 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
setLibrary();
}

void setLibrary() async {
// final path = (await getApplicationDocumentsDirectory()).path;
// 测试业务动态load library
// VoltronJSLoaderManager.initCustomLibrary(path: '$path/libs/arm64-v8a/', name: 'voltron_core');
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down
14 changes: 14 additions & 0 deletions framework/voltron/lib/voltron/loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// limitations under the License.
//

import 'package:voltron/voltron.dart';
import 'package:voltron_renderer/voltron_renderer.dart';

import '../engine.dart';
Expand All @@ -34,6 +35,19 @@ class VoltronJSLoaderManager {
_engine = VoltronJSEngine.create(params);
}

/// 自定义so或者dylib库路径和名称,可用于动态加载library库
/// 此方法需要在创建引擎前调用
/// 注意,调用此方法需要自己判断当前机器的cpu架构,否则会导致加载失败
/// 另外调用此方法需要保证路径和名称正确性,否则会导致加载失败
static void initCustomLibrary({required String path, required String name}) {
if (path.isNotEmpty) {
FfiManager.libPath = path;
}
if (name.isNotEmpty) {
FfiManager.libraryName = name;
}
}

// 框架初始化
static VoltronJSLoaderManager createLoaderManager(
EngineInitParams params,
Expand Down
8 changes: 4 additions & 4 deletions framework/voltron/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

name: voltron
description: A flutter plugin project to render hippy page.
version: 0.0.34
version: 0.0.36
homepage: https://hippyjs.org
repository: https://github.com/Tencent/Hippy

Expand Down Expand Up @@ -60,9 +60,9 @@ dependencies:
connectivity_plus: ^3.0.6
uuid: ^3.0.6
ffi: ^2.0.0
voltron_renderer: 0.0.24
voltron_vfs: 0.0.6
voltron_ffi: 0.0.5
voltron_renderer: 0.0.26
voltron_vfs: 0.0.7
voltron_ffi: 0.0.6

dev_dependencies:
flutter_test:
Expand Down
4 changes: 4 additions & 0 deletions modules/vfs/voltron/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.7

- update ffi_manager to 0.0.6

## 0.0.6

- fix build error
Expand Down
4 changes: 2 additions & 2 deletions modules/vfs/voltron/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

name: voltron_vfs
description: voltron vfs module
version: 0.0.6
version: 0.0.7
homepage: https://hippyjs.org
repository: https://github.com/Tencent/Hippy

Expand All @@ -34,4 +34,4 @@ dependencies:
flutter:
sdk: flutter
ffi: ^2.0.0
voltron_ffi: 0.0.5
voltron_ffi: 0.0.6
4 changes: 4 additions & 0 deletions modules/voltron/ffi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.6

- support dynamic library lib

## 0.0.5

- update ffi to 2.0.0
Expand Down
4 changes: 3 additions & 1 deletion modules/voltron/ffi/lib/ffi_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import 'global_callback.dart';
enum _DefaultRegisterFuncType { globalCallback }

class FfiManager {
static String libPath = '';
static String libraryName = 'voltron_core';
static const String _kDefaultRegisterHeader = 'default';
final _interactiveCppRequests = ReceivePort()..listen(requestExecuteCallback);

Expand All @@ -49,7 +51,7 @@ class FfiManager {

String get registerFuncName => 'AddCallFunc';

final DynamicLibrary _library = loadLibrary('voltron_core', isStatic: false);
final DynamicLibrary _library = loadLibrary(libraryName, isStatic: false, path: libPath);

FfiManager._internal() {
_initFfi = _library.lookupFunction<
Expand Down
2 changes: 1 addition & 1 deletion modules/voltron/ffi/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

name: voltron_ffi
description: voltron ffi module
version: 0.0.5
version: 0.0.6
homepage: https://hippyjs.org
repository: https://github.com/Tencent/Hippy

Expand Down
4 changes: 4 additions & 0 deletions renderer/voltron/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.26

- update ffi_manager to 0.0.6

## 0.0.24

- fix width calculate error and add modal navigator param
Expand Down
4 changes: 2 additions & 2 deletions renderer/voltron/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

name: voltron_renderer
description: voltron renderer
version: 0.0.24
version: 0.0.26
homepage: https://hippyjs.org
repository: https://github.com/Tencent/Hippy

Expand All @@ -46,7 +46,7 @@ dependencies:
waterfall_flow: ^3.0.2
charset: ^1.1.0
ffi: ^2.0.0
voltron_ffi: 0.0.5
voltron_ffi: 0.0.6

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 3c1ef52

Please sign in to comment.