How do I run/test my Flutter app on a real device?
Asked Answered
B

4

102

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.
Buckden answered 30/1, 2019 at 15:55 Comment(7)
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. flutter.io/docs/get-started/codelab codelab and getting started pageBaillargeon
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.Buckden
Have a look at this answerClip
Possible duplicate of flutter run: No connected devicesSchaffner
It works on a real device ( made it myself ), but you need to enroll for iOS development program and have knowledge about XcodeRadian
@dashmug no you can run it on a real device. follow the docs. i have run samples on my phone as wellBaillargeon
(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?Kerchief
K
124

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.

Using the right cable can make a difference. If the device is charging but nothing happens, try using another cable, preferably the one that came with the device. A notification on the device (e.g. "connected as a media device") and on Windows (e.g. "Device connected and ready to go") are indications that the USB connection is working. You should then be able to see the device on the CLI with:

flutter devices

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

Kolo answered 5/2, 2019 at 1:29 Comment(10)
How do you "Run Flutter just like you would if you had a simulator running."Oatmeal
@Oatmeal just press Debug (the green arrow button)Bumgardner
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 deviceRealize
@FrancescoB. What button? Where is that?Vincevincelette
@Vincevincelette 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 <no devices>). But I'm guessing your IDE is XCode, isn'it? :DBumgardner
@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 :PVincevincelette
@Vincevincelette alright, I see what you mean, thanksBumgardner
In the terminal, use flutter runPerea
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..Strobel
I had to enable "USB debugging" under "Developer options" on Android. I wasn't prompted to do that as it suggests above.Hanker
S
10

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.

Slyke answered 19/4, 2021 at 10:41 Comment(1)
Scrcpy is for screen copy. Does scrcpy actually give a way to test an app under development on the target device? Or is this answer off-topic?Cristinecristiona
S
8

Run flutter devices.

Identify your device.

Run flutter run -d "<device_id>" or flutter run -d "<device_name>".

Sogdiana answered 19/8, 2023 at 11:20 Comment(0)
K
1

Follow These Easy Steps.

  1. Enable Developer Option In Your Mobile.

  2. Connect Your Phone with PC. (Using USB Cable)

  3. Go to Your Flutter Project File Path.

  4. Open Your Terminal.

  5. Enter This Command flutter devices

  6. Next Enter This Command flutter run

  7. Next You Choose Your Device. (As 1,2,3)

Kordofan answered 5/7, 2023 at 16:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.