使用github操作在Android上测试Flutter应用

    科技2025-02-18  11

    In a previous piece, I discussed how to test Flutter apps on iOS devices with GitHub Action:

    在上一篇文章中,我讨论了如何使用GitHub Action在iOS设备上测试Flutter应用程序:

    However, with the wide variety of Android devices (e.g. folding screen and dual-screen), it makes sense to test Android devices as well.

    但是,由于Android设备种类繁多(例如折叠屏和双屏),因此测试Android设备也很有意义。

    Note: I borrowed the code from my side project, Mini Donkey, a utility app that helps do encrypted steganography to protect privacy. For more details on how to apply the code to a real project. Please check out the repository.

    注意:我从辅助项目 Mini Donkey 借来了代码, Mini Donkey 是一个实用程序应用程序,可帮助进行加密隐写术以保护隐私。 有关如何将代码应用于实际项目的更多详细信息。 请检出 存储库 。

    1:营造环境 (1: Build the Environment)

    We can build an environment with Java 8 and Flutter on macOS with the following GitHub Action configuration:

    我们可以使用以下GitHub Action配置在macOS上使用Java 8和Flutter构建环境:

    A couple of gotchas:

    几个陷阱:

    The platform the emulator runs on must be “macOS-latest” — other types of containers don’t support the accelerator virtualization Android emulator requires.

    模拟器运行的平台必须是“最新的macOS”-其他类型的容器不支持Android模拟器所需的加速器虚拟化。 The Java version has to be 8 because there’s a bug with Java 9+ and the Android SDK manager binary.

    Java版本必须为8,因为Java 9+和Android SDK管理器二进制文件存在错误。

    2:定义感兴趣的设备矩阵 (2: Define a Matrix of Devices of Interests)

    With the environment defined, we can list the devices we want to verify our Flutter code on with the following configuration:

    定义了环境后,我们可以使用以下配置列出要验证其Flutter代码的设备:

    Note: feel free to add more devices, according to android emulator runner, a full list of supported devices can be found using avdmanager list .

    注意:您可以随意添加更多设备,根据android仿真器运行程序 ,可以使用avdmanager list找到支持的设备的avdmanager list 。

    33:启动仿真器并运行集成测试 (33: Spin Up Emulators and Run Integration Tests)

    Supplying the Android Emulator Runner Action with a Flutter integration test script will spin up our tests:

    为Android Emulator Runner Action提供Flutter集成测试脚本将加速我们的测试:

    4:坐下来喝杯咖啡 (4: Sit Back and Get a Cup of Coffee)

    Hooray! Here’s a quick look at our device testing matrix:

    万岁! 快速浏览一下我们的设备测试矩阵:

    tianhaoz95/photochatapp tianhaoz95 / photochatapp的样本CI / CD结果

    谢谢阅读! (Thanks for reading!)

    Special thanks to Yang and Ricky for build Android Emulator Runner Action.

    特别感谢Yang和Ricky构建Android Emulator Runner Action 。

    翻译自: https://medium.com/better-programming/test-flutter-apps-on-android-with-github-actions-abdba2137b4

    相关资源:FlutterGithubUserSearch:一个用于搜索Github用户的Flutter应用程序-源码
    Processed: 0.011, SQL: 8