跳到正文
cccskills
免费在 GitHub 公开中文介绍

jna

实现或调试 Kotlin、Java 的 JNA 绑定时,核对原生声明、字段顺序、对齐方式、调用约定和资源所有权。还可用 JVM 测试发现布局与反射问题,再进行原生集成测试。

原文查看原文说明

Implement or debug JNA bindings and ABI layouts in Kotlin or Java.

JetBrains/intellij-community星标 20,685(GitHub 20,685 + cccskills 0)

实测评分 未实测

查看安装方法

适用场景

  • 定义 JNA 原生结构体
  • 排查 JNA 异常原因
  • 在 JVM 上测试结构体布局
  • 核对 ABI 类型和字段对齐

中文介绍

功能

本技能协助实现和调试从 Kotlin 或 Java 调用原生 API 的 JNA 绑定。它建议先检查 JNA Platform 和仓库中已有的映射,若其中类型与原生声明相符,就优先复用。内容包括结构体字段顺序、整数和指针宽度、对齐方式、调用约定、回调与原生内存的生命周期,以及如何按 ABI 定义映射。指南还说明哪些映射类和字段必须对 JNA 反射可见,以及如何保留和检查异常的完整原因链,以便定位问题。

适用场景

新建原生库连接,或排查结构体大小不匹配、字段访问异常、回调故障时,可以使用本技能。在运行依赖原生界面、权限、硬件或特定操作系统的集成测试之前,也可以先编写 JVM 布局回归测试。

使用示例

  • “请按这份 C 结构体声明检查 JNA 的 Kotlin 定义。”
  • “查明这个 JNA IllegalAccessException 的原因并提出修复办法。”
  • “添加一个 JVM 测试来验证这个 Structure 的大小。”

注意事项

需要核对原生声明、目标架构和所有权规则。依赖权限、硬件或操作系统的原生集成测试,应与布局测试分开处理。

本介绍由 AI(OpenAI Codex)根据公开的 SKILL.md 撰写。准确的规格请查看下方原文。

文档检查

AI 根据 SKILL.md 的内容检查了需要注意的操作和使用前提。评分只依据实际运行的结果(实测对比)。

安全性发送数据、删除文件、执行命令等是否有说明
A良好资料要求核对所有权并分开权限相关测试;未提及外发操作。
安装难易度所需工具和 API 密钥是否少且有说明
B部分不足需要 JNA、JVM 和原生目标环境,但未提供安装步骤。

不计入评分。 由 AI(OpenAI Codex)于 2026年10月28日 评估。仅供参考,安装前请同时查看原文。

如果您认为评估有误,请申请复核

请写明哪一项有误以及原因。无需登录。我们会对照 SKILL.md 重新评估,并在此处更新结果。

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

包含的文件(1)

  • SKILL.md2.8 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

<!-- Generated by community/.ai/render-guides.mjs; edit community/.agents/skills/jna/SKILL.md -->

JNA bindings

Treat every mapping as an ABI contract. Verify the native declaration, target architectures, and ownership rules before changing Kotlin or Java code.

Reuse existing mappings

Search JNA Platform and the repository before declaring a native type. Prefer a maintained platform mapping when its field types, alignment, and calling convention match the target API.

Keep reflected types accessible

JNA reflects mapped classes and fields while deriving layouts and invoking callbacks. Make every Structure, Union, callback, and related declaring class JVM-accessible from com.sun.jna:

  • In Kotlin, use internal or public mapped classes; never use private, local, or anonymous mapped classes.
  • Keep the mapped class's enclosing chain accessible too.
  • Expose structure fields as real public JVM fields, normally with @JvmField.
  • Do not assume public fields compensate for a non-public declaring class. Layout can fail with IllegalAccessException from Structure.getFieldValue.

Prefer moving visibility only as far as needed over suppressing reflection errors or opening accessibility globally.

Match the native ABI

  • Declare structure fields in native order and use @Structure.FieldOrder.
  • Map fixed-width integers, pointers, size_t, native booleans, wide strings, and platform-dependent numeric types deliberately. Do not infer their size from Kotlin or Java names.
  • Model embedded values with Structure.ByValue; model pointers separately with Pointer or the appropriate reference type.
  • Check packing and alignment requirements instead of relying on defaults when the native declaration specifies them.
  • Use the correct calling convention and library options.
  • Keep callback objects and native memory strongly reachable for the full native lifetime, and release owned resources according to the native API.
  • For pointer-backed structures, call read() and write() at the required ownership boundary.

Verify without requiring native UI or permissions

Add a small JVM regression test that constructs each mapped structure and calls size() or otherwise forces JNA to derive its layout. Assert stable sizes or offsets only when they are defined for the tested architecture.

Keep permission-, hardware-, and OS-dependent native integration coverage separate. A layout test should catch visibility and field-order failures before a native callback reaches production code.

When debugging, retain the complete cause chain: wrapper errors often hide the useful IllegalAccessException, invalid field type, alignment error, or callback exception underneath.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

actions

免费有简介

实现或修改 IntelliJ `AnAction`,并在 `plugin.xml` 中注册。将显示名称和说明写入消息资源文件,按需设置图标,并通过事件协程作用域启动挂起任务,避免同步处理阻塞 IDE。

  • 为 IDE 菜单添加操作
  • 修改操作注册或图标
  • 整理操作名称和说明
JetBrains/intellij-community2.1万2026年10月29日 更新

bazel-test-migration

免费有简介

将 IntelliJ JPS 测试模块迁移到 Bazel,并排查仅在 Bazel 中出现的失败。根据症状检查依赖、插件、测试数据和 runfiles,重新生成并验证目标。

  • 将 JPS 测试模块迁移到 Bazel
  • 排查仅在 Bazel 中失败的测试
  • 检查测试依赖和数据配置
JetBrains/intellij-community2.1万2026年10月29日 更新

code-style

免费有简介

按 IntelliJ 项目规范编写或审查 Kotlin 和 Java 代码,涵盖语言选择、格式、密封类型、线程注解及控制流异常处理。

  • 按 IntelliJ 规范编写 Kotlin
  • 审查 Java 代码
  • 检查异常处理和密封类型分支
JetBrains/intellij-community2.1万2026年10月29日 更新

commits

免费有简介

本指南帮助您按 IntelliJ 项目规则拆分更改并撰写提交信息:有工单时使用编号和变更说明,无工单时使用标签与子系统名,并在需要时说明原因和决定。

  • 按项目格式编写带工单号的提交信息
  • 整理测试或文档提交并选择合适标签
  • 按规则修改已有提交信息
JetBrains/intellij-community2.1万2026年10月29日 更新

使用多个 Python 类型检查器比较代码片段或文件的类型推断和报错判断,并汇总各工具的结论、耗时与诊断信息,可保存为 Markdown 报告。

  • 比较不同检查器的类型推断
  • 确认代码是否会被判为类型错误
  • 查看多个工具的诊断差异
JetBrains/intellij-community2.1万2026年10月29日 更新

整理 Compose Desktop 界面中的状态和副作用,让可组合函数负责绘制,由展示器或协调器处理应用决策。了解状态归属、Effect、可复用组件接口、延迟列表键、动画和性能,适用于单项界面修改。

  • 分离界面绘制与展示器决策
  • 整理界面状态的归属
  • 检查 Effect 键和协程用法
JetBrains/intellij-community2.1万2026年10月29日 更新

查看 JetBrains 的全部技能

报告此技能的问题