From a318cc22f1d6766362fbc0df96a106e317ed478d Mon Sep 17 00:00:00 2001 From: hyiso Date: Fri, 10 May 2024 19:15:20 +0800 Subject: [PATCH] =?UTF-8?q?Flutter=20=E4=BE=9D=E8=B5=96=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20flutter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hyiso --- .../flutter_tools/lib/src/flutter_plugins.dart | 2 +- .../lib/src/ohos/ohos_plugins_manager.dart | 17 ++++++++++++++++- .../main/ets/entryability/EntryAbility.ets.tmpl | 2 +- .../entry/src/main/ets/pages/Index.ets.tmpl | 2 +- .../app_shared/ohos.tmpl/oh-package.json5.tmpl | 4 ++-- .../entry.tmpl/oh-package.json5.tmpl | 2 +- .../main/ets/entryability/EntryAbility.ets.tmpl | 2 +- .../src/main/ets/pages/Index.ets.tmpl | 2 +- .../flutter_module.tmpl/oh-package.json5.tmpl | 4 ++-- .../plugin/ohos.tmpl/oh-package.json5.tmpl | 2 +- .../ets/components/plugin/pluginClass.ets.tmpl | 2 +- .../src/main/ets/entryability/EntryAbility.ets | 2 +- .../ohos/entry/src/main/ets/pages/Index.ets | 2 +- .../example/ohos/oh-package.json5 | 4 ++-- packages/integration_test/ohos/oh-package.json5 | 2 +- .../FlutterDeviceScreenshot.ets | 2 +- .../integration_test/IntegrationTestPlugin.ets | 2 +- 17 files changed, 35 insertions(+), 20 deletions(-) diff --git a/packages/flutter_tools/lib/src/flutter_plugins.dart b/packages/flutter_tools/lib/src/flutter_plugins.dart index c9812ad870..caf80406d7 100644 --- a/packages/flutter_tools/lib/src/flutter_plugins.dart +++ b/packages/flutter_tools/lib/src/flutter_plugins.dart @@ -527,7 +527,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { '''; const String _arktsPluginRegistryTemplate = ''' -import { FlutterEngine, Log } from '@ohos/flutter_ohos'; +import { FlutterEngine, Log } from 'flutter'; {{#methodChannelPlugins}} import {{class}} from '{{name}}'; {{/methodChannelPlugins}} 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 e38f461d4b..787196b691 100644 --- a/packages/flutter_tools/lib/src/ohos/ohos_plugins_manager.dart +++ b/packages/flutter_tools/lib/src/ohos/ohos_plugins_manager.dart @@ -16,6 +16,7 @@ import 'dart:convert'; import 'package:json5/json5.dart'; +import 'package:path/path.dart'; import '../base/common.dart'; import '../base/file_system.dart'; @@ -143,7 +144,11 @@ Future addPluginsOverrides(FlutterProject flutterProject) async { final Map overrides = config['overrides'] as Map? ?? {}; for (final Plugin plugin in plugins) { - overrides[plugin.name] = globals.fs.path.join(plugin.path, OhosPlugin.kConfigKey); + final String pluginOhos = globals.fs.path.join(plugin.path, OhosPlugin.kConfigKey); + overrides[plugin.name] = pluginOhos; + if (useDeprecatedFlutterDependency(globals.fs.file(join(pluginOhos, 'oh-package.json5')))) { + globals.printWarning('OhosDependenciesManager: ${plugin.name} is using deprecated "@ohos/flutter_ohos", change to "flutter" instead.'); + } } final String configNew = const JsonEncoder.withIndent(' ').convert(config); packageFile.writeAsStringSync(configNew, flush: true); @@ -173,3 +178,13 @@ Future removePluginsOverrides(FlutterProject flutterProject) async { final String configNew = const JsonEncoder.withIndent(' ').convert(config); packageFile.writeAsStringSync(configNew, flush: true); } + + +/// 检查对 Flutter 的依赖是否是 @ohos/flutter_ohos +bool useDeprecatedFlutterDependency(File packageFile) { + final String packageConfig = packageFile.readAsStringSync(); + final Map config = JSON5.parse(packageConfig) as Map; + final Map dependencies = config['dependencies'] as Map? ?? + {}; + return dependencies.containsKey('@ohos/flutter_ohos'); +} \ No newline at end of file diff --git a/packages/flutter_tools/templates/app_shared/ohos.tmpl/entry/src/main/ets/entryability/EntryAbility.ets.tmpl b/packages/flutter_tools/templates/app_shared/ohos.tmpl/entry/src/main/ets/entryability/EntryAbility.ets.tmpl index 8bc48be877..4621102264 100644 --- a/packages/flutter_tools/templates/app_shared/ohos.tmpl/entry/src/main/ets/entryability/EntryAbility.ets.tmpl +++ b/packages/flutter_tools/templates/app_shared/ohos.tmpl/entry/src/main/ets/entryability/EntryAbility.ets.tmpl @@ -13,7 +13,7 @@ * limitations under the License. */ -import { FlutterAbility, FlutterEngine } from '@ohos/flutter_ohos'; +import { FlutterAbility, FlutterEngine } from 'flutter'; import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant'; export default class EntryAbility extends FlutterAbility { diff --git a/packages/flutter_tools/templates/app_shared/ohos.tmpl/entry/src/main/ets/pages/Index.ets.tmpl b/packages/flutter_tools/templates/app_shared/ohos.tmpl/entry/src/main/ets/pages/Index.ets.tmpl index 1125f9fdd9..bcff3c137a 100644 --- a/packages/flutter_tools/templates/app_shared/ohos.tmpl/entry/src/main/ets/pages/Index.ets.tmpl +++ b/packages/flutter_tools/templates/app_shared/ohos.tmpl/entry/src/main/ets/pages/Index.ets.tmpl @@ -14,7 +14,7 @@ */ import common from '@ohos.app.ability.common'; -import { FlutterPage } from '@ohos/flutter_ohos' +import { FlutterPage } from 'flutter'; let storage = LocalStorage.getShared() const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS' diff --git a/packages/flutter_tools/templates/app_shared/ohos.tmpl/oh-package.json5.tmpl b/packages/flutter_tools/templates/app_shared/ohos.tmpl/oh-package.json5.tmpl index 63ea525b73..1862c1706b 100644 --- a/packages/flutter_tools/templates/app_shared/ohos.tmpl/oh-package.json5.tmpl +++ b/packages/flutter_tools/templates/app_shared/ohos.tmpl/oh-package.json5.tmpl @@ -21,12 +21,12 @@ "author": "", "license": "", "dependencies": { - "@ohos/flutter_ohos": "file:./har/flutter.har" + "flutter": "file:./har/flutter.har" }, "devDependencies": { "@ohos/hypium": "1.0.6" }, "overrides": { - "@ohos/flutter_ohos": "file:./har/flutter.har" + "flutter": "file:./har/flutter.har" } } diff --git a/packages/flutter_tools/templates/module/ohos/host_app_common/entry.tmpl/oh-package.json5.tmpl b/packages/flutter_tools/templates/module/ohos/host_app_common/entry.tmpl/oh-package.json5.tmpl index 6f7b62b27e..415bab49a2 100644 --- a/packages/flutter_tools/templates/module/ohos/host_app_common/entry.tmpl/oh-package.json5.tmpl +++ b/packages/flutter_tools/templates/module/ohos/host_app_common/entry.tmpl/oh-package.json5.tmpl @@ -22,7 +22,7 @@ "license": "", "dependencies": { "@ohos/flutter_module": "../flutter_module", - '@ohos/flutter_ohos': 'file:../flutter_module/har/flutter.har', + 'flutter': 'file:../flutter_module/har/flutter.har', } } diff --git a/packages/flutter_tools/templates/module/ohos/host_app_common/entry.tmpl/src/main/ets/entryability/EntryAbility.ets.tmpl b/packages/flutter_tools/templates/module/ohos/host_app_common/entry.tmpl/src/main/ets/entryability/EntryAbility.ets.tmpl index cfcd3afd2a..aaedf7fc69 100644 --- a/packages/flutter_tools/templates/module/ohos/host_app_common/entry.tmpl/src/main/ets/entryability/EntryAbility.ets.tmpl +++ b/packages/flutter_tools/templates/module/ohos/host_app_common/entry.tmpl/src/main/ets/entryability/EntryAbility.ets.tmpl @@ -13,7 +13,7 @@ * limitations under the License. */ -import { FlutterAbility } from '@ohos/flutter_ohos' +import { FlutterAbility } from 'flutter' export default class EntryAbility extends FlutterAbility { } diff --git a/packages/flutter_tools/templates/module/ohos/host_app_common/entry.tmpl/src/main/ets/pages/Index.ets.tmpl b/packages/flutter_tools/templates/module/ohos/host_app_common/entry.tmpl/src/main/ets/pages/Index.ets.tmpl index 1125f9fdd9..248d9b0b06 100644 --- a/packages/flutter_tools/templates/module/ohos/host_app_common/entry.tmpl/src/main/ets/pages/Index.ets.tmpl +++ b/packages/flutter_tools/templates/module/ohos/host_app_common/entry.tmpl/src/main/ets/pages/Index.ets.tmpl @@ -14,7 +14,7 @@ */ import common from '@ohos.app.ability.common'; -import { FlutterPage } from '@ohos/flutter_ohos' +import { FlutterPage } from 'flutter' let storage = LocalStorage.getShared() const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS' diff --git a/packages/flutter_tools/templates/module/ohos/module_library/flutter_module.tmpl/oh-package.json5.tmpl b/packages/flutter_tools/templates/module/ohos/module_library/flutter_module.tmpl/oh-package.json5.tmpl index 1fa6a4dfea..ab38f86672 100644 --- a/packages/flutter_tools/templates/module/ohos/module_library/flutter_module.tmpl/oh-package.json5.tmpl +++ b/packages/flutter_tools/templates/module/ohos/module_library/flutter_module.tmpl/oh-package.json5.tmpl @@ -21,7 +21,7 @@ "author": "", "license": "OpenValley", "dependencies": { - "@ohos/flutter_ohos": "file:../har/flutter.har" - }, + "flutter": "file:../har/flutter.har" + } } diff --git a/packages/flutter_tools/templates/plugin/ohos.tmpl/oh-package.json5.tmpl b/packages/flutter_tools/templates/plugin/ohos.tmpl/oh-package.json5.tmpl index bc5113b4e1..e77f195a01 100644 --- a/packages/flutter_tools/templates/plugin/ohos.tmpl/oh-package.json5.tmpl +++ b/packages/flutter_tools/templates/plugin/ohos.tmpl/oh-package.json5.tmpl @@ -6,6 +6,6 @@ "author": "", "license": "Apache-2.0", "dependencies": { - "@ohos/flutter_ohos": "file:./har/flutter.har" + "flutter": "file:./har/flutter.har" } } diff --git a/packages/flutter_tools/templates/plugin/ohos.tmpl/src/main/ets/components/plugin/pluginClass.ets.tmpl b/packages/flutter_tools/templates/plugin/ohos.tmpl/src/main/ets/components/plugin/pluginClass.ets.tmpl index cc521f51b2..318356e4ee 100644 --- a/packages/flutter_tools/templates/plugin/ohos.tmpl/src/main/ets/components/plugin/pluginClass.ets.tmpl +++ b/packages/flutter_tools/templates/plugin/ohos.tmpl/src/main/ets/components/plugin/pluginClass.ets.tmpl @@ -5,7 +5,7 @@ import { MethodCallHandler, MethodChannel, MethodResult, -} from '@ohos/flutter_ohos'; +} from 'flutter'; /** {{pluginClass}} **/ export default class {{pluginClass}} implements FlutterPlugin, MethodCallHandler { diff --git a/packages/integration_test/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets b/packages/integration_test/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets index 8bc48be877..4621102264 100644 --- a/packages/integration_test/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets +++ b/packages/integration_test/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { FlutterAbility, FlutterEngine } from '@ohos/flutter_ohos'; +import { FlutterAbility, FlutterEngine } from 'flutter'; import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant'; export default class EntryAbility extends FlutterAbility { diff --git a/packages/integration_test/example/ohos/entry/src/main/ets/pages/Index.ets b/packages/integration_test/example/ohos/entry/src/main/ets/pages/Index.ets index ac2b5dc723..bcff3c137a 100644 --- a/packages/integration_test/example/ohos/entry/src/main/ets/pages/Index.ets +++ b/packages/integration_test/example/ohos/entry/src/main/ets/pages/Index.ets @@ -14,7 +14,7 @@ */ import common from '@ohos.app.ability.common'; -import { FlutterPage } from '@ohos/flutter_ohos'; +import { FlutterPage } from 'flutter'; let storage = LocalStorage.getShared() const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS' diff --git a/packages/integration_test/example/ohos/oh-package.json5 b/packages/integration_test/example/ohos/oh-package.json5 index f039c73b02..2bd6e8250e 100644 --- a/packages/integration_test/example/ohos/oh-package.json5 +++ b/packages/integration_test/example/ohos/oh-package.json5 @@ -6,12 +6,12 @@ "author": "", "license": "", "dependencies": { - "@ohos/flutter_ohos": "file:./har/flutter.har" + "flutter": "file:./har/flutter.har" }, "devDependencies": { "@ohos/hypium": "1.0.6" }, "overrides": { - "@ohos/flutter_ohos": "file:./har/flutter.har" + "flutter": "file:./har/flutter.har" } } \ No newline at end of file diff --git a/packages/integration_test/ohos/oh-package.json5 b/packages/integration_test/ohos/oh-package.json5 index de39e1c92f..bc9968565b 100644 --- a/packages/integration_test/ohos/oh-package.json5 +++ b/packages/integration_test/ohos/oh-package.json5 @@ -6,6 +6,6 @@ "author": "", "license": "Apache-2.0", "dependencies": { - "@ohos/flutter_ohos": "file:har/flutter.har", + "flutter": "file:har/flutter.har", } } diff --git a/packages/integration_test/ohos/src/main/ets/components/integration_test/FlutterDeviceScreenshot.ets b/packages/integration_test/ohos/src/main/ets/components/integration_test/FlutterDeviceScreenshot.ets index ea9629b059..55387a3676 100644 --- a/packages/integration_test/ohos/src/main/ets/components/integration_test/FlutterDeviceScreenshot.ets +++ b/packages/integration_test/ohos/src/main/ets/components/integration_test/FlutterDeviceScreenshot.ets @@ -15,7 +15,7 @@ import { MethodChannel, MethodResult, -} from '@ohos/flutter_ohos'; +} from 'flutter'; import UIAbility from '@ohos.app.ability.UIAbility'; /** diff --git a/packages/integration_test/ohos/src/main/ets/components/integration_test/IntegrationTestPlugin.ets b/packages/integration_test/ohos/src/main/ets/components/integration_test/IntegrationTestPlugin.ets index 1b9bf02b13..64db195e87 100644 --- a/packages/integration_test/ohos/src/main/ets/components/integration_test/IntegrationTestPlugin.ets +++ b/packages/integration_test/ohos/src/main/ets/components/integration_test/IntegrationTestPlugin.ets @@ -24,7 +24,7 @@ import { MethodCallHandler, MethodChannel, MethodResult, -} from '@ohos/flutter_ohos'; +} from 'flutter'; import UIAbility from '@ohos.app.ability.UIAbility'; const TAG = "IntegrationTestPlugin" -- Gitee