[英]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附加上下文
For Android, this is pretty easy:对于 Android,这很简单:
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 或注册一个“开发者帐户”:
(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 后。
Make sure your phone is connected to your PC/Laptop.确保您的手机已连接到 PC/笔记本电脑。
Enable Developers Options and Connect your device to the WIFI.启用开发者选项并将您的设备连接到 WIFI。
Open CMD.打开 CMD。
Input "adb tcpip 5555".输入“adb tcpip 5555”。 The adb should be restarted
应该重新启动 adb
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 中设置物理设备部署。
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 并按照说明解决问题。
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 工作区。
In Xcode, select the Runner project in the left navigation panel.在 Xcode 中,在左侧导航面板中选择 Runner 项目。
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 会创建并下载开发证书,使用您的帐户注册您的设备,并创建和下载配置文件(如果需要)。
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 帮助页面上的说明进行操作。
Then, go to the Settings app on the iOS device, select General > Device Management
and trust your Certificate.然后,转到 iOS 设备上的“设置”应用程序,
select General > Device Management
并信任您的证书。
If automatic signing fails in Xcode, verify that the project's General > Identity > Bundle Identifier
value is unique.如果 Xcode 中的自动签名失败,请验证项目的
General > Identity > Bundle Identifier
值是否唯一。
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.