HarmonyOS 鸿蒙Next build-profile.json5会被覆盖的问题
HarmonyOS 鸿蒙Next build-profile.json5会被覆盖的问题
使用auto sign会出现签名覆盖的问题导致频繁出现冲突,这个现在有解决方案吗
2 回复
import { appTasks, OhosPluginId } from '@ohos/hvigor-ohos-plugin';
import * as data from "./data.json"
import { getNode } from '@ohos/hvigor'
export default {
system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins: [customPlugin()], /* Custom plugin to extend the functionality of Hvigor. */
// config: {
// ohos: {
// overrides:{
// signingConfig: getSigningConfig(), //签名配置对象
// appOpt: {
// versionCode: getVersionCode(),
// versionName: getVersionName(),
// } //app.json中的内容
// }
// }
// }
}
function customPlugin(): HvigorPlugin{
return {
pluginId: 'customPlugin',
apply(currentNode: HvigorNode){
// 插件主体
console.log('hello customPlugin!');
hapTask();
}
}
}
function hapTask(entry:HvigorNode) {
const rootNode = getNode(__filename);
rootNode.afterNodeEvaluate(node => {
// 获取app插件的上下文对象
const appContext = node.getContext(OhosPluginId.OHOS_APP_PLUGIN) as OhosAppContext;
// 通过上下文对象获取从根目录build-profile.json5文件中读出来的obj对象
const buildProfileOpt = appContext.getBuildProfileOpt();
// 修改obj对象为想要的,此处举例修改app中的signingConfigs
buildProfileOpt['app']['signingConfigs'] = [
{
"name": "default",
"type": "HarmonyOS",
"material": {
"certpath": data.certpath,
"storePassword": data.storePassword,
"keyAlias": data.keyAlias,
"keyPassword": data.keyPassword,
"profile": data.profile,
"signAlg": data.signAlg,
"storeFile": data.storeFile
}
}
];
// 将obj对象设置回上下文对象以使能到构建的过程与结果中
appContext.setBuildProfileOpt(buildProfileOpt);
})
}