65

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.
Paresh Mangukiya
  • 37,512
  • 17
  • 201
  • 182
Noel Llevares
  • 13,607
  • 2
  • 51
  • 79
  • you could use Android Studio or intellij Ide and run the app as a normal android app by clicking green run button from the run menu. https://flutter.io/docs/get-started/codelab codelab and getting started page – Raghunandan Jan 30 '19 at 15:57
  • 1
    That runs it in a simulator which is not what I want. I can't see anything in that page about setting up my real device. – Noel Llevares Jan 30 '19 at 16:05
  • 1
    Have a look at this [answer](https://stackoverflow.com/a/49055266/4366237) – Umair M Jan 30 '19 at 16:11
  • Possible duplicate of [flutter run: No connected devices](https://stackoverflow.com/questions/49045393/flutter-run-no-connected-devices) – Richard Heap Jan 30 '19 at 16:16
  • It works on a real device ( made it myself ), but you need to enroll for iOS development program and have knowledge about Xcode – CZ54 Jan 30 '19 at 16:20
  • @dashmug no you can run it on a real device. follow the docs. i have run samples on my phone as well – Raghunandan Jan 30 '19 at 16:27
  • (1) Are you trying to run on an Android or an iOS device? (2) Can you post the output of `flutter doctor` while your device is connected to your computer? – Edman Jan 30 '19 at 16:30

3 Answers3

81

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

fortuna
  • 858
  • 7
  • 5
  • 15
    How do you "Run Flutter just like you would if you had a simulator running." – Sam Mar 07 '20 at 10:30
  • @Sam just press Debug (the green arrow button) – Francesco B. Dec 07 '20 at 23:04
  • 3
    it helps if you use the right kind of cable. the first one i tried was only charging, the moment i switched it out for a data cable vscode detected the device – therightstuff Dec 27 '20 at 08:13
  • @FrancescoB. What button? Where is that? – Moberg Jan 03 '21 at 14:20
  • @Moberg in Visual Studio Code, which I moved to, you gotta open "main.dart" or whatever file contains your void main(){...} function: you'll see an arrow icon to the top right;when you press it, a drop down menu will open and prompt you to choose which device to use. In Android Studio, it seems to me that there's always a green arrow icon to the top right, just below the menu bar; however you first have to pick a device from the dropdown to its left (the one with ). But I'm guessing your IDE is XCode, isn'it? :D – Francesco B. Jan 04 '21 at 10:33
  • 1
    @FrancescoB. I can pick whichever, but referring to the looks of a button without saying which program it can be found in is hard mode :P – Moberg Jan 05 '21 at 07:45
  • @Moberg alright, I see what you mean, thanks – Francesco B. Jan 07 '21 at 14:26
  • In the terminal, use ```flutter run``` – Peter Nielsen Jun 21 '21 at 19:21
  • you might also need to install a physical USB driver for your (android) device (check out ADB driver) - in case it is installed, command `flutter devices` will show this device with its device-id, apart from the default chrome device. then you have to `flutter run -d {device-id}` to specifically target that device.. – hello_earth Aug 14 '21 at 08:04
  • I had to enable "USB debugging" under "Developer options" on Android. I wasn't prompted to do that as it suggests above. – dan-gph Jan 20 '22 at 05:03
3

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/

Paresh Mangukiya
  • 37,512
  • 17
  • 201
  • 182
3

Also, you can use your android 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.