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