简体   繁体   中英

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. However, Flutter docs seem to only document how to do it with the iOS simulator or Android emulators.

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.

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)?

Additional context

  • I'm a web developer.
  • I use Android Studio and VS Code.
  • I work on a MacBook.

For Android, this is pretty easy:

  1. Enable Developer options and USB debugging on your device. This varies slightly by Android version, but the short version is you tap on the Device Build Number 7 times. Then a "Developer Options" option comes up and you can click "enable USB Debugging." See the linked Android documentation for the most up-to-date instructions.
  2. Then plug your phone into your computer with a USB cable. You'll probably see some popup on your phone asking if you want to allow USB debuggng with that computer. Say "yes".
  3. Run Flutter just like you would if you had a simulator running.

For iOS this is a little more complicated because you need an Apple ID or to sign up for a " Developer Account ":

  1. Open XCode, then open "Preferences>Accounts". Sign in with your ID.
  2. "Manage Certificates" > click on the "+" sign and select "iOS Development".
  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.

(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.)

Also you can use your device wirelessly using scrcpy.

Visit this link and install scrcpy. https://github.com/Genymobile/scrcpy

After you install and path scrcpy on your PC/Laptop.

  1. Make sure your phone is connected to your PC/Laptop.

  2. Enable Developers Options and Connect your device to the WIFI.

  3. Open CMD.

  4. Input "adb tcpip 5555". The adb should be restarted

  5. Next, input "adb connect ipaddressofyourdevice:5555" Ex: adb connect 192.168.254.19:5555

Now, you can use your device wirelessly.

Deploy to iOS devices

To deploy your Flutter app to a physical iOS device, you'll need some additional tools and an Apple account. You'll also need to set up physical device deployment in Xcode.

  1. Install homebrew .

  2. Open the terminal and run these commands to install the tools for deploying Flutter apps to iOS devices.

     $ 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.

  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.

  4. In Xcode, select the Runner project in the left navigation panel.

  5. In the Runner target settings page, make sure your Development Team is selected under 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).

    • To start your first iOS development project, you may need to sign into Xcode with your Apple ID.

    Development and testing is supported for any Apple ID. Enrolling in the Apple Developer Program is required to distribute your app to the App Store. To create an Apple ID, follow the instructions on the Apple help page .

    • 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. Select Trust in the dialog prompt when first connecting the iOS device to your Mac .

    Then, go to the Settings app on the iOS device, select General > Device Management and trust your Certificate.

  6. If automatic signing fails in Xcode, verify that the project's General > Identity > Bundle Identifier value is unique.

  7. Start your app by running flutter run

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

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

Attach your real device on your development PC. To check setup process, run flutter doctor command. If result success of all required criteria then hit

flutter run

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM