OpenHarmony 源码中编译Hap包预装(L2) 原创

碼磚民工
发布于 2023-10-13 17:39
浏览
0收藏

@toc

1. 简介

本文介绍 OpenHarmony3.2 beta3 Stage工程,系统源码中编译js,并预装到系统中的配置。

2. 源码路径applications\standard\MyApplication(stage工程)

源码见附件,签名参考签名

2.1 源码修改

2.1.1 修改applications\standard\MyApplication\AppScope\app.json

{
  "app": {
    "bundleName": "com.example.myapplication",
    "vendor": "example",
    "versionCode": 1000000,
    "versionName": "1.0.0",
    "icon": "$media:app_icon",
    "label": "$string:app_name",
    "minAPIVersion": 9,			// 必须添加
    "targetAPIVersion": 9,		// 必须添加
    "distributedNotificationEnabled": true
  }
}

不添加version信息,编译的hap包安装报错:failed to install bundle. error: install parse profile missing prop.

2.1.2 新建module.json

applications\standard\MyApplication\entry\src\main\module.json5复制一份并将复制文件重命名为module.json

如果module.json中添加权限,需要对应调整UnsgnedReleasedProfileTemplate-sys2.0.json中的"allowed-acls"字段,重新生成签名。

2.1.3 修改applications\standard\hap\ohos.build

"module_list"中添加"//applications/standard/MyApplication:myapplication_hap"

2.2 添加文件

2.2.1 添加文件BUILD.gn

路径:applications\standard\MyApplication\BUILD.gn

内容:

import("//build/ohos.gni")

ohos_hap("myapplication_hap") {
  hap_profile = "./entry/src/main/module.json"
  deps = [
    ":myapplication_js_assets",
    ":myapplication_resources",
  ]
  certificate_profile = "./signature/app-profile-20-sys.p7b"
  hap_name = "myapplication"
  part_name = "prebuilt_hap"
  subsystem_name = "applications"
  js_build_mode = "release"
  module_install_dir = "app/com.example.myapplication"
}

ohos_app_scope("myapplication_app_profile") {
  app_profile = "AppScope/app.json"
  sources = [ "AppScope/resources" ]
}

ohos_js_assets("myapplication_js_assets") {
  ets2abc = true
  source_dir = "entry/src/main/ets"
}

ohos_resources("myapplication_resources") {
  sources = [ "entry/src/main/resources" ]
  deps = [ ":myapplication_app_profile" ]
  hap_profile = "entry/src/main/module.json"
}

2.2.2 签名文件

签名文件app-profile-20-sys.p7b在applications\standard\MyApplication\signature\app-profile-20-sys.p7b, 自己可以参考文档生成,签名不对有可能预装不成功, 签名使用的是OpenHarmony默认的别名和密.码。

2.3 编译

全量编译: ./build.sh --product-name rk3568后就会生成myapplication.hap包,可以通过hdc_std.exe install myapplication.hap安装

2.4 预装

2.4.1 OpenHarmony 3.2beta2(已经废弃)

直接编译好后,重新烧写系统即可。

2.4.2 OpenHarmony 3.2beta3

经过如下配置之后,重新编译烧写系统,应用即可预装

2.4.2.1 使用keytool输出指纹(keytool是java自带工具)

keytool -printcert -file OpenHarmonyProfileRelease.pem

选择第一条指纹SHA256的数据,去掉中间的冒号,我的版本去掉冒号后的指纹为(有说任何一条sha256都可以):

"9AED2A79925ECA050CD2BB9D2A7F694E49E5E135D28EBDCE53836DE76B5080ED"

2.4.2.2 配置vendor\hihope\rk3568\preinstall-config\install_list_capability.json
        {
            "bundleName": "com.example.myapplication",
            "app_signature": ["9AED2A79925ECA050CD2BB9D2A7F694E49E5E135D28EBDCE53836DE76B5080ED"],
            "singleton": true,
            "keepAlive": true
        }
2.4.2.3 配置vendor\hihope\rk3568\preinstall-config\install_list.json
        {
            "app_dir" : "/system/app/com.example.myapplication",
            "removable" : true
        }

removable字段,表示预装应用是否可以卸载。

FA工程正确编译成hap包未解决。

3. 问题

  • Stage工程可以编译,编译结果还能安装成功。FA工程编译成功了,不能安装,安装报错:failed to install bundle. error: install parse profile missing prop.

  • **failed to install bundle. error: install state error. **

    重新烧系统

  • Stage工程可以编译hap包安装报错:failed to install bundle. error: install parse profile missing prop.

    app.json没有添加version配置

  • failed to install bundle. error: install failed due to grant request permissions failed

    module.json中配置了权限,需要对应调整UnsgnedReleasedProfileTemplate-sys2.0.json中的"allowed-acls"字段,重新生成签名并导入工程,重新编译。

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
标签
MyApplication.rar 60.52K 0次下载
已于2023-10-13 17:40:11修改
2
收藏
回复
举报
2条回复
按时间正序
/
按时间倒序
红叶亦知秋
红叶亦知秋

大佬最近非常活跃呀!

回复
2023-10-13 18:06:06
晒太阳的懒猫
晒太阳的懒猫

学习并收藏了,谢谢分享


回复
2023-10-14 09:00:05
回复
    相关推荐