1 00:00:00,270 --> 00:00:03,910 Pushing our own projects to GitHub is certainly useful, but 2 00:00:03,910 --> 00:00:06,770 what if we want to contribute to an outside project? 3 00:00:06,770 --> 00:00:09,210 How can we do that from within Android Studio? 4 00:00:10,970 --> 00:00:14,540 Luckily, Android Studio makes this easy as well, but 5 00:00:14,540 --> 00:00:17,810 first, let's take a look at the project we'll be contributing to. 6 00:00:18,970 --> 00:00:21,720 We are going to be making changes to the fun facts project 7 00:00:21,720 --> 00:00:23,950 from the beginning of the Android track. 8 00:00:23,950 --> 00:00:26,840 If you're not familiar with the project, that's okay. 9 00:00:26,840 --> 00:00:29,790 It's a fairly simple project with only one button. 10 00:00:29,790 --> 00:00:33,360 When the button is pressed, we randomly select a fun fact and 11 00:00:33,360 --> 00:00:35,230 a background color for the screen. 12 00:00:35,230 --> 00:00:37,270 Let's open the project on GitHub. 13 00:00:37,270 --> 00:00:46,102 It's located at github.com/treehouse/android-fun-facts-gi- 14 00:00:46,102 --> 00:00:50,825 thub, which is in the Teacher's Notes 15 00:00:50,825 --> 00:00:56,410 along with a link to the Fun Facts course. 16 00:00:56,410 --> 00:00:59,600 Once we're here, we can click the Fork button on the upper-right, 17 00:00:59,600 --> 00:01:01,880 to fork this project into our own repository. 18 00:01:03,630 --> 00:01:06,050 If you're not interested in contributing to a project, 19 00:01:06,050 --> 00:01:09,430 you can skip the forking step, and just clone the project from the source. 20 00:01:10,490 --> 00:01:14,060 Since we'd like to contribute to this project, we'll stick with forking. 21 00:01:14,060 --> 00:01:15,420 Once forking is finished, 22 00:01:15,420 --> 00:01:18,390 we'll want to find the clone URL on the right side of the screen. 23 00:01:19,530 --> 00:01:22,790 Let's copy that, as we'll need it to clone the repository. 24 00:01:22,790 --> 00:01:25,270 Now that we know what project we're working with, and 25 00:01:25,270 --> 00:01:28,750 we've created our fork, let's start up Android Studio. 26 00:01:28,750 --> 00:01:33,256 But this time, instead of creating or opening an existing project, 27 00:01:33,256 --> 00:01:38,323 let's click on Check Out Project from Version Control, and select GitHub. 28 00:01:41,629 --> 00:01:45,960 Next, if it isn't already saved, we'll be prompted for our login information. 29 00:01:51,362 --> 00:01:54,684 Now we can paste in the clone URL from earlier, and 30 00:01:54,684 --> 00:01:57,623 hit Test to verify it's a valid GitHub URL. 31 00:02:01,158 --> 00:02:05,871 Then we select the Project Directory and the name of our project, 32 00:02:05,871 --> 00:02:09,310 I'm going to pick FunFacts, and click Clone. 33 00:02:12,310 --> 00:02:14,090 And let's click Yes to open the project. 34 00:02:17,070 --> 00:02:17,600 Awesome! 35 00:02:17,600 --> 00:02:21,430 We've successfully pulled a project from GitHub and everything looks good to go. 36 00:02:21,430 --> 00:02:22,840 But what if it didn't work? 37 00:02:22,840 --> 00:02:24,510 How would we fix that? 38 00:02:24,510 --> 00:02:28,029 I'm going to quickly pull in an older version of this project to show how to fix 39 00:02:28,029 --> 00:02:31,454 some common issues you might find when checking out a project from GitHub. 40 00:02:35,246 --> 00:02:38,320 Right off the bat, things are a bit different. 41 00:02:38,320 --> 00:02:40,960 Let's leave this as the recommended option and click Okay. 42 00:02:42,890 --> 00:02:47,770 Android Studio then lets us know that it will update the local.properties file 43 00:02:47,770 --> 00:02:49,540 to use our default SDK. 44 00:02:49,540 --> 00:02:53,560 This just means that the Project Creator keeps the SDK in a different folder 45 00:02:53,560 --> 00:02:54,420 structure than we do. 46 00:02:56,310 --> 00:02:59,980 Next we can click Add Root to let Android Studio know what's going on. 47 00:03:01,670 --> 00:03:02,770 At the top of the screen, 48 00:03:02,770 --> 00:03:05,820 there seems to be a lot of options grayed out that shouldn't be. 49 00:03:07,730 --> 00:03:10,320 Let's sync the project with Gradle to see if everything's all right. 50 00:03:11,770 --> 00:03:14,030 This should generally be the first thing we try, 51 00:03:14,030 --> 00:03:16,440 because it will often help narrow down the specific issue. 52 00:03:18,260 --> 00:03:22,710 It looks like we're targeting a version of Android that we don't have in our SDK. 53 00:03:22,710 --> 00:03:25,160 Rather than installing the missing platform and 54 00:03:25,160 --> 00:03:30,510 then targeting an older SDK, let's just change our target to one we do have. 55 00:03:30,510 --> 00:03:33,050 An easy way to find out what Gradle settings work for 56 00:03:33,050 --> 00:03:36,800 us is to inspect the Gradle files in a recent project. 57 00:03:36,800 --> 00:03:41,210 Let's use the GitHub test project from earlier so we can compare Gradle files. 58 00:03:41,210 --> 00:03:42,552 To get a better view of things, 59 00:03:42,552 --> 00:03:45,354 I'm going to change both projects to the Project Perspective. 60 00:03:49,899 --> 00:03:56,485 Then, I'll drill down into the app folder, and we'll compare build.gradle files. 61 00:04:02,326 --> 00:04:05,974 Unfortunately, our new project doesn't seem to show the whole project 62 00:04:05,974 --> 00:04:08,110 in the Project Perspective. 63 00:04:08,110 --> 00:04:11,336 Luckily, we can find the files we need by clicking up here. 64 00:04:17,075 --> 00:04:19,790 Looks like there are a couple of differences. 65 00:04:19,790 --> 00:04:24,698 Let's change the compile SDK version, build tools version, 66 00:04:24,698 --> 00:04:28,317 and target SDK version to all be more current. 67 00:04:36,396 --> 00:04:40,933 Also, why do we have a RunProGuard property where GitHub test has 68 00:04:40,933 --> 00:04:42,179 a minifyEnable? 69 00:04:42,179 --> 00:04:47,175 A quick Google search for RunProGuard shows us that RunProGuard was renamed to 70 00:04:47,175 --> 00:04:49,911 MinifyEnabled in a recent Gradle update. 71 00:04:49,911 --> 00:04:57,950 Let's replace RunProGuard with MinifyEnabled. 72 00:04:57,950 --> 00:04:59,492 Before we sync the project, 73 00:04:59,492 --> 00:05:03,097 let's quickly compare the projects build.gradle file as well. 74 00:05:15,525 --> 00:05:18,315 Looks like we should be using a newer version of Gradle here too. 75 00:05:19,325 --> 00:05:19,991 Let's update that. 76 00:05:25,983 --> 00:05:28,745 Now we can sync the project and hope it all works. 77 00:05:32,710 --> 00:05:33,860 Still an error? 78 00:05:33,860 --> 00:05:35,670 This looks complicated. 79 00:05:35,670 --> 00:05:38,550 Before we dig too deep into this, let's poke around and 80 00:05:38,550 --> 00:05:42,250 see if we can't find a file that looks like it could be updated. 81 00:05:42,250 --> 00:05:45,730 Let's start with settings.gradle. 82 00:05:45,730 --> 00:05:47,943 Looks pretty simple, but let's see if it's different over here. 83 00:05:52,108 --> 00:05:53,880 Nope, exactly the same. 84 00:05:55,140 --> 00:05:57,103 Hmm. 85 00:05:57,103 --> 00:05:59,279 Let's try going into the gradle folder and 86 00:05:59,279 --> 00:06:01,945 comparing the gradle wrapper.properties files. 87 00:06:08,920 --> 00:06:13,140 Looks like there's a difference at the end of the distribution URL property. 88 00:06:13,140 --> 00:06:16,880 Taking a closer look at the difference, it seems to be a version number. 89 00:06:16,880 --> 00:06:20,680 Let's try updating the distribution URL to be the more current version. 90 00:06:22,350 --> 00:06:23,742 And then we can try syncing it again. 91 00:06:26,483 --> 00:06:27,570 And there we go. 92 00:06:27,570 --> 00:06:30,050 We've successfully updated our project. 93 00:06:30,050 --> 00:06:30,550 Awesome!