1 00:00:00,430 --> 00:00:03,940 When we create a project, Android Studio creates all of the files and 2 00:00:03,940 --> 00:00:06,330 folders that we need behind the scenes. 3 00:00:06,330 --> 00:00:09,280 Let's run the project to verify that everything's working. 4 00:00:09,280 --> 00:00:10,760 We'll also see where to look for 5 00:00:10,760 --> 00:00:13,510 information about errors, if we run into any problems. 6 00:00:15,060 --> 00:00:19,340 We'll talk about all these different views in Android Studio in a little bit. 7 00:00:19,340 --> 00:00:22,030 But first, let's try to run the app. 8 00:00:22,030 --> 00:00:24,000 There's a couple ways we can do it. 9 00:00:24,000 --> 00:00:26,860 We can select Run from the menu up here and 10 00:00:26,860 --> 00:00:31,910 then select Run App, or from the toolbar, we can click on the run button. 11 00:00:33,100 --> 00:00:33,980 I'll choose this option. 12 00:00:35,340 --> 00:00:37,967 Also, if you like keyboard shortcuts, 13 00:00:37,967 --> 00:00:41,530 you can hit Shift+F10 on Windows or Ctrl+R on Mac. 14 00:00:42,840 --> 00:00:45,340 Now we see the device chooser dialog. 15 00:00:45,340 --> 00:00:49,588 If we had an Android phone or tablet plugged into our computer with a USB 16 00:00:49,588 --> 00:00:53,050 cable, then it might show up here as a connected device. 17 00:00:53,050 --> 00:00:55,930 We'll see how to do that later on. 18 00:00:55,930 --> 00:01:00,500 But for now, we want to launch the emulator with the default virtual device. 19 00:01:00,500 --> 00:01:03,580 If your installation doesn't have a default virtual device, or 20 00:01:03,580 --> 00:01:07,130 you'd like to learn how to create and customize your virtual devices, 21 00:01:07,130 --> 00:01:10,310 check out the workshop linked in the teacher's notes below. 22 00:01:10,310 --> 00:01:12,620 Once we've selected a virtual device we can hit OK. 23 00:01:14,340 --> 00:01:18,020 Android Studio will launch the emulator and run our app. 24 00:01:18,020 --> 00:01:21,580 The emulator may take a little bit to load, so be patient. 25 00:01:21,580 --> 00:01:24,230 The good news is that once the emulator is up, 26 00:01:24,230 --> 00:01:27,450 we can leave it running to avoid the wait on subsequent runs. 27 00:01:29,078 --> 00:01:33,500 In the meantime, notice down at the bottom there's a message about a Gradle build. 28 00:01:34,700 --> 00:01:37,900 Gradle is the name of something that's called a build system, and 29 00:01:37,900 --> 00:01:41,500 it's responsible for transforming all the raw materials for the app 30 00:01:41,500 --> 00:01:45,190 here in Android Studio into something that can be installed on a device. 31 00:01:46,660 --> 00:01:47,590 And there it is. 32 00:01:47,590 --> 00:01:49,700 You've just ran your first Android app. 33 00:01:50,830 --> 00:01:52,860 But what if yours isn't working? 34 00:01:52,860 --> 00:01:54,940 How do we know if something went wrong? 35 00:01:54,940 --> 00:01:59,130 Back in Android Studio, let's click on the Logcat at the bottom of the screen. 36 00:02:01,700 --> 00:02:04,080 Logcat is Android's logging system. 37 00:02:04,080 --> 00:02:06,340 It gives us a way to read the system logs, 38 00:02:06,340 --> 00:02:09,010 which is really useful when debugging an app. 39 00:02:09,010 --> 00:02:10,970 If there's anything wrong with your code, 40 00:02:10,970 --> 00:02:15,030 then the problem might show up here as some kind of error message. 41 00:02:15,030 --> 00:02:20,300 Now if we click over to Messages, this shows messages from the build process. 42 00:02:20,300 --> 00:02:22,860 If anything went wrong when building your project, 43 00:02:22,860 --> 00:02:25,260 the error should be reported here. 44 00:02:25,260 --> 00:02:29,760 And if you do have errors here, or in Logcat, and you don't know what to do, 45 00:02:29,760 --> 00:02:33,460 first search for the error to see if someone else has already solved it. 46 00:02:33,460 --> 00:02:38,650 If no one has, then copy the error and paste it as a question in the community. 47 00:02:38,650 --> 00:02:42,840 Also, if you've got an idea about which piece of code is causing the error, 48 00:02:42,840 --> 00:02:45,530 please include the code in your post as well. 49 00:02:45,530 --> 00:02:49,130 Someone who is reading your post can usually help you a lot faster 50 00:02:49,130 --> 00:02:50,810 if they can see the code. 51 00:02:50,810 --> 00:02:53,710 All right, now let's break something to see an example 52 00:02:53,710 --> 00:02:56,020 of what an error can look like. 53 00:02:56,020 --> 00:02:57,770 Let's say I missed a curly bracket. 54 00:02:59,560 --> 00:03:03,899 If I try to run the app, then I should get a Gradle build error. 55 00:03:05,368 --> 00:03:07,310 Sure enough, it says we're missing a curly bracket. 56 00:03:07,310 --> 00:03:10,061 And if we double click on the error, 57 00:03:10,061 --> 00:03:14,030 it'll take us to the appropriate spot in the file. 58 00:03:14,030 --> 00:03:17,460 Also, since this error prevents our project from being built, 59 00:03:17,460 --> 00:03:19,580 it's a Gradle build error. 60 00:03:19,580 --> 00:03:22,690 And if you didn't notice the error down here, Android Studio 61 00:03:22,690 --> 00:03:27,000 also shows us lots of red squiggly marks, letting us know there's an error. 62 00:03:28,630 --> 00:03:36,200 Let's put the curly bracket back and check to make sure the error is fixed. 63 00:03:36,200 --> 00:03:40,600 But instead of running the app, let's click on the Gradle sync button up here, 64 00:03:42,750 --> 00:03:44,980 which just builds the app without running it. 65 00:03:46,020 --> 00:03:50,410 This time we don't see any error messages, which means it was a successful build. 66 00:03:51,560 --> 00:03:56,090 Another way we can build a project is to use the Build menu and 67 00:03:56,090 --> 00:03:57,450 then select Make Project. 68 00:03:58,890 --> 00:04:02,840 Or if we really want to start our build from scratch, we can choose Clean Project, 69 00:04:04,260 --> 00:04:08,470 which cleans up all the behind the scenes files and rebuilds the project for us. 70 00:04:09,520 --> 00:04:10,920 One last thing. 71 00:04:10,920 --> 00:04:13,790 Don't be alarmed if you can't find an error message again. 72 00:04:13,790 --> 00:04:17,390 You can always find them down here in Messages or Logcat. 73 00:04:18,510 --> 00:04:22,510 Even if those tabs are missing, you can still find them by placing your mouse 74 00:04:22,510 --> 00:04:27,350 over this little square in the corner, and then picking the view you'd like to open. 75 00:04:27,350 --> 00:04:31,227 Also, clicking the square will toggle showing and 76 00:04:31,227 --> 00:04:34,030 hiding these views around the edge. 77 00:04:35,770 --> 00:04:38,590 And remember, if you're having any trouble with this stuff, 78 00:04:38,590 --> 00:04:41,200 head on over to the community and we'll make sure to help you out. 79 00:04:42,970 --> 00:04:48,270 We just created and ran our first Android app, not bad for a few minutes of work. 80 00:04:48,270 --> 00:04:52,720 We set up an integrated development environment, or IDE, which in our case, 81 00:04:52,720 --> 00:04:57,500 is Android Studio, and we saw how to create and run a new project. 82 00:04:57,500 --> 00:05:00,250 Coming up, we'll make some changes to the screen layout, and 83 00:05:00,250 --> 00:05:01,800 then we'll write some actual code. 84 00:05:02,820 --> 00:05:05,590 Now, everything should be working at this point, 85 00:05:05,590 --> 00:05:08,170 which is actually a really big accomplishment. 86 00:05:08,170 --> 00:05:09,280 Setting up a computer for 87 00:05:09,280 --> 00:05:12,130 Android development is a lot easier than it used to be. 88 00:05:12,130 --> 00:05:14,110 But things can still go wrong. 89 00:05:14,110 --> 00:05:17,240 Remember, if you have any problems, check the community for help.