From cbc8243e3277a5b9f8a2d7f954dba643777fae0b Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Thu, 8 Aug 2024 11:53:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9ohos=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E7=BA=A7=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=97=B6=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- .../lib/src/ohos/ohos_plugins_manager.dart | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/flutter_tools/lib/src/ohos/ohos_plugins_manager.dart b/packages/flutter_tools/lib/src/ohos/ohos_plugins_manager.dart index e4e8e2ddf5..0a89fe2dd6 100644 --- a/packages/flutter_tools/lib/src/ohos/ohos_plugins_manager.dart +++ b/packages/flutter_tools/lib/src/ohos/ohos_plugins_manager.dart @@ -51,7 +51,7 @@ Future checkOhosPluginsDependencies(FlutterProject flutterProject) async { if (flutterProject.isModule) { dependencies[plugin.name] = 'file:$absolutePath'; } else { - final String relativePath = globals.fs.path.relative(absolutePath, from: globals.fs.path.dirname(packageFile.path)); + final String relativePath = _relative(absolutePath, from: globals.fs.path.dirname(packageFile.path)); dependencies[plugin.name] = 'file:$relativePath'; } } @@ -86,13 +86,14 @@ Future addPluginsModules(FlutterProject flutterProject) async { } modules.add({ 'name': plugin.name, - 'srcPath': globals.fs.path.join(plugin.path, OhosPlugin.kConfigKey), + 'srcPath': _relative( + globals.fs.path.join(plugin.path, OhosPlugin.kConfigKey), + from: flutterProject.ohos.ohosRoot.path, + ), 'targets': >[ { 'name': 'default', - 'applyToProducts': [ - 'default' - ] + 'applyToProducts': ['default'] } ], }); @@ -119,9 +120,12 @@ Future addFlutterModuleAndPluginsSrcOverrides(FlutterProject flutterProjec final Map overrides = config['overrides'] as Map? ?? {}; for (final Plugin plugin in plugins) { - overrides[plugin.name] = globals.fs.path.join(plugin.path, OhosPlugin.kConfigKey); + overrides[plugin.name] = _relative( + globals.fs.path.join(plugin.path, OhosPlugin.kConfigKey), + from: flutterProject.ohos.ohosRoot.path, + ); } - final String relativePath = globals.fs.path.relative(flutterProject.ohos.flutterModuleDirectory.path, from: flutterProject.ohos.ohosRoot.path); + final String relativePath = _relative(flutterProject.ohos.flutterModuleDirectory.path, from: flutterProject.ohos.ohosRoot.path); overrides['@ohos/flutter_module'] = 'file:./$relativePath'; overrides['@ohos/flutter_ohos'] = 'file:./har/flutter.har'; final String configNew = const JsonEncoder.withIndent(' ').convert(config); @@ -189,3 +193,7 @@ Future addFlutterModuleAndPluginsOverrides(FlutterProject flutterProject) final String configNew = const JsonEncoder.withIndent(' ').convert(config); packageFile.writeAsStringSync(configNew, flush: true); } + +String _relative(String path, {String? from}) { + return globals.fs.path.relative(path, from: from).replaceAll(r'\', '/'); +} -- Gitee