Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Running the Fun Facts Project4:49 with Ben Deitch
We haven't done any programming yet, but we do have an app! In this video we'll see how to run our app on an Android Virtual Device (AVD). We'll also see where we can find error messages when something goes wrong.
When we create a project, Android Studio creates all the files and 0:00 folders that we need behind the scenes. 0:03 Let's run the project to verify that everything's working. 0:06 We'll also see where to look for 0:09 information about errors if we run into any problems. 0:10 We'll talk about all these different views in Android Studio in a little bit, but 0:14 first let's try to run the app. 0:18 There's a couple ways we can do it. 0:21 We can select Run, from the menu up here, and then choose, Run 'app'. 0:23 Or from the toolbar, we can click on the Run app button. 0:27 I'll choose this option. 0:32 Also, if you like keyboard shortcuts, you can hit Shift+F10 on Windows, or 0:34 Ctrl+R on Mac. 0:38 Now we see the device user dialogue. 0:41 If we had an Android phone or tablet plugged into our computer with a USB 0:44 cable, then it might show up here as a connected device. 0:48 We'll see how to do that later on. 0:51 But for now we want to launch the emulator with the default virtual device. 0:54 If your installation doesn't have a default version virtual device or 0:58 you would like to learn how to create and customize your virtual devices, 1:01 check out the workshop linked in the teacher's notes below. 1:04 Once we have selected a virtual device, we can hit OK. 1:07 Android Studio will launch the emulator and run our app. 1:11 The emulator may take a little bit to load, so be patient. 1:14 The good news is that once the emulator is up, 1:17 we can leave it running to avoid the wait on subsequent runs. 1:20 In the mean time, notice down at the bottom, 1:23 there's a message about a Gradle build. 1:25 Gradle is the name of something that's called a build system. 1:28 And it's responsible for transforming all the raw materials for the app 1:31 here in Android Studio Into something that can be installed on the device. 1:35 And there it is. 1:39 You've just ran your first Android app. 1:40 But what if it isn't working? 1:43 How do we know if something went wrong? 1:45 Back in Android Studio, let's click on Logcat at the bottom of the screen. 1:46 Logcat is Android's logging system. 1:52 It gives us a way to read the system logs, 1:55 which is really useful when debugging an app. 1:57 If there's anything wrong with your code, 1:59 then the problem might show up here as some kind of error message. 2:01 Now if we click over to messages, this shows messages from the build process. 2:05 If anything went wrong when building your project, 2:11 the error should be reported here. 2:13 And if you do have errors here or in Logcat and you don't know what to do, 2:15 first search for the error to see if someone else has already solved it. 2:19 If no one has, then copy the error and paste it as a question in the community. 2:23 Also, if you've got an idea about which piece of code is causing the error, 2:27 please include the code in your post as well. 2:32 Someone who's reading your post can usually help you a lot faster if they can 2:35 see the code. 2:39 All right, 2:40 now let's break something to see an example of what an error can look like. 2:40 Let's say I missed a semi-colon. 2:45 If I try to run the app, then I should get a Gradle build error. 2:48 Sure enough, it says Error: expected. 2:53 And if we double click on the error, 2:58 it will take us to the appropriate spot in the file. 3:00 And this is a Gradle build error because it prevents our project from being built. 3:04 Also, we see lots of red squiggly lines letting us know that we've made an error. 3:09 Let's put the semicolon back and check to make sure the error is fixed. 3:13 But instead of running the app, let's click this hammer to build the project. 3:17 And this time, we don't see any errors which means it was a successful build. 3:25 Another way we can build a project is to use the Build menu and 3:30 then select Make Project. 3:33 Or if you really want to start a build from scratch, you can chose clean project, 3:35 which cleans up all the behind the scenes files, and rebuilds the project for us. 3:40 One last thing, don't be alarmed if you can't find an error message again. 3:45 You can always find them down here in messages or Logcat. 3:49 Even if those tabs are missing, you can still find them by placing your mouse over 3:53 this little square in the corner and then picking the view you'd like to open. 3:57 Also, clicking the square will toggle showing and 4:02 hiding these views around the edge. 4:04 And remember, if you're having any trouble with this stuff, 4:06 head on over to the community and we'll make sure to help you out. 4:09 We just created and ran our first Android app. 4:14 Not bad for a few minutes of work. 4:17 We've set up an integrated development environment or IDE which in our case is 4:19 Android Studio and we saw how to create and run a new project. 4:23 Coming up, we'll make some changes to the screen layout and 4:28 then we'll write some actual code. 4:30 Now, everything should be working at this point, 4:33 which is actually a really big accomplishment. 4:36 Setting up a computer for 4:38 Android development is a lot easier than it used to be. 4:40 But things can still go wrong. 4:43 Remember, if you have any problems, check the community for help. 4:44
You need to sign up for Treehouse in order to download course files.Sign up