From f71af727c433037f1f36ca9ddfdf606e360d4a87 Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Sat, 7 Sep 2024 11:22:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=9D=E6=8C=81debug=E4=B8=8Erelease?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96engine=E6=97=B6=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cjand <1747143535@qq.com> --- .../embedding/engine/loader/FlutterLoader.ets | 24 +++++++++---------- .../ets/embedding/ohos/FlutterAbility.ets | 11 +++++---- .../ohos/FlutterAbilityAndEntryDelegate.ets | 23 +++++++----------- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets index aaeb579a61..6ee6566ca5 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets @@ -96,7 +96,7 @@ export default class FlutterLoader { this.flutterApplicationInfo = ApplicationInfoLoader.load(context); await prefetchDefaultFontManager(); if (this.flutterApplicationInfo!.isDebugMode) { - await this.copyResource(context) + this.copyResource(context) } this.initResult = new InitResult( `${context.filesDir}/`, @@ -107,9 +107,9 @@ export default class FlutterLoader { } - private async copyResource(context: common.Context) { + private copyResource(context: common.Context) { let filePath = context.filesDir + FILE_SEPARATOR + this.flutterApplicationInfo!.flutterAssetsDir - const timestamp = await this.checkTimestamp(filePath); + const timestamp = this.checkTimestamp(filePath); if (timestamp == null) { Log.d(TAG, "no need copyResource") return; @@ -125,19 +125,19 @@ export default class FlutterLoader { fs.mkdirSync(filePath) } - let icudtlBuffer = await this.context.resourceManager.getRawFileContent(this.flutterApplicationInfo!.flutterAssetsDir + "/icudtl.dat") + let icudtlBuffer = this.context.resourceManager.getRawFileContentSync(this.flutterApplicationInfo!.flutterAssetsDir + "/icudtl.dat") let icudtlFile = fs.openSync(filePath + FILE_SEPARATOR + "/icudtl.dat", fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE) fs.writeSync(icudtlFile.fd, icudtlBuffer.buffer) - let kernelBuffer = await this.context.resourceManager.getRawFileContent(this.flutterApplicationInfo!.flutterAssetsDir + FILE_SEPARATOR + DEFAULT_KERNEL_BLOB) + let kernelBuffer = this.context.resourceManager.getRawFileContentSync(this.flutterApplicationInfo!.flutterAssetsDir + FILE_SEPARATOR + DEFAULT_KERNEL_BLOB) let kernelFile = fs.openSync(filePath + FILE_SEPARATOR + DEFAULT_KERNEL_BLOB, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE) fs.writeSync(kernelFile.fd, kernelBuffer.buffer) - let vmBuffer = await this.context.resourceManager.getRawFileContent(this.flutterApplicationInfo!.flutterAssetsDir + FILE_SEPARATOR + this.flutterApplicationInfo!.vmSnapshotData) + let vmBuffer = this.context.resourceManager.getRawFileContentSync(this.flutterApplicationInfo!.flutterAssetsDir + FILE_SEPARATOR + this.flutterApplicationInfo!.vmSnapshotData) let vmFile = fs.openSync(filePath + FILE_SEPARATOR + this.flutterApplicationInfo!.vmSnapshotData, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE) fs.writeSync(vmFile.fd, vmBuffer.buffer) - let isolateBuffer = await this.context.resourceManager.getRawFileContent(this.flutterApplicationInfo!.flutterAssetsDir + FILE_SEPARATOR + this.flutterApplicationInfo!.isolateSnapshotData) + let isolateBuffer = this.context.resourceManager.getRawFileContentSync(this.flutterApplicationInfo!.flutterAssetsDir + FILE_SEPARATOR + this.flutterApplicationInfo!.isolateSnapshotData) let isolateFile = fs.openSync(filePath + FILE_SEPARATOR + this.flutterApplicationInfo!.isolateSnapshotData, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE) fs.writeSync(isolateFile.fd, isolateBuffer.buffer) @@ -191,7 +191,7 @@ export default class FlutterLoader { + this.flutterApplicationInfo!.nativeLibraryDir + FILE_SEPARATOR + this.flutterApplicationInfo!.aotSharedLibraryName); - + const fileIsAccess = fs.accessSync(OH_ICU_DATA_FILE_PATH) if (fileIsAccess) { @@ -247,8 +247,8 @@ export default class FlutterLoader { return this.flutterApplicationInfo == null ? "" : this.flutterApplicationInfo!.flutterAssetsDir + "/" + filePath; } - private async checkTimestamp(dataDir: string) : Promise { - let bundleInfo = await bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT); + private checkTimestamp(dataDir: string) { + let bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT); const expectedTimestamp = TIMESTAMP_PREFIX + bundleInfo.versionCode + "-" + bundleInfo.updateTime; const existingTimestamps = this.getExistingTimestamps(dataDir); if (existingTimestamps == null) { @@ -288,8 +288,8 @@ class InitResult { dataDirPath: string; constructor(appStoragePath: string, - engineCachesPath: string, - dataDirPath: string) { + engineCachesPath: string, + dataDirPath: string) { this.appStoragePath = appStoragePath; this.engineCachesPath = engineCachesPath; this.dataDirPath = dataDirPath; diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets index 8ba4463178..0d5f2c19be 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets @@ -103,11 +103,6 @@ export class FlutterAbility extends UIAbility implements Host { } this.errorManagerId = errorManager.on('error', observer); - let flutterApplicationInfo = ApplicationInfoLoader.load(this.context); - - if (flutterApplicationInfo.isDebugMode) { - this.delegate?.initWindow(); - } } onDestroy() { @@ -138,6 +133,12 @@ export class FlutterAbility extends UIAbility implements Host { onWindowStageCreate(windowStage: window.WindowStage) { FlutterManager.getInstance().pushWindowStage(this, windowStage); this.delegate?.initWindow(); + if (this.shouldAttachEngineToAbility()) { + // Notify any plugins that are currently attached to our FlutterEngine that they + // are now attached to an Ability. + Log.d(TAG, "Attaching FlutterEngine to the Ability that owns this delegate."); + this.delegate?.flutterEngine?.getAbilityControlSurface()?.attachToAbility(this.delegate); + } this.mainWindow = windowStage.getMainWindowSync(); try { windowStage.on('windowStageEvent', (data) => { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets index 480371d807..43b9a9140c 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets @@ -75,13 +75,6 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent if (this.flutterEngine == null) { await this.setupFlutterEngine(); } - //shouldAttachEngineToAbility - if (this.host?.shouldAttachEngineToAbility()) { - // Notify any plugins that are currently attached to our FlutterEngine that they - // are now attached to an Ability. - Log.d(TAG, "Attaching FlutterEngine to the Ability that owns this delegate."); - this.flutterEngine?.getAbilityControlSurface()?.attachToAbility(this); - } //providePlatformPlugin this.platformPlugin = this.host?.providePlatformPlugin(this.flutterEngine!) //configureFlutterEngine @@ -178,9 +171,9 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent this.isFlutterEngineFromHostOrCache = true; if (this.flutterEngine == null) { throw new Error( - "The requested cached FlutterEngine did not exist in the FlutterEngineCache: '" - + cachedEngineId - + "'"); + "The requested cached FlutterEngine did not exist in the FlutterEngineCache: '" + + cachedEngineId + + "'"); } return; } @@ -202,9 +195,9 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent const flutterEngineGroup = FlutterEngineGroupCache.instance.get(cachedEngineGroupId); if (flutterEngineGroup == null) { throw new Error( - "The requested cached FlutterEngineGroup did not exist in the FlutterEngineGroupCache: '" - + cachedEngineGroupId - + "'"); + "The requested cached FlutterEngineGroup did not exist in the FlutterEngineGroupCache: '" + + cachedEngineGroupId + + "'"); } if (this.context != null) { @@ -218,8 +211,8 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent // Our host did not provide a custom FlutterEngine. Create a FlutterEngine to back our // FlutterView. Log.d( - TAG, - "No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterAbility."); + TAG, + "No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterAbility."); let group = this.engineGroup; if (group == null && this.context != null) { -- Gitee From 116325750a284c8b00434153728d6edefd8436df Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Mon, 9 Sep 2024 18:16:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=9D=E6=8C=81debug=E4=B8=8Erelease?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96engine=E6=97=B6=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cjand <1747143535@qq.com> --- .../flutter/src/main/ets/embedding/ohos/FlutterAbility.ets | 6 ------ .../ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets index 0d5f2c19be..3c26873bd4 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets @@ -133,12 +133,6 @@ export class FlutterAbility extends UIAbility implements Host { onWindowStageCreate(windowStage: window.WindowStage) { FlutterManager.getInstance().pushWindowStage(this, windowStage); this.delegate?.initWindow(); - if (this.shouldAttachEngineToAbility()) { - // Notify any plugins that are currently attached to our FlutterEngine that they - // are now attached to an Ability. - Log.d(TAG, "Attaching FlutterEngine to the Ability that owns this delegate."); - this.delegate?.flutterEngine?.getAbilityControlSurface()?.attachToAbility(this.delegate); - } this.mainWindow = windowStage.getMainWindowSync(); try { windowStage.on('windowStageEvent', (data) => { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets index 43b9a9140c..af06d40f3a 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets @@ -75,6 +75,13 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent if (this.flutterEngine == null) { await this.setupFlutterEngine(); } + //shouldAttachEngineToAbility + if (this.host?.shouldAttachEngineToAbility()) { + // Notify any plugins that are currently attached to our FlutterEngine that they + // are now attached to an Ability. + Log.d(TAG, "Attaching FlutterEngine to the Ability that owns this delegate."); + this.flutterEngine?.getAbilityControlSurface()?.attachToAbility(this); + } //providePlatformPlugin this.platformPlugin = this.host?.providePlatformPlugin(this.flutterEngine!) //configureFlutterEngine -- Gitee