11作者: rekireki6 个月前
前段时间,我决定尝试用 Rust 构建一个 Android 应用。几周后,我成功了。最近 iced 发布了新版本,所以我刚刚将示例更新到了新的 iced 和 wgpu。我想分享我的经验,以吸引更多人关注在 Android 上使用 Rust。 首先,我要感谢所有为以下基础 crate 和工具做出贡献的人: * [https://github.com/rust-mobile/android-activity](https://github.com/rust-mobile/android-activity) * [https://github.com/jni-rs/jni-rs](https://github.com/jni-rs/jni-rs) * [https://github.com/gfx-rs/wgpu](https://github.com/gfx-rs/wgpu) * [https://github.com/rust-windowing/winit](https://github.com/rust-windowing/winit) * 等等 当我开始时,我需要了解已经存在哪些工具和示例。幸运的是,已经有一套很好的示例,同时使用了 NativeActivity 和 GameActivity: [https://github.com/rust-mobile/rust-android-examples](https://github.com/rust-mobile/rust-android-examples) 基本方法是使用 android-activity、winit 和 wgpu,就这么简单。除此之外,你可以在 rust-android-examples 仓库中找到一些 egui 示例。 好的,在运行了基本示例之后,我想将它们与 iced 结合起来。Iced 是一个跨平台的 GUI 库,主要面向桌面和 Web。据我目前所知,它明确不以移动端为目标。然而,有人在某个问题中发布了他们的实验。我就是这样知道这是可行的: [https://github.com/iced-rs/iced/issues/302](https://github.com/iced-rs/iced/issues/302) 有一种方法可以将 iced 集成到 wgpu 应用程序中,被称为集成示例: [https://github.com/iced-rs/iced/tree/0.14.0/examples/integration](https://github.com/iced-rs/iced/tree/0.14.0/examples/integration) 上面我提到,将 winit 和 wgpu 与 android-activity 结合使用就足以构建应用程序了。将 1 + 1 加起来,我得到了 2:让我们将 iced 集成示例与 android-activity 一起使用。编译起来非常容易,几乎没有错误。我遇到的第一个问题是没有渲染文本。我通过这里展示的方式加载字体解决了这个问题: [https://github.com/pop-os/cosmic-text/issues/243#issue-2189977938](https://github.com/pop-os/cosmic-text/issues/243#issue-2189977938) 然后我修补了一些小部件以添加触摸支持。就这样。我的角色是将之前的所有工作结合起来,形成一个可运行的示例。 一些使用 Rust 构建 Android 应用程序的其他方法: * xilem 明确目标是支持移动端 [https://github.com/linebender/xilem](https://github.com/linebender/xilem) * egui 支持移动端 [https://github.com/emilk/egui](https://github.com/emilk/egui) * 游戏引擎,如 Fyrox 和 Bevy 支持移动端: * [https://github.com/FyroxEngine/Fyrox](https://github.com/FyroxEngine/Fyrox) * [https://github.com/bevyengine/bevy](https://github.com/bevyengine/bevy) * 几乎所有基于 winit 和 wgpu 构建的东西 以上所有都与使用 NativeActivity 或 GameActivity 构建原生应用程序有关。我将 Webview 排除在当前帖子的范围之外。 iOS 呢?据我所知,它应该与 Android 类似,甚至可能更简单。我还没有构建它,但下次我有大量空闲时间时,我会尝试让它工作。计划是一样的:选择 winit、wgpu、iced 集成示例,将它们混合在一起直到它工作。它将需要相同的加载字体的技巧,以及可能其他一些东西,但目前没有明显的障碍。 再次感谢所有让这一切成为可能的人,祝你用 Rust 构建移动应用程序时玩得开心!
1作者: 1zael6 个月前
我为旧金山构建了一个开源项目,作为 Citizen App 付费 911 警情推送的替代方案。<p>它从旧金山官方开放数据门户网站实时获取调度数据,使用 LLM(大型语言模型)将警方代码翻译成易于理解的摘要,并自动屏蔽敏感地点(收容所、医院等)。<p>在一次黑客马拉松之夜,我因为 Citizen App 是唯一的实时警情推送选择,而且还收费,感到很恼火,于是就做了这个项目。<p>代码库:<a href="https:&#x2F;&#x2F;github.com&#x2F;midaz&#x2F;sf-police-blotter" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;midaz&#x2F;sf-police-blotter</a> Discord 频道:<a href="https:&#x2F;&#x2F;discord.gg&#x2F;KCkKeKRm" rel="nofollow">https:&#x2F;&#x2F;discord.gg&#x2F;KCkKeKRm</a><p>欢迎讨论技术方案或提出反馈意见。