简体   繁体   English

如何在真实设备上运行/测试我的 Flutter 应用程序?

[英]How do I run/test my Flutter app on a real device?

I want to run/test (not automated test) my Flutter app on a real iPhone and Android phone during development.我想在开发期间在真实的 iPhone 和 Android 手机上运行/测试(不是自动测试)我的 Flutter 应用程序。 However, Flutter docs seem to only document how to do it with the iOS simulator or Android emulators.然而,Flutter 文档似乎只记录了如何使用 iOS 模拟器或 Android 仿真器进行操作。

I think it's already a no-brainer for iOS/Android devs but I am neither and Flutter is my first foray into mobile development.我认为这对于 iOS/Android 开发人员来说已经是一个无需动脑筋的事情,但我两者都不是,而 Flutter 是我第一次涉足移动开发。

Is there any link to a beginner's guide somewhere on how to develop while running it on a real device (with all of Flutter's live-reload goodness)?是否有关于如何在真实设备上运行它时进行开发的初学者指南的任何链接(具有 Flutter 的所有实时重载优势)?

Additional context附加上下文

  • I'm a web developer.我是 web 开发人员。
  • I use Android Studio and VS Code.我使用 Android Studio 和 VS Code。
  • I work on a MacBook.我在 MacBook 上工作。

For Android, this is pretty easy:对于 Android,这很简单:

  1. Enable Developer options and USB debugging on your device.在您的设备上启用开发人员选项和 USB 调试。 This varies slightly by Android version, but the short version is you tap on the Device Build Number 7 times.这因 Android 版本而略有不同,但简短版本是您点击设备版本号 7 次。 Then a "Developer Options" option comes up and you can click "enable USB Debugging."然后出现“开发人员选项”选项,您可以单击“启用 USB 调试”。 See the linked Android documentation for the most up-to-date instructions.有关最新说明,请参阅链接的 Android 文档。
  2. Then plug your phone into your computer with a USB cable.然后使用 USB 数据线将手机插入计算机。 You'll probably see some popup on your phone asking if you want to allow USB debuggng with that computer.您可能会在手机上看到一些弹出窗口,询问您是否要允许使用该计算机进行 USB 调试。 Say "yes".说“是”。
  3. Run Flutter just like you would if you had a simulator running.就像运行模拟器一样运行 Flutter。

For iOS this is a little more complicated because you need an Apple ID or to sign up for a " Developer Account ":对于 iOS,这有点复杂,因为您需要一个 Apple ID 或注册一个“开发者帐户”:

  1. Open XCode, then open "Preferences>Accounts".打开 XCode,然后打开“首选项>帐户”。 Sign in with your ID.使用您的 ID 登录。
  2. "Manage Certificates" > click on the "+" sign and select "iOS Development". “管理证书”> 单击“+”号并选择“iOS 开发”。
  3. Plug your device into your machine.将您的设备插入您的机器。 Find your device in the drop down (Window > Organizer).在下拉菜单中找到您的设备(窗口 > 管理器)。
  4. Below the Team pop-up menu, click Fix Issue.在团队弹出菜单下方,单击修复问题。
  5. In Xcode , click the Run button.在 Xcode 中,单击运行按钮。

(in subsequent runs, you can deploy to the iOS device with Android Studio, VS Code, or any other IDE of choice, you just need to set up that certificate the first time with Xcode. Here's Apple's documentation on setting up Xcode to run a physical device.) (在后续运行中,您可以使用 Android Studio、VS Code 或任何其他选择的 IDE 部署到 iOS 设备,您只需要在第一次使用 Xcode 设置该证书。这是 Apple 的文档关于设置 Xcode 以运行物理设备。)

Also you can use your device wirelessly using scrcpy.您也可以使用 scrcpy 无线使用您的设备。

Visit this link and install scrcpy.访问此链接并安装 scrcpy。 https://github.com/Genymobile/scrcpy https://github.com/Genymobile/scrcpy

After you install and path scrcpy on your PC/Laptop.在您的 PC/笔记本电脑上安装并路径 scrcpy 后。

  1. Make sure your phone is connected to your PC/Laptop.确保您的手机已连接到 PC/笔记本电脑。

  2. Enable Developers Options and Connect your device to the WIFI.启用开发者选项并将您的设备连接到 WIFI。

  3. Open CMD.打开 CMD。

  4. Input "adb tcpip 5555".输入“adb tcpip 5555”。 The adb should be restarted应该重新启动 adb

  5. Next, input "adb connect ipaddressofyourdevice:5555" Ex: adb connect 192.168.254.19:5555接下来,输入“adb connect ipaddressofyourdevice:5555” 例如:adb connect 192.168.254.19:5555

Now, you can use your device wirelessly.现在,您可以无线使用您的设备。

Deploy to iOS devices部署到 iOS 设备

To deploy your Flutter app to a physical iOS device, you'll need some additional tools and an Apple account.要将 Flutter 应用程序部署到物理 iOS 设备,您需要一些额外的工具和一个 Apple 帐户。 You'll also need to set up physical device deployment in Xcode.您还需要在 Xcode 中设置物理设备部署。

  1. Install homebrew .安装自制软件

  2. Open the terminal and run these commands to install the tools for deploying Flutter apps to iOS devices.打开终端并运行这些命令以安装用于将 Flutter 应用程序部署到 iOS 设备的工具。

     $ brew update $ brew install --HEAD libimobiledevice $ brew install ideviceinstaller ios-deploy cocoapods $ pod setup

    If any of these commands fails with an error, run brew doctor and follow the instructions for resolving the issue.如果这些命令中的任何一个失败并出现错误,请运行 brew doctor 并按照说明解决问题。

  3. Follow the Xcode signing flow to provision your project: Open the default Xcode workspace in your project by running open ios/Runner.xcworkspace in a terminal window from your Flutter project directory.按照 Xcode 签名流程配置您的项目: 通过在 Flutter 项目目录的终端窗口中运行 open ios/Runner.xcworkspace来打开项目中的默认 Xcode 工作区。

  4. In Xcode, select the Runner project in the left navigation panel.在 Xcode 中,在左侧导航面板中选择 Runner 项目。

  5. In the Runner target settings page, make sure your Development Team is selected under General > Signing > Team .在 Runner 目标设置页面中,确保在General > Signing > Team下选择了您的开发General > Signing > Team When you select a team, Xcode creates and downloads a Development Certificate, registers your device with your account, and creates and downloads a provisioning profile (if needed).当您选择一个团队时,Xcode 会创建并下载开发证书,使用您的帐户注册您的设备,并创建和下载配置文件(如果需要)。

    • To start your first iOS development project, you may need to sign into Xcode with your Apple ID.要开始您的第一个 iOS 开发项目,您可能需要使用您的 Apple ID 登录 Xcode。

    Development and testing is supported for any Apple ID.任何 Apple ID 都支持开发和测试。 Enrolling in the Apple Developer Program is required to distribute your app to the App Store.需要注册 Apple Developer Program 才能将您的应用分发到 App Store。 To create an Apple ID, follow the instructions on the Apple help page .要创建 Apple ID,请按照Apple 帮助页面上的说明进行操作。

    • The first time you use an attached physical device for iOS development, you will need to trust both your Mac and the Development Certificate on that device.第一次使用连接的物理设备进行 iOS 开发时,您需要信任您的 Mac 和该设备上的开发证书。 Select Trust in the dialog prompt when first connecting the iOS device to your Mac .首次将 iOS 设备连接到 Mac 时,在对话框提示中选择信任

    Then, go to the Settings app on the iOS device, select General > Device Management and trust your Certificate.然后,转到 iOS 设备上的“设置”应用程序, select General > Device Management并信任您的证书。

  6. If automatic signing fails in Xcode, verify that the project's General > Identity > Bundle Identifier value is unique.如果 Xcode 中的自动签名失败,请验证项目的General > Identity > Bundle Identifier值是否唯一。

  7. Start your app by running flutter run通过运行flutter run启动您的应用程序

For more info: https://kobiton.com/topics/develop-deploy-and-test-flutter-apps/更多信息: https : //kobiton.com/topics/develop-deploy-and-test-flutter-apps/

您将在此链接后找到在真实物理iOS 设备上运行 Flutter 应用程序的完整故障排除指南- 带热重载⚡️ - 适用于 M1 和 Intel Macs

Attach your real device on your development PC.将您的真实设备连接到您的开发 PC 上。 To check setup process, run flutter doctor command.要检查设置过程,请运行flutter doctor命令。 If result success of all required criteria then hit如果所有必需条件的结果都成功,则点击

flutter run

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在没有苹果开发者帐户的真实苹果设备上测试我的 Flutter 应用程序,如果可以,我该怎么做? - Can I test my Flutter application in a real apple device without apple developer account, and if so how do I do it? 如何使用 Expo 在真实的 iOS 设备上运行应用程序? - How do I run an app on a real iOS device using Expo? 如何在发布/分发模式下在设备上测试App? - How do I test App on my device in release/distribution mode? 当我在真实设备上运行应用程序时,Xcode崩溃 - Xcode crashes when i run the app on my real device 如何在真实设备上测试Braintree + Apple Pay? - How do I test Braintree + Apple Pay on a real device? 启动应用程序后,如何从测试广告过渡到真实广告? - How do I transition from test ads to real ads when I launch my app? 无法在调试模式下在真实 ios 设备上运行 flutter 应用程序 - Can't run flutter app on real ios device in debug mode 在真实设备中测试iPhone应用程序 - Test iPhone app in real device 我可以在我的物理 iPhone 设备上通过 VSCode (Windows) 测试我的 Flutter 应用程序吗? - Can I test my Flutter App from VSCode (Windows) on my physical iPhone device? 如何在Xcode 9的iOS设备上运行我的App? - How I can run my App on my iOS device in Xcode 9 ?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM