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