Opening a GitHub Project6:31 with Ben Deitch
Pulling GitHub projects into Android Studio is a great way to see how a project works. This video covers how to pull a GitHub project into Android Studio as well as how to fix some common errors that you might encounter.
Pushing our own projects to GitHub is certainly useful, but 0:00 what if we want to contribute to an outside project? 0:03 How can we do that from within Android Studio? 0:06 Luckily, Android Studio makes this easy as well, but 0:10 first, let's take a look at the project we'll be contributing to. 0:14 We are going to be making changes to the fun facts project 0:18 from the beginning of the Android track. 0:21 If you're not familiar with the project, that's okay. 0:23 It's a fairly simple project with only one button. 0:26 When the button is pressed, we randomly select a fun fact and 0:29 a background color for the screen. 0:33 Let's open the project on GitHub. 0:35 It's located at github.com/treehouse/android-fun-facts-gi- 0:37 thub, which is in the Teacher's Notes 0:46 along with a link to the Fun Facts course. 0:50 Once we're here, we can click the Fork button on the upper-right, 0:56 to fork this project into our own repository. 0:59 If you're not interested in contributing to a project, 1:03 you can skip the forking step, and just clone the project from the source. 1:06 Since we'd like to contribute to this project, we'll stick with forking. 1:10 Once forking is finished, 1:14 we'll want to find the clone URL on the right side of the screen. 1:15 Let's copy that, as we'll need it to clone the repository. 1:19 Now that we know what project we're working with, and 1:22 we've created our fork, let's start up Android Studio. 1:25 But this time, instead of creating or opening an existing project, 1:28 let's click on Check Out Project from Version Control, and select GitHub. 1:33 Next, if it isn't already saved, we'll be prompted for our login information. 1:41 Now we can paste in the clone URL from earlier, and 1:51 hit Test to verify it's a valid GitHub URL. 1:54 Then we select the Project Directory and the name of our project, 2:01 I'm going to pick FunFacts, and click Clone. 2:05 And let's click Yes to open the project. 2:12 Awesome! 2:17 We've successfully pulled a project from GitHub and everything looks good to go. 2:17 But what if it didn't work? 2:21 How would we fix that? 2:22 I'm going to quickly pull in an older version of this project to show how to fix 2:24 some common issues you might find when checking out a project from GitHub. 2:28 Right off the bat, things are a bit different. 2:35 Let's leave this as the recommended option and click Okay. 2:38 Android Studio then lets us know that it will update the local.properties file 2:42 to use our default SDK. 2:47 This just means that the Project Creator keeps the SDK in a different folder 2:49 structure than we do. 2:53 Next we can click Add Root to let Android Studio know what's going on. 2:56 At the top of the screen, 3:01 there seems to be a lot of options grayed out that shouldn't be. 3:02 Let's sync the project with Gradle to see if everything's all right. 3:07 This should generally be the first thing we try, 3:11 because it will often help narrow down the specific issue. 3:14 It looks like we're targeting a version of Android that we don't have in our SDK. 3:18 Rather than installing the missing platform and 3:22 then targeting an older SDK, let's just change our target to one we do have. 3:25 An easy way to find out what Gradle settings work for 3:30 us is to inspect the Gradle files in a recent project. 3:33 Let's use the GitHub test project from earlier so we can compare Gradle files. 3:36 To get a better view of things, 3:41 I'm going to change both projects to the Project Perspective. 3:42 Then, I'll drill down into the app folder, and we'll compare build.gradle files. 3:49 Unfortunately, our new project doesn't seem to show the whole project 4:02 in the Project Perspective. 4:05 Luckily, we can find the files we need by clicking up here. 4:08 Looks like there are a couple of differences. 4:17 Let's change the compile SDK version, build tools version, 4:19 and target SDK version to all be more current. 4:24 Also, why do we have a RunProGuard property where GitHub test has 4:36 a minifyEnable? 4:40 A quick Google search for RunProGuard shows us that RunProGuard was renamed to 4:42 MinifyEnabled in a recent Gradle update. 4:47 Let's replace RunProGuard with MinifyEnabled. 4:49 Before we sync the project, 4:57 let's quickly compare the projects build.gradle file as well. 4:59 Looks like we should be using a newer version of Gradle here too. 5:15 Let's update that. 5:19 Now we can sync the project and hope it all works. 5:25 Still an error? 5:32 This looks complicated. 5:33 Before we dig too deep into this, let's poke around and 5:35 see if we can't find a file that looks like it could be updated. 5:38 Let's start with settings.gradle. 5:42 Looks pretty simple, but let's see if it's different over here. 5:45 Nope, exactly the same. 5:52 Hmm. 5:55 Let's try going into the gradle folder and 5:57 comparing the gradle wrapper.properties files. 5:59 Looks like there's a difference at the end of the distribution URL property. 6:08 Taking a closer look at the difference, it seems to be a version number. 6:13 Let's try updating the distribution URL to be the more current version. 6:16 And then we can try syncing it again. 6:22 And there we go. 6:26 We've successfully updated our project. 6:27 Awesome! 6:30
You need to sign up for Treehouse in order to download course files.Sign up