From ddeb80c41c3cf8e4f849b8da98cb099cf980d6dd Mon Sep 17 00:00:00 2001 From: xiaoxiaowesley Date: Mon, 26 Feb 2024 16:41:10 +0800 Subject: [PATCH] =?UTF-8?q?flutter=20plugin=E5=AF=B9=E4=BA=8Eflutter=5Foho?= =?UTF-8?q?s=E7=9A=84=E4=BE=9D=E8=B5=96=E6=94=B9=E6=88=90depedencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoxiaowesley --- .../lib/src/ohos/ohos_plugins_manager.dart | 22 +++++++++++++++++++ .../projectName.tmpl/oh-package.json5.tmpl | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) 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 e9cdfcf9ba..8bef3277fb 100644 --- a/packages/flutter_tools/lib/src/ohos/ohos_plugins_manager.dart +++ b/packages/flutter_tools/lib/src/ohos/ohos_plugins_manager.dart @@ -111,6 +111,7 @@ Future pluginsHarGenerate(String ohosPath, String pluginName, String moduleName, BuildInfo buildInfo, OhosBuildData ohosBuildData) async { final String modulePath = globals.fs.path.join(ohosPath, moduleName); checkDevDependencies(modulePath, buildInfo, ohosBuildData); + checkDependencies(modulePath, buildInfo, ohosBuildData); await ohpmInstall( processManager: globals.processManager, entryPath: modulePath, @@ -148,6 +149,27 @@ void checkDevDependencies( } } +/// 检查module的dependencies,如果存在 "@ohos/flutter_ohos": "file:./libs/flutter_ohos.har" , 拷贝har文件到module目录 +void checkDependencies( + String modulePath, BuildInfo buildInfo, OhosBuildData ohosBuildData) { + + globals.printStatus('checkDependencies 检查modulePath: $modulePath'); + final Directory moduleDirectory = globals.fs.directory(modulePath); + final File packageConfigFile = moduleDirectory.childFile('oh-package.json5'); + final List devDependencies = + getOhosDependenciesListFromPackageFile(packageConfigFile, + dependenceType: DependenceType.normal); + + /// 如果包含@ohos/flutter_ohos,每次构建,都需要重新拷贝har文件,确保flutter_embedding.har文件的正确性 + if (devDependencies.any( + (OhosDependence element) => element.moduleName == '@ohos/flutter_ohos')) { + final OhosDependence flutterOhosDepence = devDependencies.firstWhere( + (OhosDependence element) => element.moduleName == '@ohos/flutter_ohos'); + copyOhosEmbeddingHarToModule( + modulePath, flutterOhosDepence, buildInfo, ohosBuildData); + } +} + void copyOhosEmbeddingHarToModule( String modulePath, OhosDependence flutterOhosDepence, diff --git a/packages/flutter_tools/templates/plugin/ohos.tmpl/projectName.tmpl/oh-package.json5.tmpl b/packages/flutter_tools/templates/plugin/ohos.tmpl/projectName.tmpl/oh-package.json5.tmpl index ef6526586a..bcbbd9cdc1 100644 --- a/packages/flutter_tools/templates/plugin/ohos.tmpl/projectName.tmpl/oh-package.json5.tmpl +++ b/packages/flutter_tools/templates/plugin/ohos.tmpl/projectName.tmpl/oh-package.json5.tmpl @@ -5,7 +5,7 @@ "main": "index.ets", "author": "", "license": "Apache-2.0", - "devDependencies": { + "dependencies": { "@ohos/flutter_ohos": "file:./libs/flutter_ohos.har" } } -- Gitee