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