一、导出模板配置(export_presets.cfg)
在Godot项目根目录的export_presets.cfg
中添加鸿蒙配置段:
ini
[preset.harmonyos]
name="HarmonyOS"
platform="HarmonyOS"
runnable=true
export_filter="all_resources"
# 基础配置
custom_template="harmonyos/release"
application/name="MyGame"
package/package_name="com.example.mygame"
version/code="1"
version/name="1.0.0"
icon="res://icon.png"
# 设备与分布式支持
harmonyos/supports_devices=["phone","tablet"]
harmonyos/distributed_capabilities=["cross_device_launch"]
# 权限声明
harmonyos/permissions=[
"ohos.permission.GRAPHICS_ACCESS",
"ohos.permission.INTERNET",
"ohos.permission.DISTRIBUTED_DATASYNC"
]
关键参数说明:
custom_template
:指向编译好的鸿蒙导出模板distributed_capabilities
:声明支持跨设备启动能力supports_devices
:需同时支持手机和平板时使用数组格式
二、config.json核心配置
在DevEco Studio项目的src/main/resources/config.json
中添加:
json
{
"app": {
"bundleName": "com.example.mygame",
"vendor": "example",
"versionCode": 1,
"versionName": "1.0.0"
},
"deviceConfig": {
"default": {
"graphics": {
"apiLevel": "[email protected]", // 必须声明Vulkan版本
"useBufferAge": true
},
"storage": {
"dataAccessible": "all"
}
}
},
"module": {
"abilities": [{
"name": "EntryAbility",
"orientation": "landscape", // 强制横屏
"continuable": true, // 允许跨设备流转
"metaData": {
"customizeData": [{
"name": "godotMainScene",
"value": "res://main.tscn"
}]
}
}],
"requestPermissions": [{
"name": "ohos.permission.GRAPHICS_ACCESS"
},{
"name": "ohos.permission.INTERNET"
},{
"name": "ohos.permission.DISTRIBUTED_DATASYNC",
"reason": "跨设备多人游戏需要"
}]
}
}
重点配置项:
- 图形能力:必须声明Vulkan 1.3以兼容Godot渲染管线
- 存储权限 :通过
dataAccessible
控制存档文件访问范围 - 分布式能力 :设置
continuable=true
启用跨设备流转 - 传感器支持(如需要):
json
"deviceConfig": {
"sensors": ["accelerometer", "gyroscope"]
}
三、适配注意事项
- 图形优化 :建议在Godot项目设置中启用
rendering/vulkan/use_half_float=true
提升性能 - 输入适配 :鸿蒙分布式设备需通过
Input.singleton.parse_input_event
处理跨端输入事件 - 日志调试 :通过
hilog.info("Godot", "Log message")
替换原生print输出 - 包体控制 :使用鸿蒙的
app_packing
工具压缩HAP包时,建议开启LZ4HC压缩算法
四、典型问题处理
- 权限拒绝 :在
module.json5
中补充声明:
json
"abilities": [{
"permissions": ["ohos.permission.GRAPHICS_ACCESS"]
}]
- 触控失灵 :检查
config.json
是否声明:
json
"reqPermissions": [{
"name": "ohos.permission.TOUCH_EVENT"
}]