diff --git a/packages/flutter_tools/lib/src/ohos/hvigor.dart b/packages/flutter_tools/lib/src/ohos/hvigor.dart index cb07a97e40bda968ee0689359aaf687162247b77..b03f4560811ebf3658eeeeb9619a7bef0ac341dc 100644 --- a/packages/flutter_tools/lib/src/ohos/hvigor.dart +++ b/packages/flutter_tools/lib/src/ohos/hvigor.dart @@ -47,6 +47,8 @@ const String FLUTTER_ASSETS_PATH = 'flutter_assets'; const String FLUTTER_ENGINE_SO = 'libflutter.so'; +const String VMSERVICE_SNAPSHOT_SO = 'libvmservice_snapshot.so'; + const String APP_SO_ORIGIN = 'app.so'; const String APP_SO = 'libapp.so'; @@ -95,6 +97,14 @@ String getEngineSoPath(String ohosRootPath, TargetPlatform targetPlatform, FLUTTER_ENGINE_SO); } +/// eg:entry/libs/arm64-v8a/libvmservice_snapshot.so +String getVmServiceSoDest(String ohosRootPath, TargetPlatform targetPlatform, + OhosProject ohosProject) { + return globals.fs.path.join( + getProjectArchPath(ohosRootPath, targetPlatform, ohosProject), + VMSERVICE_SNAPSHOT_SO); +} + /// eg:entry/libs/arm64-v8a/libapp.so String getAppSoPath(String ohosRootPath, TargetPlatform targetPlatform, OhosProject ohosProject) { @@ -173,25 +183,39 @@ Future signHap(LocalFileSystem localFileSystem, String unsignedFile, } final Directory resultBackup = localFileSystem .directory(globals.fs.path.join(signToolHome, 'result.bak')); - //如果result.bak不存在,代表是第一次构建,拷贝result.bak。 以后每一次result,都从result.bak还原 + + String projectHome = globals.fs.directory(getOhosBuildDirectory()).path; + final Directory projectSignHistory = localFileSystem + .directory(globals.fs.path.join(projectHome, 'signature')); + + bool isNeedCopySignHistory = true; + // 如果result.bak不存在,代表是环境配置完成后第一次签名,拷贝result.bak。 if (!resultBackup.existsSync()) { copyDirectory(result, resultBackup); - } else { + } else if (!projectSignHistory.existsSync()) { + // 如果projectSignHistory不存在,代表该工程从未进行过签名,此时从 result.bak 还原数据进行签名 result.deleteSync(recursive: true); copyDirectory(resultBackup, result); + } else { + // 如果projectSignHistory存在,代表该工程之前进行过签名,此时拷贝历史签名数据进行签名 + isNeedCopySignHistory = false; + copyDirectory(projectSignHistory, result); } - final List cmdCreateCertAndProfile = []; - cmdCreateCertAndProfile.add('python3'); - cmdCreateCertAndProfile - .add(globals.fs.path.join(signToolHome, 'autosign.py')); - cmdCreateCertAndProfile.add('createAppCertAndProfile'); + if (isNeedCopySignHistory) { + final List cmdCreateCertAndProfile = []; + cmdCreateCertAndProfile.add('python3'); + cmdCreateCertAndProfile + .add(globals.fs.path.join(signToolHome, 'autosign.py')); + cmdCreateCertAndProfile.add('createAppCertAndProfile'); - await invokeCmd( - command: cmdCreateCertAndProfile, - workDirectory: signToolHome, - processManager: globals.processManager, - logger: logger); + await invokeCmd( + command: cmdCreateCertAndProfile, + workDirectory: signToolHome, + processManager: globals.processManager, + logger: logger); + copyDirectory(result, projectSignHistory); + } final List cmdSignHap = []; if (isWindows) { @@ -518,32 +542,36 @@ void cleanAndCopyFlutterRuntime( originHarFile.copySync(desHarPath); //copy ohos engine so - if (isWindows) { - final String originEnginePath = globals.fs.path - .join(ohosRootPath, 'har', 'har_product', '$FLUTTER_ENGINE_SO.$suffix'); - final String desEnginePath = globals.fs.path.join( - ohosProject.flutterModuleDirectory.path, - 'libs', - 'arm64-v8a', - FLUTTER_ENGINE_SO); - final File flutterEngineSoFile = - globals.localFileSystem.file(originEnginePath); - flutterEngineSoFile.copySync(desEnginePath); + final String? originEngineSoPath = isWindows + ? globals.fs.path.join(ohosRootPath, 'har', 'har_product', '$FLUTTER_ENGINE_SO.$suffix') + : globals.artifacts?.getArtifactPath(Artifact.flutterEngineSo); + if (originEngineSoPath == null) { + throwToolExit("flutter engine runtime file 'libflutter.so' no found"); + } + logger?.printStatus('flutterEngineSoPath: $originEngineSoPath'); + + final String destEngineSoPath = getEngineSoPath(ohosRootPath, targetPlatform, ohosProject); + ensureParentExists(destEngineSoPath); + final File flutterEngineSoFile = globals.localFileSystem.file(originEngineSoPath); + flutterEngineSoFile.copySync(destEngineSoPath); + + final String vmServiceSoDest = getVmServiceSoDest(ohosRootPath, targetPlatform, ohosProject); + final File vmServiceSoDestFile = globals.localFileSystem.file(vmServiceSoDest); + if (buildInfo.isProfile) { + // copy libvmservice_snapshot.so + final String vmserviceSoSrc = isWindows + ? globals.fs.path.join(ohosRootPath, 'har', 'har_product', '$VMSERVICE_SNAPSHOT_SO.$suffix') + : globals.fs.path.join(flutterEngineSoFile.parent.path, + 'gen/flutter/shell/vmservice/ohos/libs', + VMSERVICE_SNAPSHOT_SO); + final File vmserviceSoSrcFile = globals.localFileSystem.file(vmserviceSoSrc); + vmserviceSoSrcFile.copySync(vmServiceSoDest); } else { - final String? flutterEngineSoPath = - globals.artifacts?.getArtifactPath(Artifact.flutterEngineSo); - if (flutterEngineSoPath == null) { - throwToolExit("flutter engine runtime file 'libflutter.so' no found"); + if (vmServiceSoDestFile.existsSync()) { + vmServiceSoDestFile.deleteSync(); } - logger?.printStatus('flutterEngineSoPath:$flutterEngineSoPath'); - final File flutterEngineSoFile = - globals.localFileSystem.file(flutterEngineSoPath); - - final String enginCopyDes = - getEngineSoPath(ohosRootPath, targetPlatform, ohosProject); - ensureParentExists(enginCopyDes); - flutterEngineSoFile.copySync(enginCopyDes); } + logger?.printStatus('copy flutter runtime to project end'); } diff --git a/packages/flutter_tools/lib/src/ohos/ohos_device.dart b/packages/flutter_tools/lib/src/ohos/ohos_device.dart index b00c6aef2ebb449e484fdf62b7bfbf61844d8dde..7a3d2f2e1344376cf60d31ae3459ed456ae83711 100644 --- a/packages/flutter_tools/lib/src/ohos/ohos_device.dart +++ b/packages/flutter_tools/lib/src/ohos/ohos_device.dart @@ -735,7 +735,7 @@ class HdcLogReader extends DeviceLogReader { static final RegExp _logFormat = RegExp(r'^[\d-:. ]{30,40}[VDIWEF][^:]+:'); static final List _allowedTags = [ - RegExp(r'^[\d-:. ]{30,40}[VDIWEF][^:]flutter[^:]+:', caseSensitive: false), + RegExp(r'^[\d-:. ]{30,40}[VDIWEF]\s[^:]+Flutter[^:]+:\sflutter\s'), RegExp(r'^[\d-:. ]{30,40}[IE].*Dart VM\s+'), RegExp(r'^[WEF]\/System\.err:\s+'), RegExp(r'^[F]\/[\S^:]+:\s+'), diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index 5bd5fe1f9f323765296f48ffb671ffb10968af83..c744b0315b9e66d8314a4cfcea8e0bd3183ddad6 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -251,7 +251,7 @@ class FlutterDevice { // when on hdc server mode,the host is not local,change to hdc server final String? hdcServerHost = getHdcServerHost(); if(hdcServerHost!=null){ - const String localHost = '0.0.0.0'; + const String localHost = '127.0.0.1'; observatoryUri = Uri.parse(observatoryUri?.toString()?.replaceAll(localHost, hdcServerHost)??localHost); } diff --git a/packages/flutter_tools/lib/src/vmservice.dart b/packages/flutter_tools/lib/src/vmservice.dart index b1035b704b0c36d4a5713ac278ab8266afad3a1a..01bce347f94e6306812f09b8bbe2edbb4fbf55a2 100644 --- a/packages/flutter_tools/lib/src/vmservice.dart +++ b/packages/flutter_tools/lib/src/vmservice.dart @@ -152,7 +152,7 @@ Future _defaultOpenChannel(String url, { final String? hdcServerHost = getHdcServerHost(); // when on hdc server mode,the host is not local,change to hdc server if(hdcServerHost!=null){ - url = url.replaceAll('0.0.0.0', hdcServerHost); + url = url.replaceAll('127.0.0.1', hdcServerHost); logger.printStatus('io.WebSocket.connect change url to $url'); } socket = await constructor(url, compression: compression, logger: logger); diff --git a/packages/flutter_tools/templates/app_shared/ohos.tmpl/.gitignore b/packages/flutter_tools/templates/app_shared/ohos.tmpl/.gitignore index c6da0806e7b770953be804991bc28a2894a1e4b6..11784662aacd838dd06d8d80504c161b73904865 100644 --- a/packages/flutter_tools/templates/app_shared/ohos.tmpl/.gitignore +++ b/packages/flutter_tools/templates/app_shared/ohos.tmpl/.gitignore @@ -11,5 +11,6 @@ **/.test entry/libs/arm64-v8a/libapp.so entry/libs/arm64-v8a/libflutter.so +entry/libs/arm64-v8a/libvmservice_snapshot.so entry/src/main/resources/rawfile/flutter_assets/ har/flutter_embedding.har diff --git a/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/flutter_embedding.har.debug.10 b/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/flutter_embedding.har.debug.10 index fb25ab6a0aaa1e99ed0f532214080062b213f8f1..457d0d83b2e998db5c79e2a92d2a360e81071162 100644 Binary files a/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/flutter_embedding.har.debug.10 and b/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/flutter_embedding.har.debug.10 differ diff --git a/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/flutter_embedding.har.profile.10 b/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/flutter_embedding.har.profile.10 index 27a247af9dbf3b48bdaafa7fda931a29bf0d63f0..4d39a4f2db09eaf2e549e7c569535f22ea474ff1 100644 Binary files a/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/flutter_embedding.har.profile.10 and b/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/flutter_embedding.har.profile.10 differ diff --git a/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/flutter_embedding.har.release.10 b/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/flutter_embedding.har.release.10 index 708cb2d4846a781cabcaefc6400e4746dc5e49fa..223c678869e3d73e36a6ed427aa9e6952e90c491 100644 Binary files a/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/flutter_embedding.har.release.10 and b/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/flutter_embedding.har.release.10 differ diff --git a/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/libvmservice_snapshot.so.profile.10 b/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/libvmservice_snapshot.so.profile.10 new file mode 100644 index 0000000000000000000000000000000000000000..5029cd23b3afaae3c61b194ab61a677031830586 Binary files /dev/null and b/packages/flutter_tools/templates/app_shared/ohos.tmpl/har/har_product.tmpl/libvmservice_snapshot.so.profile.10 differ diff --git a/packages/flutter_tools/templates/template_manifest.json b/packages/flutter_tools/templates/template_manifest.json index 01731c1345a7452651d31449b9ad2671c496fd36..09a574f9f51f92f811bfb42e3c9d80ab5a54590b 100644 --- a/packages/flutter_tools/templates/template_manifest.json +++ b/packages/flutter_tools/templates/template_manifest.json @@ -182,6 +182,7 @@ "templates/app_shared/ohos.tmpl/har/har_product.tmpl/libflutter.so.debug.10", "templates/app_shared/ohos.tmpl/har/har_product.tmpl/libflutter.so.profile.10", "templates/app_shared/ohos.tmpl/har/har_product.tmpl/libflutter.so.release.10", + "templates/app_shared/ohos.tmpl/har/har_product.tmpl/libvmservice_snapshot.so.profile.10", "templates/app_shared/ohos.tmpl/local.properties.tmpl", "templates/app_shared/ohos.tmpl/dta/icudtl.dat", "templates/app_shared/ohos.tmpl/entry/libs/arm64-v8a/libc++_shared.so",