diff --git a/README.en.md b/README.en.md index 10b4ed164dfa8a7e44c86d88d8d4246ece695075..2a6eb00fe3c940b6dd4d83dabe0ef34d5978c9ee 100644 --- a/README.en.md +++ b/README.en.md @@ -60,57 +60,60 @@ This repository is a compatible extension of Flutter SDK for the OpenHarmony pla export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn ``` - 4. Configure the signing tool - - - Download [Signature Tool](https://gitee.com/openharmony/developtools_hapsigner) and configure the environment variable SIGN_TOOL_HOME. - - ``` - export SIGN_TOOL_HOME=/home//ohos/developtools_hapsigner/autosign - ``` - - - Execute the gradle command to compile and obtain hap-sign-tool.jar. Make sure it is in the directory: ./hapsigntool/hap_sign_tool/build/libs/hap-sign-tool.jar. (gradle version recommended 7.x) - - ``` - gradle build - ``` - - - Edit the `autosign.config` and `createAppCertAndProfile.config` files in the autosign directory and modify their values: - - ``` - sign.profile.inFile=profile_tmp.json - ``` - - - In the autosign directory (the command `chmod 777 *.sh` must be executed first in linux and mac environments, and there is no need to execute this command in Windows environment), add the `profile_tmp_template.json` file and edit it as follows: - - ``` - { - "version-name": "2.0.0", - "version-code": 2, - "app-distribution-type": "os_integration", - "uuid": "5027b99e-5f9e-465d-9508-a9e0134ffe18", - "validity": { - "not-before": 1594865258, - "not-after": 1689473258 - }, - "type": "release", - "bundle-info": { - "developer-id": "OpenHarmony", - "distribution-certificate": "-----BEGIN CERTIFICATE-----\nMIICSTCCAc+gAwIBAgIFAJV7uNUwCgYIKoZIzj0EAwIwYzELMAkGA1UEBhMCQ04x\nFDASBgNVBAoMC09wZW5IYXJtb255MRkwFwYDVQQLDBBPcGVuSGFybW9ueS BUZWT ZMBcGA1UECwwQT3Blbkhhcm1vbnkgVGVhbTEoMCYGA1UEAwwf\nT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gUmVsZWFzZTBZMBMGByqGSM49AgEGCCqG\nSM49AwEHA0IABAW8pFu7tHGUuWtddD5wvazc1qN8t s9UPZH4pecbb/bSFWKh7X7R\n/eTVaRrCTSSdovI1dhoV5GjuFsKW+jT2TwSjazBpMB0GA1UdDgQWBBScyywAaAMj\nI7HcuIS42lvZx0Lj+zAJBgNVHRMEAjAAMA4GA1UdDwEB/wQEAwIHgDATBgNVHSUE\ nDDAKBggrBgEFBQcDAzAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEAMAoGCCqGSM49\nBAMCA2gAMGUCFfNidGo6uK6KGT9zT1T5bY1NCHTH3P3muy5X1xudOgxWoOqIbnk\ntmQYB78dxWEHLQIxANfApAlXAD/0 hnyNC8RDzfLOPEeay6jU9FXJj3AoR90rwZpR\noN9sYD6Oks4VGRw6yQ==\n-----END CERTIFICATE-----\n", - "bundle-name": "{{ohosId}}", - "apl": "normal", - "app-feature": "hos_normal_app" - }, - "acls": { - "allowed-acls": [ - "" - ] - }, - "permissions": { - "restricted-permissions": [] - }, - "issuer": "pki_internal" - } - ``` + 4. Signature + + You can sign the application using either of the following two methods. + + (1) Signing with `Deveco Studio` + + - Open the ohos directory of the project using Deveco Studio. + - Click on File > Project Structure > Project > Signing Configs. Check the Automatically generate signature option, wait for the automatic signing process to complete, and then click OK. + - Review the configuration information in build-profile.json5. Add the certificate information generated from the automatic signing process to the configuration. + + (2) Signing with signing tool + + - Download [Signature Tool](https://gitee.com/openharmony/developtools_hapsigner) and configure theenvironment variable SIGN_TOOL_HOME. + ``` + export SIGN_TOOL_HOME=/home//ohos/developtools_hapsigner/autosign + ``` + - Execute the gradle command to compile and obtain hap-sign-tool.jar. Make sure it is in thedirectory: ./ hapsigntool/hap_sign_tool/build/libs/hap-sign-tool.jar. (gradle version recommended 7.x) + ``` + gradle build + ``` + - Edit the `autosign.config` and `createAppCertAndProfile.config` files in the autosign directory andmodify their values: + ``` + sign.profile.inFile=profile_tmp.json + ``` + - In the autosign directory (the command `chmod 777 *.sh` must be executed first in linux and macenvironments, and there is no need to execute this command in Windows environment), add the`profile_tmp_template.json` file and edit it as follows: + ``` + { + "version-name": "2.0.0", + "version-code": 2, + "app-distribution-type": "os_integration", + "uuid": "5027b99e-5f9e-465d-9508-a9e0134ffe18", + "validity": { + "not-before": 1594865258, + "not-after": 1689473258 + }, + "type": "release", + "bundle-info": { + "developer-id": "OpenHarmony", + "distribution-certificate": "-----BEGIN CERTIFICATE-----\nMIICSTCCA +gAwIBAgIFAJV7uNUwCgYIKoZIzj0EAwIwYzELMAkGA1UEBhMCQ04x\nFDASBgNVBAoMC09wZW5IYXJtb255MRkwFwYDVQLDBB PcGVuSGFybW9ueS BUZWTZMBcGA1UECwwQT3Blbkhhcm1vbnkgVGVhbTEoMCYGA1UEAwwf\nT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gUmVsZWFzZT ZMBMGByqGSM49AgEGCCqG\nSM49AwEHA0IABAW8pFu7tHGUuWtddD5wvazc1qN8t s9UPZH4pecbb/ bSFWKh7X7R\neTVaRrCTSSdovI1dhoV5GjuFsKW+jT2TwSjazBpMB0GA1UdDgQWBBScyywAaAMj\nI7HcuIS42lvZx0L +zAJBgNVHRMEAjAAMA4GA1UdDwEB/ wQEAwIHgDATBgNVHSUE\nDDAKBggrBgEFBQcDAzAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEAMAoGCCqGSM49\nBAMCA2gAMGU CFfNidGo6uK6KGTzT1T5bY1NCHTH3P3muy5X1xudOgxWoOqIbnk\ntmQYB78dxWEHLQIxANfApAlXAD/ 0hnyNC8RDzfLOPEeay6jU9FXJj3AoR90rwZpR\noN9sYD6Oks4VGRw6yQ==\n-----END CERTIFICATE-----\n", + "bundle-name": "{{ohosId}}", + "apl": "normal", + "app-feature": "hos_normal_app" + }, + "acls": { + "allowed-acls": [ + "" + ] + }, + "permissions": { + "restricted-permissions": [] + }, + "issuer": "pki_internal" + } + ``` 5. The application build relies on [Flutter Engine](https://github.com/flutter/engine) to build products: `ohos_debug_unopt_arm64` and `ohos_release_arm64`. Please add: `--local-engine= in the Flutter Tools command running parameters. \` diff --git a/README.md b/README.md index 8ee6acfd404ac3fc8f4a6786b8e96ceed1074163..b95bb41c6e68ab8499c087e0d06f9f929b179a31 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,17 @@ Flutter SDK 仓库 export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn ``` - 4. 配置签名工具 + 4. 配置签名 + + 可以通过下面任意一种方式对应用进行签名。 + + (1) 使用 `Deveco Studio` 签名 + + - 用 `Deveco Studio` 打开项目的 `ohos` 目录 + - 单击 `File > Project Structure > Project > Signing Configs` 界面勾选 `Automatically generate signature`,等待自动签名完成即可,单击 `OK`。 + - 查看 `build-profile.json5` 配置信息,配置信息中增加自动签名生成的证书信息。 + + (2) 使用 [签名工具](https://gitee.com/openharmony/developtools_hapsigner) 签名 - 下载[签名工具](https://gitee.com/openharmony/developtools_hapsigner),并配置环境变量SIGN_TOOL_HOME。 @@ -111,6 +121,7 @@ Flutter SDK 仓库 "issuer": "pki_internal" } ``` + 5. 应用构建依赖[Flutter Engine](https://github.com/flutter/engine)构建产物:`ohos_debug_unopt_arm64` 与 `ohos_release_arm64`,请在Flutter Tools指令运行参数中添加:`--local-engine=\` diff --git a/packages/flutter_tools/lib/src/ohos/hvigor.dart b/packages/flutter_tools/lib/src/ohos/hvigor.dart index b3ba711c9a0456c8bd9667dbff647dc1742fcb42..be474e8e5be9ce18b6f0c03c26cc7d9d5afe7e04 100644 --- a/packages/flutter_tools/lib/src/ohos/hvigor.dart +++ b/packages/flutter_tools/lib/src/ohos/hvigor.dart @@ -15,6 +15,7 @@ import 'dart:io'; +import 'package:json5/json5.dart'; import 'package:process/process.dart'; import '../artifacts.dart'; @@ -695,16 +696,28 @@ class OhosHvigorBuilder implements OhosBuilder { throwToolExit('assembleHap error! please check log.'); } - final String unsignedFile = globals.fs.path.join( + final String desSignedFile = globals.fs.path.join( ohosRootPath, ohosProject.mainModuleName, 'build/default/outputs/default', - 'entry-default-unsigned.hap'); - final String desSignedFile = globals.fs.path.join( + 'entry-default-signed.hap'); + + final File buildProfile = flutterProject.ohos.getBuildProfileFile(); + final String buildProfileConfig = buildProfile.readAsStringSync(); + final dynamic obj = JSON5.parse(buildProfileConfig); + dynamic signingConfigs = obj['app']?['signingConfigs']; + if(signingConfigs is List && signingConfigs.isNotEmpty){ + final File signedFile= globals.localFileSystem.file(desSignedFile); + if(signedFile.existsSync()) { + return; + } + } + + final String unsignedFile = globals.fs.path.join( ohosRootPath, ohosProject.mainModuleName, 'build/default/outputs/default', - 'entry-default-signed.hap'); + 'entry-default-unsigned.hap'); await signHap(globals.localFileSystem, unsignedFile, desSignedFile, logger, ohosBuildData.appInfo!.bundleName);