当前位置:   article > 正文

【鸿蒙开发实战教程】在MacOS上如何使用 Flutter 构建鸿蒙APP_will skip sign 'app'. no signingconfigs profile is

will skip sign 'app'. no signingconfigs profile is configured in current pro

前言

根据研究机构Counterpoint Research发布的最新数据,2024年第一季度,鸿蒙OS份额由去年一季度的8%上涨至17%,iOS份额则从20%下降至16%。这意味着,华为鸿蒙OS在中国市场的份额超越苹果iOS,已成中国第二大操作系统。

随着鸿蒙市场份额的不断提升,相应的岗位也会迎来一个爆发式的增长。这对于想要换赛道的程序员来说是一个非常好的消息,话说大家最近有想法转型鸿蒙开发吗?

目前各大厂商纷纷与华为合作构建鸿蒙版移动应用,华为内部也主导适配目前的主流跨平台方案Flutter,并提供反向适配支持,此文将分享如何在Mac上构建鸿蒙App。

一、Harmony Flutter

目前社区最新支持 Flutter 3.7.12 OpenHarmony-SIG/flutter_flutter (gitee.com)

二、Node 环境配置

1、Node 管理工具 nvm

nvm: github.com/nvm-sh/nvm

2、安装 nvm

i): 下载并安装

curl -o- raw.githubusercontent.com/nvm-sh/nvm/… | bash
ii): 添加环境变量到 ~/.zshrc

#nvm
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
  • 1
  • 2
  • 3

3、使用 nvm 管理 node

i): 安装 node nvm install

$ nvm install 16
Now using node v16.9.1 (npm v7.21.1)
  • 1
  • 2

ii): 切换 node 版本 nvm use
arduino复制代码$ nvm use 16
Now using node v16.9.1 (npm v7.21.1)

iii): 查看 node 版本 nvm -v

$ node -v 
v16.9.1
  • 1
  • 2

4、在用户目录 /User/xxx/ 创建 .npmrc 文件,配置如下

registry=https://repo.huaweicloud.com/repository/npm/
@ohos:registry=https://repo.harmonyos.com/npm/
  • 1
  • 2

三、Java 环境配置

1、安装和查看本地 java 版本及 jdk 路径
a) 安装Java11 和 Java 17

鸿蒙签名工具基于 Gradle 7.1 编译构建(需要jdk11)

ohsdkmgr 必须jdk17+
brewinstallopenjdk@11brew install openjdk@11brewinstallopenjdk@11 brew install openjdk@17

b) 查看 java 路径 /usr/libexec/java_home -V
$ /usr/libexec/java_home -V

 Matching Java Virtual Machines (3):
    17.0.9 (x86_64) "Homebrew" - "OpenJDK 17.0.9" /usr/local/Cellar/openjdk@17/17.0.9/libexec/openjdk.jdk/Contents/Home
    11.0.21 (x86_64) "Homebrew" - "OpenJDK 11.0.21" /usr/local/Cellar/openjdk@11/11.0.21/libexec/openjdk.jdk/Contents/Home
    1.8.391.13 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
/usr/local/Cellar/openjdk@17/17.0.9/libexec/openjdk.jdk/Contents/Home
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

2、Java版本管理工具

a) 安装 jenv brew install jenv
b) 添加环境变量 ~/.zshrc
export PATH="$HOME/.jenv/bin:$PATH" 
eval "$(jenv init -)" 
  • 1
  • 2
c) 添加 jdk 到 jenv jenv add
 jenv add /usr/local/Cellar/openjdk@17/17.0.9/libexec/openjdk.jdk/Contents/Home
  • 1
d) 查看 jenv 管理的 jdk 版本 jenv versions
$ jenv versions
    
  system
  1.8.0.391
  11.0
  11.0.21
  17.0
* 17.0.9 (set by /Users/xxx/.jenv/version)
  openjdk64-11.0.21
  openjdk64-17.0.9
  oracle64-1.8.0.391
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
e) 切换 jdk 版本 jenv global
$ jenv global 11.0.21
  • 1
f) 查看当前使用 java 版本 java -version
openjdk version "17.0.9" 2023-10-17
OpenJDK Runtime Environment Homebrew (build 17.0.9+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.9+0, mixed mode, sharing)
  • 1
  • 2
  • 3

3、Gradle 配置

i): 下载 gradle7.1: https://gradle.org/releases/
ii): 添加 gradle 环境变量
export PATH=/Users/xxx/ohos/tools/gradle-7.1/bin:$PATH
  • 1

四、同步引擎代码

1、文件夹目录分布结构如下

在这里插入图片描述

2、下载 depot_tools

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
  • 1

3、设置环境变量:

export PATH=/Users/xxx/ohos/flutter/depot_tools:$PATH
  • 1

4、创建 engine 目录,创建文件 .gclient并添加以下代码

solutions = [
  {
    "managed": False,
    "name": "src/flutter",
    "url": "git@gitee.com:openharmony-sig/flutter_engine.git",
    "custom_deps": {},
    "deps_file": "DEPS",
    "safesync_url": "",
  },
]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

5、切换到 engine 目录,执行gclient sync执行完成如下

在这里插入图片描述

五、Harmony SDK 配置

1、Command Line Tools 配置: HarmonyOS开发者网站

●Command Line Tools for HarmonyOS
●Command Line Tools for OpenHarmony

a): 设置环境变量
#Open Harmony SDK & HDC
export HDC_SERVER_PORT=7035
export OHPM_HOME=/Users/xxx/ohos/tools/oh-command-line-tools/ohpm
export PATH=/Users/xxx/ohos/tools/oh-command-line-tools/sdkmanager/bin:$PATH
export PATH=$PATH:$OHPM_HOME/bin
export OHOS_SDK_HOME=/Users/xxx/ohos/tools/oh-command-line-tools/sdk
export HDC_HOME=/Users/xxx/ohos/tools/oh-command-line-tools/sdk/11/toolchains
#export HDC_HOME=/Users/xxx/ohos/tools/hwsdk/openharmony/9/toolchains
export PATH=$PATH:$HDC_HOME

export PATH=/Users/xxx/ohos/tools/command-line-tools/sdkmanager/bin:$PATH
export HOS_SDK_HOME=/Users/xxx/ohos/tools/hwsdk
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
b): 执行 ohsdkmgr list, API(10、11) 需去官网自行下载:构建详情 (openharmony.cn)

在这里插入图片描述

c): 下载完成后放sdk这个层级下

在这里插入图片描述

d): 分别进入

●sdk/11/ets/build-tools/ets-loader
●sdk/11/js/build-tools/ace-loader

e): 执行npm install
f): 将oh command tools 里面的 native 文件夹拷贝至 engine/ndk/mac/4.0 目录下,如下图

在这里插入图片描述

g): 编译引擎,切换到 engine 目录下,执行 make 命令(此过程预计1小时左右)
 编译出来的产物
  • 1

●ohos_debug_unopt_arm64

●ohos_release_arm64

2、鸿蒙签名配置

a): 下载鸿蒙签名工具:
git clone https://gitee.com/openharmony/developtools_hapsigner.git
  • 1
b):设置环境变量
#Harmony sign tool
export SIGN_TOOL_HOME=/Users/xxx/ohos/tools/developtools_hapsigner/autosign
  • 1
  • 2
c): 增加 profile_tmp_template.json 内容如下, 其中 {{ohosId}} 为创建的 Flutter 应用名称
{
    "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\nFDASBgNVBAoMC09wZW5IYXJtb255MRkwFwYDVQQLDBBPcGVuSGFybW9ueSBUZWFt\nMSMwIQYDVQQDDBpPcGVuSGFybW9ueSBBcHBsaWNhdGlvbiBDQTAeFw0yMjAxMjkw\nNTU0MTRaFw0yMzAxMjkwNTU0MTRaMGgxCzAJBgNVBAYTAkNOMRQwEgYDVQQKDAtP\ncGVuSGFybW9ueTEZMBcGA1UECwwQT3Blbkhhcm1vbnkgVGVhbTEoMCYGA1UEAwwf\nT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gUmVsZWFzZTBZMBMGByqGSM49AgEGCCqG\nSM49AwEHA0IABAW8pFu7tHGUuWtddD5wvazc1qN8ts9UPZH4pecbb/bSFWKh7X7R\n/eTVaRrCTSSdovI1dhoV5GjuFsKW+jT2TwSjazBpMB0GA1UdDgQWBBScyywAaAMj\nI7HcuIS42lvZx0Lj+zAJBgNVHRMEAjAAMA4GA1UdDwEB/wQEAwIHgDATBgNVHSUE\nDDAKBggrBgEFBQcDAzAYBgwrBgEEAY9bAoJ4AQMECDAGAgEBCgEAMAoGCCqGSM49\nBAMCA2gAMGUCMFfNidGo6uK6KGT9zT1T5bY1NCHTH3P3muy5X1xudOgxWoOqIbnk\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"
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
d): 编辑配置文件

●autosign.config
●createAppCertAndProfile.config

修改值:sign.profile.inFile=profile_tmp.json

e): 切换 Java 版本11 (签名工具基于Gradle 7.1编译构建)
f): 切换至 developtools_hapsigner/hapsigntool **目录,**执行 gradle build 或者 **gradle jar,**确保 hap-sign-tool.jar 生成

六、鸿蒙 Flutter 配置

a): 下载 Flutter

git clone https://gitee.com/openharmony-sig/flutter_flutter.git
  • 1

b): 设置环境变量

#Harmony flutter
export PATH=/Users/xxx/ohos/flutter/flutter_flutter/bin:$PATH
export PATH=/Users/xxx/ohos/flutter/flutter_flutter/bin/cache/dart-sdk/bin:$PATH
export PATH=/Users/xxx/ohos/flutter/flutter_flutter/.pub-cache/bin:$PATH
export FLUTTER_GIT_URL=https://gitee.com/openharmony-sig/flutter_flutter.git
export PUB_HOSTED_URL=https://pub.flutter-io.cn
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
c): 执行 flutter doctor -v
[✓] Flutter (Channel master, 3.7.12, on macOS 12.7 21G816 darwin-x64, locale zh-Hans-CN)
    • Flutter version 3.7.12 on channel master at /Users/xxx/ohos/flutter/flutter_flutter
    • Upstream repository https://gitee.com/openharmony-sig/flutter_flutter.git
    • FLUTTER_GIT_URL = https://gitee.com/openharmony-sig/flutter_flutter.git
    • Framework revision 00cc3dce34 (2 weeks ago), 2023-12-11 13:38:48 +0000
    • Engine revision 1a65d409c7
    • Dart version 2.19.6
    • DevTools version 2.20.1
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] OpenHarmony toolchain - develop for OpenHarmony devices
    • OpenHarmony Sdk location: /Users/xxx/ohos/tools/oh-command-line-tools/sdk, available api versions has [9, 10]
    • hdc version 2.0.0
    • ohpm version 1.2.0
    • signTool location:/Users/xxx/ohos/tools/developtools_hapsigner/autosign

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/xxx/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • ANDROID_HOME = /Users/xxx/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/900330
推荐阅读
相关标签