HarmonyOS鸿蒙Next中通过inputMethodEngine.Panel.setUiContent拉起的page无法断点调试

HarmonyOS鸿蒙Next中通过inputMethodEngine.Panel.setUiContent拉起的page无法断点调试

在IME Kit中

自建输入法:

export default class ServiceExtAbility extends InputMethodExtensionAbility {
  onCreate(want: Want): void {
    this.addLog(`onCreate want: ${want.abilityName}`);
    keyboardController.onCreate(this.context);
  }

  onDestroy(): void {
    this.addLog('onDestroy');
    keyboardController.onDestroy();
  }

  addLog(message: string): void {
    Log.showInfo(TAG, `kikaInput-new: ${message}`);
  }
}

拉起自定义键盘界面:

inputMethodAbility.createPanel(this.mContext, panelInfo).then((panel: inputMethodEngine.Panel) => {
  this.panel = panel;
  panel.resize(dWidth, keyHeight).then(() => {
    panel.moveTo(0, this.barPosition).then(() => {
      panel.setUiContent('pages/Index').then(() => {
        this.inputHandle.addLog('loadContent finished');
      })
    })
  })
})

这时候在Index的page里面想要断点调试,无法命中断点:

aboutToAppear(): void {
  // 感知是否设置沉浸模式,如果是沉浸模式选择沉浸模式类型
  inputMethodEngine.getKeyboardDelegate().on("editorAttributeChanged", (attr : inputMethodEngine.EditorAttribute) => {
    console.info('recv editorAttributeChanged, immersiveMode: ', attr.immersiveMode);
    if (attr.immersiveMode == 1) {
      this.panel?.setImmersiveMode(inputMethodEngine.ImmersiveMode.DARK_IMMERSIVE);
      console.info('recv editorAttributeChanged, panel:', this.panel?.getImmersiveMode());
    }
  })
}

更多关于HarmonyOS鸿蒙Next中通过inputMethodEngine.Panel.setUiContent拉起的page无法断点调试的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

在HarmonyOS Next中,通过inputMethodEngine.Panel.setUiContent拉起的软键盘页面属于输入法扩展服务,运行在独立的扩展进程(如com.ohos.inputmethod)中。断点调试失败是因为当前调试会话默认附加在主应用进程上。要调试该页面,需在DevEco Studio的调试配置中手动附加到对应的扩展进程。

更多关于HarmonyOS鸿蒙Next中通过inputMethodEngine.Panel.setUiContent拉起的page无法断点调试的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS Next中,通过inputMethodEngine.Panel.setUiContent加载的页面确实存在调试限制。这是因为输入法面板(Panel)作为系统级服务组件,其加载的UI页面运行在独立的渲染进程中,与DevEco Studio的调试器默认连接的UI主进程不同。

目前针对这种场景的调试,建议采用以下替代方案:

  1. 增强日志输出:在关键代码路径(如aboutToAppear、事件回调等)使用console.info()Log类输出详细日志,通过日志分析定位问题。

  2. 使用hilog命令行工具:通过hilog命令实时查看输入法服务的日志输出:

    hilog | grep your_tag
    
  3. 模拟器/真机调试模式:确保在module.json5中正确配置输入法扩展能力:

    "extensionAbilities": [{
      "type": "inputMethod",
      "srcEntry": "./ets/inputmethodextability/ServiceExtAbility.ts"
    }]
    
  4. 分离调试:将核心业务逻辑抽离到可独立调试的公共模块中,先确保基础逻辑正确,再集成到输入法面板。

  5. 检查资源配置:确认pages/Index页面路径配置正确,且相关资源已打包到HAP中。

输入法扩展能力的调试支持仍在持续优化中,后续版本可能会提供更完善的调试工具链。当前阶段通过组合使用日志输出和逻辑验证是最高效的问题排查方式。

回到顶部