Leave a rating/review
So far, you’ve tested out the app on an Android emulator. That’s nice and all but probably not why you’re learning Android development. You want to make apps that run on real Android devices!
Now developing on an emulator works very well. During development, I always run and test my app on an emulator then once in a while if there’s a need to, then I’ll test the app on a real device.
However, you do need to run your creations on a real device in order to test them properly. There are some things the Android emulator simply cannot do.
For example, let’s say you’re creating a car racing game and you need to use the accelerometer to control the steering.
Your laptop probably doesnt have an accelerometer and even if it does, imagine how weird it would look if you moved it around like a steering wheel while developing the app.
In this scenario your app needs the devices’s accelerometer and you have no choice but to test that functionality on an actual device.
Let’s give it a shot!
I’ll show you how to run your app using a USB cable and also how to run it over a wifi connection. Okay, so I’m gonna start by running the app on my Android device using a USB cable connected to my computer.
In order to do that, you first need to go to Settings on your device. I have my android device here mirrored using an app called Vysor. So, what you’re seeing here on the screen is actually my android device plugged into my computer.
To connect your device via USB and run the app, you first need to enable USB Debugging. To do this, your phone must be setup for development. Now do note that the exact process here will change slightly between different phones and versions of Android, but the basic steps should still remain the same.
Okay, let’s do that now.
- Open the Settings app.
- Scroll to the bottom and select About phone.
- Then select “Software Information”
- Locate the Build number.
- Then tap it seven times. You’ll see a message that says: “Developer mode has been enabled”
- I have developer mode previously enabled so you see the message telling us that’s there no need to enable it again.
- Head back to the settings screen, scroll to the bottom, and tap Developer options.
- In the Developer options window, scroll down and enable USB debugging.
I already have it enabled here because Vysor, the mirroring software, needs it to work. When you enable it, a dialog would pop up, then you just tap OK.
Once you’re done, go back to the home screen on the device. Then connect your Android device to your computer using a USB cable if you havent already.
Your phone will prompt you with a dialog to allow USB debugging. If this is your computer feel free to check the “Always allow from this computer” option so that you no longer get this message each time you plug in your phone.
Your device is now ready to test your app.
Back in Android Studio, click on the device selection dropdown button beside the run button. You’ll now be able to see your Android device. Go ahead and select it. Then click on the run button. Android Studio installs and starts up Bullseye on your connected device.
Bullseye is now running on a real phone. I can also move the slider with the mouse but its actually running on my phone.
Okay, I’ll go ahead and test out the game by playing some rounds.
Cool!!! Everything works fine and Bullseye is now a finished Android app that runs on a real device.
Now, the new Android Studio Bumblebee version also allows you to run your apps over Wifi. With this, there no need to connect your phone using a usb cable. You only need to make sure that your Android phone and computer are connected to the same wireless network. But this feature only works on Android 11 and up.
Let’s do that now.
For this you need to enable debugging over wifi.
- Head over to developer options
- Scroll down to the debugging section then turn on “Wireless Debugging”
- Select allow on the popup to allow wireless debugging on this network. If this is your computer you can select the always allow option.
That’s the setup for your phone to get things working.
Next, head over to Android Studio. Click on the device selection dropdown button. Then select “Pair Devices Using Wi-Fi” A window opens up and in here, you can pair using QR code or using a pairing code.
At the bottom of the window, you can see where the QR code scanner is located on your Android device. Let’s head back to developer options on our device.
Then click on wireless debugging. And you can see both options for pairing. I’ll select pair device with QR code. It launches the QR code scanner. I’ll head back to Android Studio to scan the QR code. And you should also do that.
And instantly, the device is paired. You can see it was successful. Alright, lets close this window.
And if you check the list of devices, you can see our phone is automatically selected. You can see tcp at the end of the device name to show that it is paired over a network.
I’ll hit the run button one last time.
Cool!!! We have bullseye up and running on our device connected over wifi.
Play a few rounds if you want.
You now have your first Android app running on a real device device.