This content originally appeared on DEV Community and was authored by HarmonyOS
Read the original article:How to Handle Dynamic bundleName in shortcuts_config.json
Question
I want to configure bundleName dynamically in shortcuts_config.json using a value from strings.json, but it doesn't work. How can I achieve dynamic bundleName configuration for shortcuts?
Short Answer
shortcuts_config.json does not support dynamic values for bundleName. To handle dynamic bundleName, you need to modify the module.json5 file programmatically during the build process, for example using Hvigor’s plugin hooks. You can fins the related example below;
import { hapTasks, OhosHapContext, OhosPluginId } from '@ohos/hvigor-ohos-plugin';
import { getNode } from '@ohos/hvigor'
const entryNode = getNode(__filename);
entryNode.afterNodeEvaluate(node => {
const hapContext = node.getContext(OhosPluginId.OHOS_HAP_PLUGIN) as OhosHapContext;
const moduleJsonOpt = hapContext.getModuleJsonOpt();
// Modify metadata to point to shortcuts config resource
moduleJsonOpt.module.abilities[0].metadata[1] = {
"name": "ohos.ability.shortcuts",
"resource": "$profile:shortcuts_config"
};
hapContext.setModuleJsonOpt(moduleJsonOpt);
});
export default {
system: hapTasks,
plugins: []
}
Applicable Scenarios
When your app’s bundleName changes per build/profile and you want your shortcut configuration to reflect that without hardcoding the value.
Reference Link
https://developer.huawei.com/consumer/en/doc/harmonyos-guides/ide-build-expanding-context
Written by Emincan Ozcan
This content originally appeared on DEV Community and was authored by HarmonyOS
HarmonyOS | Sciencx (2025-11-18T03:48:42+00:00) How to Handle Dynamic bundleName in shortcuts_config.json. Retrieved from https://www.scien.cx/2025/11/18/how-to-handle-dynamic-bundlename-in-shortcuts_config-json/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.