1 00:00:00,000 --> 00:00:02,480 (energetic music) 2 00:00:02,480 --> 00:00:04,920 (typing) 3 00:00:04,920 --> 00:00:06,549 In this video, we're going to download the 4 00:00:06,549 --> 00:00:09,918 YouTube player library and add it to a project 5 00:00:09,918 --> 00:00:12,200 that we're also going to create. 6 00:00:12,200 --> 00:00:14,100 So, with Android Studio loaded, 7 00:00:14,100 --> 00:00:16,131 we're going to create this new project by clicking on, 8 00:00:16,131 --> 00:00:18,331 Start a New Android Studio Project, 9 00:00:18,331 --> 00:00:21,581 and we'll call this one YouTube player. 10 00:00:22,731 --> 00:00:24,426 Now, notice that I've used a lower case T 11 00:00:24,426 --> 00:00:26,197 in the word YouTube. 12 00:00:26,197 --> 00:00:27,581 For the library that we're going to be using, 13 00:00:27,581 --> 00:00:29,617 that has a capital T throughout. 14 00:00:29,617 --> 00:00:31,996 And what I suggest you do for the company domain 15 00:00:31,996 --> 00:00:34,188 is do something a little bit different. 16 00:00:34,188 --> 00:00:35,537 Now, in my case I'm going to use 17 00:00:35,537 --> 00:00:39,106 learnprogramming.academy for the company domain. 18 00:00:39,106 --> 00:00:40,822 But the reason we want to do something different 19 00:00:40,822 --> 00:00:44,739 is because we need to get an API key from Google 20 00:00:44,739 --> 00:00:47,873 and it's tied to the package name for the app. 21 00:00:47,873 --> 00:00:49,964 Now, I'm going to show you how to get the API key 22 00:00:49,964 --> 00:00:51,466 in another video. 23 00:00:51,466 --> 00:00:54,723 And that key's used by Google to track usage of your app. 24 00:00:54,723 --> 00:00:56,171 And that allows them to charge you, 25 00:00:56,171 --> 00:00:58,763 but don't worry you get plenty of free use. 26 00:00:58,763 --> 00:01:00,729 So that won't be a problem for this app. 27 00:01:00,729 --> 00:01:03,439 But if every student used the same key, 28 00:01:03,439 --> 00:01:05,577 then without the 40,000 students that signed up 29 00:01:05,577 --> 00:01:07,496 to my previous version of this course, 30 00:01:07,496 --> 00:01:09,307 it may well be a problem. 31 00:01:09,307 --> 00:01:10,833 So don't worry about being charged though, 32 00:01:10,833 --> 00:01:13,204 you have to enable billing in the developer console 33 00:01:13,204 --> 00:01:14,863 before Google will charge you. 34 00:01:14,863 --> 00:01:16,775 And you'd have to use the app continuously 35 00:01:16,775 --> 00:01:19,295 on loads of devices all day to exceed 36 00:01:19,295 --> 00:01:22,162 the generous daily limit that they actually give you anyway. 37 00:01:22,162 --> 00:01:24,705 And again, if you haven't enabled billing, 38 00:01:24,705 --> 00:01:25,629 you won't get charged. 39 00:01:25,629 --> 00:01:27,505 And it'll actually stop working until the next day. 40 00:01:27,505 --> 00:01:29,375 So, no matter what if you don't enable billing 41 00:01:29,375 --> 00:01:30,666 you won't get charged anything, 42 00:01:30,666 --> 00:01:34,009 if you do happen to manage to go over the usage allowance. 43 00:01:34,009 --> 00:01:35,292 So for this company domain, 44 00:01:35,292 --> 00:01:38,375 I'm going to stick to using learnprogramming.academy. 45 00:01:38,375 --> 00:01:39,519 But if you've got your own domain name, 46 00:01:39,519 --> 00:01:41,010 I suggest you use that. 47 00:01:41,010 --> 00:01:44,799 Otherwise use something like yourname.example.org, 48 00:01:44,799 --> 00:01:46,850 something that will be unique to you. 49 00:01:46,850 --> 00:01:49,600 And probably a good idea to run your first and last name 50 00:01:49,600 --> 00:01:52,952 together, like Tim Buchalka.example.org for example, 51 00:01:52,952 --> 00:01:54,420 or the other way around. 52 00:01:54,420 --> 00:01:56,941 Just try to make sure you enter something unique there. 53 00:01:56,941 --> 00:01:58,174 Alright, so you know the drill 54 00:01:58,174 --> 00:01:59,472 with the Kotlin support pass by now, 55 00:01:59,472 --> 00:02:03,202 so tick it if you want Kotlin code or un-tick it for Java. 56 00:02:03,202 --> 00:02:04,901 And I'm going to click on Next now, 57 00:02:04,901 --> 00:02:07,283 and in fact you know the whole process pretty much now, 58 00:02:07,283 --> 00:02:09,211 so in future videos we're going to be starting 59 00:02:09,211 --> 00:02:12,031 with the project already created and open and I'll just give 60 00:02:12,031 --> 00:02:14,261 you the project name and template to choose. 61 00:02:14,261 --> 00:02:16,958 Alright, so I'm going to choose API 17 here as before, 62 00:02:16,958 --> 00:02:18,468 go to Next. 63 00:02:18,468 --> 00:02:21,728 I'm going to select Empty Project, Empty Activity, 64 00:02:21,728 --> 00:02:22,998 click on Next. 65 00:02:22,998 --> 00:02:24,465 I'm going to leave the default, 66 00:02:24,465 --> 00:02:27,122 for the activity name and the layout name, 67 00:02:27,122 --> 00:02:30,776 so that Android Studio creates the activity for us, 68 00:02:30,776 --> 00:02:32,159 and also creates a layout and 69 00:02:32,159 --> 00:02:35,108 I'm going to click on the Generate Layout File check box 70 00:02:35,108 --> 00:02:37,028 as well as the Backwards Compatibility one 71 00:02:37,028 --> 00:02:38,875 and click on Finish. 72 00:02:38,875 --> 00:02:41,373 Alright now while that's getting setup, 73 00:02:41,373 --> 00:02:43,885 what we need to do is go ahead and download the library 74 00:02:43,885 --> 00:02:47,052 that we're going to be using for this project. 75 00:02:47,052 --> 00:02:48,525 So let's go ahead and do that. 76 00:02:48,525 --> 00:02:51,108 So I'm going to open a browser. 77 00:02:52,192 --> 00:02:54,904 Going to paste in the URL. 78 00:02:54,904 --> 00:02:57,404 And again what we're doing here, is what we need to do, 79 00:02:57,404 --> 00:03:01,413 is integrate the YouTube API into our app. 80 00:03:01,413 --> 00:03:03,856 And we have to download the library file from the 81 00:03:03,856 --> 00:03:06,347 Google YouTube site which I've gone to now. 82 00:03:06,347 --> 00:03:08,354 And in case you're wondering, API stands for, 83 00:03:08,354 --> 00:03:10,816 Application Programme Interface. 84 00:03:10,816 --> 00:03:14,240 An API provides functions or classes for performing 85 00:03:14,240 --> 00:03:16,639 a certain task or one task or another, 86 00:03:16,639 --> 00:03:19,576 in this case playing YouTube videos. 87 00:03:19,576 --> 00:03:21,692 Alright so pages you can see here contains 88 00:03:21,692 --> 00:03:25,014 a lot of information on using the Android YouTube API. 89 00:03:25,014 --> 00:03:27,300 There's also this "Reference" tab up here which you can 90 00:03:27,300 --> 00:03:30,650 check with all the documentation for the various classes. 91 00:03:30,650 --> 00:03:32,533 And as an exercise, perhaps once you've 92 00:03:32,533 --> 00:03:34,910 finished this app in this section of the course, 93 00:03:34,910 --> 00:03:36,273 you might want to come back and 94 00:03:36,273 --> 00:03:38,178 experiment with various other things. 95 00:03:38,178 --> 00:03:40,211 One example might be checking out this 96 00:03:40,211 --> 00:03:42,804 YouTube.ThumbnailLoader. 97 00:03:42,804 --> 00:03:44,003 So, have a play once you finish 98 00:03:44,003 --> 00:03:45,423 the app in this section of the course. 99 00:03:45,423 --> 00:03:47,670 And maybe modify it to add some more functionality. 100 00:03:47,670 --> 00:03:49,095 By the time we finish this app, 101 00:03:49,095 --> 00:03:51,328 you will understand how to do things like, 102 00:03:51,328 --> 00:03:53,834 launch a new activity when the user clicks a button, 103 00:03:53,834 --> 00:03:56,308 so that you can add more screens to the app if you want. 104 00:03:56,308 --> 00:03:57,826 So there's all this information available, 105 00:03:57,826 --> 00:04:00,485 which makes using the API a lot easier. 106 00:04:00,485 --> 00:04:01,948 But we need to download the library, 107 00:04:01,948 --> 00:04:03,508 so I'm going to click on "Guides" up here, 108 00:04:03,508 --> 00:04:05,596 the "Guides" tab to go back. 109 00:04:05,596 --> 00:04:06,954 Now just down the page here, 110 00:04:06,954 --> 00:04:09,579 is a link to the download page, this one here. 111 00:04:09,579 --> 00:04:12,187 There's also a link over here in the left-hand side. 112 00:04:12,187 --> 00:04:14,379 But I'm showing you this one for a reason. 113 00:04:14,379 --> 00:04:18,579 And it's saying you need to have version 4.2.16 or higher 114 00:04:18,579 --> 00:04:21,240 of the YouTube app installed on your device, 115 00:04:21,240 --> 00:04:23,400 to be able to use this API. 116 00:04:23,400 --> 00:04:26,776 Now previously, I had to suggest that you use a physical 117 00:04:26,776 --> 00:04:29,549 device to test this app on, however, 118 00:04:29,549 --> 00:04:32,264 when the Android Oreo was released, 119 00:04:32,264 --> 00:04:35,319 Google also released emulators that can instal apps 120 00:04:35,319 --> 00:04:36,379 from the Google Play Store, 121 00:04:36,379 --> 00:04:39,239 so that limitations been removed. 122 00:04:39,239 --> 00:04:41,789 There's actually now two different types of emulators, 123 00:04:41,789 --> 00:04:43,210 but we'll be discussing the differences 124 00:04:43,210 --> 00:04:45,330 when we come to running this app. 125 00:04:45,330 --> 00:04:48,380 So for now, I'm going to click on the download link. 126 00:04:48,380 --> 00:04:50,822 That takes us to the download page. 127 00:04:50,822 --> 00:04:52,640 Now the version number while I'm recording this video, 128 00:04:52,640 --> 00:04:55,611 as you can see on the screen, is 1.2.2. 129 00:04:55,611 --> 00:04:57,937 And it doesn't seem to change very often. 130 00:04:57,937 --> 00:04:59,470 But if there happens to be a new version 131 00:04:59,470 --> 00:05:00,984 when you come to watch this, then that's fine. 132 00:05:00,984 --> 00:05:03,312 Just grab that current version and download it. 133 00:05:03,312 --> 00:05:05,835 So I'm going to click on download. 134 00:05:05,835 --> 00:05:08,704 And I'm going to save it to my downloads folder. 135 00:05:08,704 --> 00:05:11,915 Now we're going to find that downloaded file, 136 00:05:11,915 --> 00:05:15,784 and I'm going to double click it in my case to extract it. 137 00:05:15,784 --> 00:05:17,069 But if you're on Linux, 138 00:05:17,069 --> 00:05:18,960 you can right click and choose extract, 139 00:05:18,960 --> 00:05:20,568 and if you're on Windows you can do a similar thing, 140 00:05:20,568 --> 00:05:22,000 you can click on extract all. 141 00:05:22,000 --> 00:05:22,833 So basically, 142 00:05:22,833 --> 00:05:26,942 unzip the file and then go into the unzipped folder, 143 00:05:26,942 --> 00:05:28,623 there's a libs sub-folder, 144 00:05:28,623 --> 00:05:29,943 you want to click on that, 145 00:05:29,943 --> 00:05:32,903 then there's this YouTubeAndroidPlayerAPI.jar, 146 00:05:32,903 --> 00:05:34,383 so we're going to select that. 147 00:05:34,383 --> 00:05:36,559 In my case I'm going to select copy, so you'll do 148 00:05:36,559 --> 00:05:40,319 the equivalent if you're on Windows or on Linux. 149 00:05:40,319 --> 00:05:42,493 And then we want to swing back to our project 150 00:05:42,493 --> 00:05:43,993 in Android Studio. 151 00:05:44,837 --> 00:05:47,544 Now, generally speaking, keeping the project pane in 152 00:05:47,544 --> 00:05:50,927 Android view is more convenient but there are a 153 00:05:50,927 --> 00:05:53,186 few things that you can't do in Android View. 154 00:05:53,186 --> 00:05:57,215 One of these is copying external libraries into the project. 155 00:05:57,215 --> 00:05:59,333 That's because the libs folder, that we need, 156 00:05:59,333 --> 00:06:01,582 isn't available in Android view. 157 00:06:01,582 --> 00:06:03,115 So you can see up here there's no mechanism 158 00:06:03,115 --> 00:06:04,692 to get to the libs folder. 159 00:06:04,692 --> 00:06:05,525 So what I'm going to do, 160 00:06:05,525 --> 00:06:08,167 is switch into project view briefly 161 00:06:08,167 --> 00:06:10,147 using this drop-down up here. 162 00:06:10,147 --> 00:06:12,176 Select Project. 163 00:06:12,176 --> 00:06:15,919 Once I do that I can then click to open the project folders, 164 00:06:15,919 --> 00:06:17,002 click on app. 165 00:06:18,034 --> 00:06:19,351 We've now got this libs folder, 166 00:06:19,351 --> 00:06:21,151 and you can see at the moment that's empty. 167 00:06:21,151 --> 00:06:26,094 So I can right click the libs folder and I can select Paste. 168 00:06:26,094 --> 00:06:27,782 Now you can see that we've got a dialogue 169 00:06:27,782 --> 00:06:29,900 asking for confirmation of the copy. 170 00:06:29,900 --> 00:06:32,261 So make sure the directory it's copying the file into 171 00:06:32,261 --> 00:06:33,802 does say libs at the end. 172 00:06:33,802 --> 00:06:35,368 And you can see clearly here on my screen 173 00:06:35,368 --> 00:06:37,636 that it does say libs so we're in the right place, 174 00:06:37,636 --> 00:06:38,553 click Okay. 175 00:06:39,425 --> 00:06:42,026 Now if we expand by clicking on this little triangle, 176 00:06:42,026 --> 00:06:45,506 we can see that the YouTubeAndroidPlayerAPI.jar 177 00:06:45,506 --> 00:06:47,896 is now in the libs folder. 178 00:06:47,896 --> 00:06:49,715 With that done I'm going to go back now 179 00:06:49,715 --> 00:06:52,616 and switch it back to Android view. 180 00:06:52,616 --> 00:06:55,402 So now that we have copied the file into the libs folder, 181 00:06:55,402 --> 00:06:59,157 we need to tell Android Studio to use it in our project. 182 00:06:59,157 --> 00:07:01,569 Now one way to do that, is to add a reference to it 183 00:07:01,569 --> 00:07:03,306 in the build.gradle file. 184 00:07:03,306 --> 00:07:04,912 The things are changing at the moment, 185 00:07:04,912 --> 00:07:07,217 and you might still be working on the older version 186 00:07:07,217 --> 00:07:09,293 of Android Studio as well as this one. 187 00:07:09,293 --> 00:07:11,366 So I'm going to show you another way. 188 00:07:11,366 --> 00:07:13,085 So you can go into the File menu 189 00:07:13,085 --> 00:07:16,245 and click on Project Structure. 190 00:07:16,245 --> 00:07:18,386 Once you do that, in the left-hand side list here, 191 00:07:18,386 --> 00:07:21,656 select app from the Modules section down here. 192 00:07:21,656 --> 00:07:23,605 Then you want to come over here to the right, 193 00:07:23,605 --> 00:07:26,156 and click on the "Dependencies" tab. 194 00:07:26,156 --> 00:07:29,386 That lists all the dependencies for this project. 195 00:07:29,386 --> 00:07:32,374 Now, as you can see, we're using the app compat library 196 00:07:32,374 --> 00:07:36,125 and we're also using the constraint layout et cetera. 197 00:07:36,125 --> 00:07:37,650 Now if you're producing Kotlin code, 198 00:07:37,650 --> 00:07:40,364 you'll also see the standard Kotlin library in the list. 199 00:07:40,364 --> 00:07:43,045 You can see down here of got that showing as well. 200 00:07:43,045 --> 00:07:45,750 Now right at the top, usually it's at the top, 201 00:07:45,750 --> 00:07:49,909 there's a reference to *.jar files in the libs directory. 202 00:07:49,909 --> 00:07:52,656 Now that would automatically include any jar files 203 00:07:52,656 --> 00:07:54,946 that we place in the libs directory. 204 00:07:54,946 --> 00:07:57,177 And of course, we've actually done that at the moment. 205 00:07:57,177 --> 00:08:00,196 So there's really no need to do what we're about to do, 206 00:08:00,196 --> 00:08:02,093 and that's because our YouTube library will be 207 00:08:02,093 --> 00:08:04,380 automatically included in the project, 208 00:08:04,380 --> 00:08:06,372 because we put it into the libs folder. 209 00:08:06,372 --> 00:08:09,233 But I think it's useful to know how to add libraries, 210 00:08:09,233 --> 00:08:10,618 especially if you decide to keep the 211 00:08:10,618 --> 00:08:12,338 jar files in a different directory, 212 00:08:12,338 --> 00:08:14,397 so I'm going to go through that process anyway. 213 00:08:14,397 --> 00:08:17,765 So to add a jar file explicitly rather than relying 214 00:08:17,765 --> 00:08:21,466 on that catch-all include, you click on the green +. 215 00:08:21,466 --> 00:08:24,698 In my case it's down here, but it may be at the top right 216 00:08:24,698 --> 00:08:27,197 depending on what operating system you're running on. 217 00:08:27,197 --> 00:08:29,356 But click on the add anyway in any event. 218 00:08:29,356 --> 00:08:31,984 Once you do that, you get this little pop-up menu. 219 00:08:31,984 --> 00:08:34,986 And I want to click on and choose Jar dependency. 220 00:08:34,986 --> 00:08:37,936 Now once you do that, that pops up a file browser 221 00:08:37,936 --> 00:08:40,645 which lets us browse the directories in the project. 222 00:08:40,645 --> 00:08:43,674 Now the jar file has to be in the project somewhere, 223 00:08:43,674 --> 00:08:45,127 so on Linux though unfortunately, 224 00:08:45,127 --> 00:08:46,933 there's no ability to move back up to 225 00:08:46,933 --> 00:08:48,801 browse the entire hard disc. 226 00:08:48,801 --> 00:08:51,423 On my Mac though, I have to actually browse into 227 00:08:51,423 --> 00:08:53,906 the project directory and find libs. 228 00:08:53,906 --> 00:08:56,186 And you'll need to do a similar thing for Windows. 229 00:08:56,186 --> 00:08:58,286 So in my case I'm actually already there, 230 00:08:58,286 --> 00:09:01,317 I've already got the YouTube Player app libs folder, 231 00:09:01,317 --> 00:09:05,106 and you can see the YouTubePlayerAPI.jar there, 232 00:09:05,106 --> 00:09:08,306 so with YouTubeAndroidPlayerAPI.jar is actually there. 233 00:09:08,306 --> 00:09:10,317 I can just expand that out we can see the full file name. 234 00:09:10,317 --> 00:09:12,385 So do whatever you need to do to get that open, 235 00:09:12,385 --> 00:09:15,946 select the file then and click on Okay or Open, 236 00:09:15,946 --> 00:09:18,264 depending on what you're operating system shows. 237 00:09:18,264 --> 00:09:19,475 And you can see that that entries 238 00:09:19,475 --> 00:09:21,888 been added now to this screen. 239 00:09:21,888 --> 00:09:23,657 Now if you want you can remove this 240 00:09:23,657 --> 00:09:26,673 catch-all include entry up here at this point. 241 00:09:26,673 --> 00:09:28,693 You just click on it and use the red minus button, 242 00:09:28,693 --> 00:09:31,482 or in my case it's not red but it will be depending on 243 00:09:31,482 --> 00:09:33,924 your operating system it may be a different colour, 244 00:09:33,924 --> 00:09:35,655 and it may also be over here to the right. 245 00:09:35,655 --> 00:09:38,071 But in my case on the Mac it's down at the bottom. 246 00:09:38,071 --> 00:09:39,145 So if I clicked on that now, 247 00:09:39,145 --> 00:09:41,153 that would actually remove that entry. 248 00:09:41,153 --> 00:09:43,719 But there's no need to remove it because the library 249 00:09:43,719 --> 00:09:46,292 won't be included twice if you leave it in. 250 00:09:46,292 --> 00:09:48,941 Now if you're experimenting with different libraries or 251 00:09:48,941 --> 00:09:50,341 trying different versions, 252 00:09:50,341 --> 00:09:54,015 then you don't want everything included automatically. 253 00:09:54,015 --> 00:09:55,423 And this is how you'd prevent 254 00:09:55,423 --> 00:09:57,459 everything in libs from being added. 255 00:09:57,459 --> 00:10:00,434 So any of your libraries you add explicitly 256 00:10:00,434 --> 00:10:04,171 will appear in the project if you actually remove this line. 257 00:10:04,171 --> 00:10:05,645 But I'm going to leave it, 258 00:10:05,645 --> 00:10:07,438 so you can see it in the build.gradle file. 259 00:10:07,438 --> 00:10:09,777 So for that reason I'm just going to click Okay, 260 00:10:09,777 --> 00:10:12,286 because we're actually finished here now. 261 00:10:12,286 --> 00:10:15,157 You can see it's got a gradle project sequence in process, 262 00:10:15,157 --> 00:10:18,428 so Android Studio quickly realised there was a change 263 00:10:18,428 --> 00:10:21,428 and synced the project for us. 264 00:10:21,428 --> 00:10:23,277 Now in earlier version of this course, 265 00:10:23,277 --> 00:10:26,777 we added the library by modifying the build.gradle file. 266 00:10:26,777 --> 00:10:29,068 But the way we've just done it is safer because 267 00:10:29,068 --> 00:10:32,158 there's no chance of typing the file name incorrectly. 268 00:10:32,158 --> 00:10:34,638 It's useful though to be familiar with build.gradle though, 269 00:10:34,638 --> 00:10:37,588 so let's have a look in there to see what we've just done. 270 00:10:37,588 --> 00:10:40,587 Now confusingly with Android Studio projects, 271 00:10:40,587 --> 00:10:42,417 there's two build gradle files, 272 00:10:42,417 --> 00:10:46,089 one you should edit and one that you'll very rarely change. 273 00:10:46,089 --> 00:10:46,922 Now the one we want, 274 00:10:46,922 --> 00:10:49,628 I'm going to click on and expand this down here, 275 00:10:49,628 --> 00:10:52,548 the one we want is in the apps directory. 276 00:10:52,548 --> 00:10:54,089 This one appears lower in the tree, 277 00:10:54,089 --> 00:10:56,681 so you can see below the project YouTubePlayer. 278 00:10:56,681 --> 00:11:00,149 It's this one here, build.gradle module app. 279 00:11:00,149 --> 00:11:02,380 Because we know to be looking at the android view though, 280 00:11:02,380 --> 00:11:04,929 I'm not going to change the file name here. 281 00:11:04,929 --> 00:11:07,177 And if you go back now, have a look in project view again, 282 00:11:07,177 --> 00:11:09,281 you can see we've got this build.gradle and it's actually 283 00:11:09,281 --> 00:11:13,270 in the app path and there's also another build.gradle there. 284 00:11:13,270 --> 00:11:14,425 But if we go back now again, 285 00:11:14,425 --> 00:11:16,809 just to have a look in Android view, 286 00:11:16,809 --> 00:11:19,966 we've got all the gradle scripts are in the same place, 287 00:11:19,966 --> 00:11:22,217 but it still shows us the module app here. 288 00:11:22,217 --> 00:11:25,297 And this is the one we ultimately want to have a look at. 289 00:11:25,297 --> 00:11:27,636 I'm going to double click on that to open it. 290 00:11:27,636 --> 00:11:28,469 And just out of interest, 291 00:11:28,469 --> 00:11:30,363 if you accidentally open the wrong one, 292 00:11:30,363 --> 00:11:31,832 have a look at this other one. 293 00:11:31,832 --> 00:11:32,798 It actually makes a point of saying, 294 00:11:32,798 --> 00:11:34,787 "Do not place your application dependencies here; 295 00:11:34,787 --> 00:11:38,066 they belong in the individual module build.gradle files". 296 00:11:38,066 --> 00:11:38,982 That's really just a warning, 297 00:11:38,982 --> 00:11:42,286 to let you know or to remind you that perhaps you're looking 298 00:11:42,286 --> 00:11:43,592 at the wrong build.gradle file. 299 00:11:43,592 --> 00:11:45,133 So I'm going to close that one down 300 00:11:45,133 --> 00:11:46,832 and leave our app one open. 301 00:11:46,832 --> 00:11:48,483 Now eventually you will get used to which ones which, 302 00:11:48,483 --> 00:11:51,003 but until then just open one and if you see that warning 303 00:11:51,003 --> 00:11:53,072 then close it and then open the other one. 304 00:11:53,072 --> 00:11:55,411 So in this case we've now got the right one open. 305 00:11:55,411 --> 00:11:57,912 So, this module build.gradle file has all sorts 306 00:11:57,912 --> 00:11:59,981 of information telling Android Studio, 307 00:11:59,981 --> 00:12:01,861 or really the gradle build system, 308 00:12:01,861 --> 00:12:04,150 how to build the file that's deployed 309 00:12:04,150 --> 00:12:06,621 to our devices or emulators. 310 00:12:06,621 --> 00:12:09,963 So down at the bottom here inside the dependencies section, 311 00:12:09,963 --> 00:12:11,720 we can see the jar file that we added 312 00:12:11,720 --> 00:12:14,312 right on the last line sitting there now. 313 00:12:14,312 --> 00:12:16,150 Now we could have just typed that line in instead 314 00:12:16,150 --> 00:12:18,951 of going through the menu that we did earlier in the video. 315 00:12:18,951 --> 00:12:20,471 If you do type these entries in, 316 00:12:20,471 --> 00:12:23,011 it's really important that you get the case right. 317 00:12:23,011 --> 00:12:24,542 Now I mentioned at the start of the videos about the 318 00:12:24,542 --> 00:12:26,733 upper and the lower case T. 319 00:12:26,733 --> 00:12:30,107 You can see here that on the libs/YouTube, 320 00:12:30,107 --> 00:12:31,846 we've got a capital T there. 321 00:12:31,846 --> 00:12:34,328 If you use a lower case T in YouTube, for example, 322 00:12:34,328 --> 00:12:35,875 it won't work. 323 00:12:35,875 --> 00:12:37,147 Now if you're used to Windows, 324 00:12:37,147 --> 00:12:38,516 remember to put the slash rather than 325 00:12:38,516 --> 00:12:41,265 the backslash between libs in the jar file names. 326 00:12:41,265 --> 00:12:43,886 So don't use back backslashes in other words. 327 00:12:43,886 --> 00:12:45,776 So at the top of this dependencies section, 328 00:12:45,776 --> 00:12:47,728 is that catch-all entry I talked about to include 329 00:12:47,728 --> 00:12:50,695 all jar files from the libs directory. 330 00:12:50,695 --> 00:12:53,787 Now I didn't delete it there so you can see it in here, 331 00:12:53,787 --> 00:12:57,608 but I'm going to delete that entire line now. 332 00:12:57,608 --> 00:12:59,608 And move that up. 333 00:12:59,608 --> 00:13:02,347 Now it's usually a good idea to be explicit about 334 00:13:02,347 --> 00:13:04,667 what you want to do in programming rather 335 00:13:04,667 --> 00:13:06,755 than relying on default behaviour. 336 00:13:06,755 --> 00:13:08,806 And this is why I've specifically listed 337 00:13:08,806 --> 00:13:12,667 the YouTube Android Player API jar file. 338 00:13:12,667 --> 00:13:15,587 So I've deleted that implementation file tree line. 339 00:13:15,587 --> 00:13:17,016 Now it wouldn't hurt to leave it in, 340 00:13:17,016 --> 00:13:19,168 the library wouldn't be included twice. 341 00:13:19,168 --> 00:13:22,368 But we're being explicit here and we're listing the jar file 342 00:13:22,368 --> 00:13:26,667 in it's own implementation statement anyway on line 34. 343 00:13:26,667 --> 00:13:28,576 Now with that said, there's no guarantee that Google won't 344 00:13:28,576 --> 00:13:31,067 remove that default inclusion of all jars in the 345 00:13:31,067 --> 00:13:33,373 lib folder so it's really useful to know 346 00:13:33,373 --> 00:13:34,843 what's going on here. 347 00:13:34,843 --> 00:13:37,024 Now whenever you make a change to the build.gradle file 348 00:13:37,024 --> 00:13:38,961 you'll get a message at the top as you can see now, 349 00:13:38,961 --> 00:13:40,902 telling you that the file's changed. 350 00:13:40,902 --> 00:13:42,974 And you need to click the Sync Now link, 351 00:13:42,974 --> 00:13:44,632 but if you're making several changes, 352 00:13:44,632 --> 00:13:47,612 you can actually do all the changes first just make sure 353 00:13:47,612 --> 00:13:50,592 that you do the Sync Now or click the Sync Now 354 00:13:50,592 --> 00:13:52,304 by clicking the link once you've finished 355 00:13:52,304 --> 00:13:55,931 the changes or you'll find things won't work properly. 356 00:13:55,931 --> 00:13:57,534 So I'm going to click on Sync Now. 357 00:13:57,534 --> 00:14:00,562 Now there are a few more things to look at in this file. 358 00:14:00,562 --> 00:14:02,912 The first are that these dependencies over here 359 00:14:02,912 --> 00:14:05,592 start with the word implementation. 360 00:14:05,592 --> 00:14:08,071 Now in previous versions of Android Studio, 361 00:14:08,071 --> 00:14:11,163 that used to say compile instead. 362 00:14:11,163 --> 00:14:13,568 And if you're working on an old version as well or more 363 00:14:13,568 --> 00:14:16,149 accurately if you're using an older version of gradle, 364 00:14:16,149 --> 00:14:19,250 then that will be compile instead of implementation. 365 00:14:19,250 --> 00:14:21,269 So watch out for that and use compile 366 00:14:21,269 --> 00:14:23,658 if you're working with the older versions. 367 00:14:23,658 --> 00:14:25,319 Now if you go through Android Studios menu 368 00:14:25,319 --> 00:14:28,749 like we did first, it will use the correct key word. 369 00:14:28,749 --> 00:14:30,328 Now the other thing that you may want to change 370 00:14:30,328 --> 00:14:33,416 in here are the minSdk up here, 371 00:14:33,416 --> 00:14:36,389 and the targetSdkVersion here at the top. 372 00:14:36,389 --> 00:14:39,497 Now these are the values we provided in the wizard when 373 00:14:39,497 --> 00:14:42,290 we originally created the project earlier in this video. 374 00:14:42,290 --> 00:14:43,498 Now if you change your mind, 375 00:14:43,498 --> 00:14:45,450 then this is the place to change them. 376 00:14:45,450 --> 00:14:48,218 So more importantly if you open an old project, 377 00:14:48,218 --> 00:14:50,330 and you want to convert it to target the latest version 378 00:14:50,330 --> 00:14:53,559 of Android or maybe drop support for an old version, 379 00:14:53,559 --> 00:14:56,090 then you can change these settings in here. 380 00:14:56,090 --> 00:14:58,210 Remember that the minimum version now supported 381 00:14:58,210 --> 00:15:01,069 is API 14, Ice Cream Sandwich. 382 00:15:01,069 --> 00:15:03,587 Now if you're converting an old Marshmallow or Nougat 383 00:15:03,587 --> 00:15:06,229 project to Oreo then you'll also want to change 384 00:15:06,229 --> 00:15:10,576 the compile SDK version to 26 and the build tools version 385 00:15:10,576 --> 00:15:12,959 to the latest version of Oreo. 386 00:15:12,959 --> 00:15:16,084 So as I record this it's 26.0.2. 387 00:15:16,084 --> 00:15:18,408 But have a look at any new project that you've created 388 00:15:18,408 --> 00:15:20,150 to get the correct version numbers. 389 00:15:20,150 --> 00:15:20,983 Assuming that you've installed 390 00:15:20,983 --> 00:15:23,576 all the latest updates of course. 391 00:15:23,576 --> 00:15:26,650 Now the last thing here is that it's possible that this 392 00:15:26,650 --> 00:15:30,223 appcompat line is actually highlighted. 393 00:15:30,223 --> 00:15:31,181 Now what I'm going to do, 394 00:15:31,181 --> 00:15:33,207 is change this back just to show you what I mean here. 395 00:15:33,207 --> 00:15:34,894 I'm going to change this back to an older version, 396 00:15:34,894 --> 00:15:35,727 26.0.2. 397 00:15:38,847 --> 00:15:39,680 Now I'm going to show you what happens 398 00:15:39,680 --> 00:15:42,042 when there's a newer version available. 399 00:15:42,042 --> 00:15:44,693 Leave that a moment to sync. 400 00:15:44,693 --> 00:15:46,802 You'll notice now that we've got an older version here, 401 00:15:46,802 --> 00:15:48,322 that this is actually highlighted. 402 00:15:48,322 --> 00:15:49,983 And if I hover over that it actually says 403 00:15:49,983 --> 00:15:54,602 a newer version of the appcompat library is available. 404 00:15:54,602 --> 00:15:56,560 If I actually click on that, 405 00:15:56,560 --> 00:15:58,171 we get the light bulb over here, 406 00:15:58,171 --> 00:15:59,694 I can come down here and I can click on 407 00:15:59,694 --> 00:16:02,603 change to 26.1.0 and that number will 408 00:16:02,603 --> 00:16:06,105 be whatever the latest version is and that will update it. 409 00:16:06,105 --> 00:16:08,673 Then I'll need to come over here and click on Sync Now. 410 00:16:08,673 --> 00:16:12,097 So if you see any entries highlighted like that in yellow, 411 00:16:12,097 --> 00:16:13,805 that's the way to actually update them to make sure 412 00:16:13,805 --> 00:16:16,274 that you're running the latest version. 413 00:16:16,274 --> 00:16:18,995 And keep in mind that when you click on the Sync Now button, 414 00:16:18,995 --> 00:16:21,216 that will actually do any necessary downloads to get 415 00:16:21,216 --> 00:16:24,296 that latest version for you, pretty cool. 416 00:16:24,296 --> 00:16:26,245 Now I've already went ahead and actually clicked on that 417 00:16:26,245 --> 00:16:27,876 and actually updated it, 418 00:16:27,876 --> 00:16:30,805 but generally before you update there are implications 419 00:16:30,805 --> 00:16:32,715 and that's why Android Studio 420 00:16:32,715 --> 00:16:35,385 didn't just go ahead and upgrade it anyway. 421 00:16:35,385 --> 00:16:37,184 Now you'll find it does that for certain things, 422 00:16:37,184 --> 00:16:38,734 like the gradle.build system. 423 00:16:38,734 --> 00:16:42,225 It will prompt you but can update to gradle automatically. 424 00:16:42,225 --> 00:16:45,072 The reason for that is that only effects the build process 425 00:16:45,072 --> 00:16:47,908 it doesn't change what's compiled into your final app. 426 00:16:47,908 --> 00:16:51,047 But changing those library versions does change your app. 427 00:16:51,047 --> 00:16:53,396 So if your apps gone through final testing, for example, 428 00:16:53,396 --> 00:16:54,767 and it's ready for release, 429 00:16:54,767 --> 00:16:57,217 you can't suddenly go changing the library versions. 430 00:16:57,217 --> 00:16:59,985 If you do, the app will need full testing again. 431 00:16:59,985 --> 00:17:01,636 And the other thing to keep in mind is that sometimes 432 00:17:01,636 --> 00:17:04,065 new libraries do introduce bugs. 433 00:17:04,065 --> 00:17:07,023 They can also change the way your app works in subtle ways. 434 00:17:07,023 --> 00:17:09,531 So bear that in mind if you change any 435 00:17:09,531 --> 00:17:12,142 of these library versions your app will need testing again 436 00:17:12,142 --> 00:17:13,761 before you release it. 437 00:17:13,761 --> 00:17:16,080 Now while you're working through the examples in this course 438 00:17:16,080 --> 00:17:18,950 I recommend that you do use the latest version of 439 00:17:18,950 --> 00:17:20,217 all the libraries though. 440 00:17:20,217 --> 00:17:21,933 And that's why I went ahead and clicked 441 00:17:21,933 --> 00:17:23,148 on the light bulb and I changed 442 00:17:23,148 --> 00:17:26,079 the appcompat version to 26.1.0. 443 00:17:26,079 --> 00:17:29,438 Which is the latest version currently existing. 444 00:17:29,438 --> 00:17:30,271 And then obviously, 445 00:17:30,271 --> 00:17:32,546 I went through and clicked on the Sync Now. 446 00:17:32,546 --> 00:17:34,298 Alright, we're going to be coming back to this file later 447 00:17:34,298 --> 00:17:36,546 to look at some of the other things in here. 448 00:17:36,546 --> 00:17:38,567 But for now though, that's the project set up 449 00:17:38,567 --> 00:17:40,823 so that we can use for YouTube API. 450 00:17:40,823 --> 00:17:43,784 So I'm going to go ahead and close the API app, 451 00:17:43,784 --> 00:17:45,607 the build.gradle file here. 452 00:17:45,607 --> 00:17:47,567 And I will finish off the video. 453 00:17:47,567 --> 00:17:48,938 In the next one we're going to start with 454 00:17:48,938 --> 00:17:52,476 creating a new activity to show those YouTube videos. 455 00:17:52,476 --> 00:17:54,095 So see you in the next video.