Skip main navigation
We use cookies to give you a better experience, if that’s ok you can close this message and carry on browsing. For more info read our cookies policy.
We use cookies to give you a better experience. Carry on browsing if you're happy with this, or read our cookies policy for more information.

Skip to 0 minutes and 6 secondsLet's set up a hardware device so that we can work with the code from Android Studio on the device using a USB connection. To do that, I have opened up this website from Google. And you should go there and follow the instructions that are on this webpage. First of all, you need to enable the on-device developer options on your phone. You can see that in this section. And you have to go through these things. Otherwise, it just won't work. There are different ways of doing it, depending on what level your Android API is at on your phone. OK. Once you've done that, then you should go in and set up on Android Studio.

Skip to 0 minutes and 56 secondsThe first part here has already been done. I have made sure that the code is actually debuggable. And then you need to enable the USB debugging on your device, which you just did. And then you have to set up the system to detect your device. Now this is different on the different operating systems that we're working with. If you have a Windows machine, you have to follow this link and do what is here. This is quite a substantial page of work. You have to follow them very carefully, because if you do something wrong here, it might mean that you can't get it to work at all. So follow it very, very carefully.

Skip to 1 minute and 39 secondsYou need to go and get some devices from the manufacturer. And you have to get the driver, the device driver, from the manufacturer that is matching the exact phone that you have. If you get the wrong one, it won't work. So make sure you get the correct one and instal that. Follow all the instructions if you are on Windows. If you're on Mac, well isn't this saying that they will just work? So, yes, it should just work. If it doesn't, well, there's something else wrong. So it should just work on Mac. On Linux, you have to set up a rule that allows the device to connect. So you follow this bullet point here and set that up.

Skip to 2 minutes and 26 secondsYou need the code from this table. And put that into this line here. And if you have more devices, you just create a line for each of the different devices with the appropriate code. Remember that if you have a new Android device or an Android device of high level, over 4.22, 4.22 or higher, then you need to also allow the device to use the USB connection. That happens once you connect it. So you have to do that as well. But once this is done, you should actually be able to run the code on your phone. We start the app on the device by clicking the Run App button here.

Skip to 3 minutes and 15 secondsNow Gradle is creating all the files that are necessary for running on the device. Takes a little bit of time.

Skip to 3 minutes and 27 secondsNow, when this comes up, you can see that we have the Samsung phone here. Mine is an S2. This is the name of it. And that is ready to be launched. So we just highlight it as it is here and press OK. And now it's actually transferring, Android Studio is transferring all the files over to the phone. And I have it on my phone. You can obviously not see it, but I am actually sitting here playing the game right now. So, yeah. That's how you would transfer it to a device.

Setting up an Android device (direct connection)

Setting up on your Android device using direct USB connection allows debugging which you cannot achieve if you set up the game using the APK method in the next Step. However, finding appropriate drivers for your device could be tricky. “Googling” the device make and model for drivers generally works.

Go to Using Hardware Devices on the Android Developers website to follow the steps to setup your device.

If you have difficulty finding drivers for your device post a message in the comments section giving details of your device make and model. Someone in the community may be able to help.

Please note

- When you connect the device there will be a pop-up on the device prompting for authorisation. If you don’t see it, reconnect the USB cable and the pop-up should appear on the device. Authorise the device.

- If the device still doesn’t show up in the list of devices after re-connecting, it could be that you’re using a ‘charging USB cable’ rather than a ‘data USB cable’. The package of the USB cable should say what it is.

In the previous video we also show ‘comments’ in a program (09:10). If you missed it in the previous Step, you can have a look at page 9 of the guide to catch up.

Share this video:

This video is from the free online course:

Begin Programming: Build Your First Mobile Game

University of Reading

Contact FutureLearn for Support