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 e4e8e2ddf57b3699a964bf7ac1f81b890b1c2867..0a89fe2dd6c1de1d0b04f9aafa7a190d9d7d772f 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'\', '/'); +}