OpenHarmony 系统应用需要在DevEco Studio单独开发编译,不能使用build.sh hb编译,比如Settings、Launcher、SystemUI等。
Launcher源码中有默认的签名配置,直接就可以使用。
Settings签名文件里面只有settings.p7b,虽然可以使用DevEco Studio默认自动签名,但是我发现push到设备里面后,点击应用,应用列表无法刷新,所以我想应该还是签名的问题,所以还是需要系统签名。
打开源码里面的签名工具目录OHOS_v4.0_NEW/developtools/hapsigner,这个就是默认签名工具,或者直接下载官方提供developtools_hapsigner。
环境配置python 和 gradle,可以参考hap包签名工具,我们不需要重新生成密钥文件,使用系统默认提供的就可以。
1、复制文件
把OpenHarmonyApplication.pem和settings.p7b复制到developtools/hapsigner/autosign/result,目录下,需要签名的hap包放到developtools/hapsigner/autosign目录下。
2、修改配置文件
修改developtools/hapsigner/autosign/signHap.config
// Common configuration, will be overwrite by detail config
#common.keystoreFile 改为 OpenHarmony.p12
common.keystoreFile=OpenHarmony.p12
common.keystorePwd=123456
common.signAlg=SHA256withECDSA
common.mode=localSign
// You must change this instead of using default
common.keyPwd=123456
common.issuerKeyPwd=123456
// keypair of app signature
#pp.keypair.keyAlias 改为 OpenHarmony Application Release
app.keypair.keyAlias=OpenHarmony Application Release
app.keypair.keyPwd=123456
// App signature cert
#cert.app.outFile 改为penHarmonyApplication.pem
cert.app.outFile=OpenHarmonyApplication.pem
// Sign profile
#sign.profile.outFile 改为要签名的包里面的p7b文件
sign.profile.outFile=settingsdata.p7b
// Sign app
#要签名的包
sign.app.inFile=SettingsData-unsigned.hap
#生成签名的包
sign.app.outFile=SettingsData-signed.hap
3、执行脚本
修改完成后,执行脚本sign_hap.sh,提示Success表示签名成功,生成的文件在developtools/hapsigner/autosign/result/目录下,Settings-signed.hap。
4、push文件
hdc操作
hdc target mount
hdc shell rm -rf /data/misc_de/0/mdds/0/default/bundle_manager_service
hdc shell rm -rf /data/accounts
hdc shell mount -o remount,rw /
hdc file send C:\Users\XXX\Desktop\openharmony\Settings\Settings.hap /system/app/com.ohos.settings/Settings.hap
hdc file send C:\Users\XXX\Desktop\openharmony\Settings\SettingsData.hap /system/app/com.ohos.settingsdata/SettingsData.hap
echo "push Settings sueecess start reboot"
hdc shell mount -o remount,rw /
hdc shell rm /data/* -rf
hdc shell sync /system/bin/udevadm trigger
hdc shell reboot
重启后,应用重新加载,成功!