Your Android Project doesn’t work in my IDE!

You just downloaded an online example project which will show you how to create a cool app for Android. You open it and you are presented by a popup dialog telling you the project is using an old version of the Gradle plugin. This wise popup suggests you update to project to take advantage of some new Android hotness like Instant Run. You’re all, “sure I’ll update!” After all, the popup is clearly wiser than you and who are you to argue with this manifestation of modal window management placed dead center in the screen? You update then you are greeted with build errors! How can this be? All you did was open the project and follow the suggestion to update! You haven’t modified any additional source files! Hi, I’m Cliff. You’re here because you think Android development sucks potatoes… and not just any kind of potatoes. You believe it sucks those big thick Idaho monsters… through a McDonald’s milkshake straw… on a hot summer day… when you’re extremely thirsty… and you are in dire need of hydration… and all you have is this Android suckiness which is severely impeded by these big ol’ potatoes! …That sort of sulkiness.

Maybe you’e a newcomer to the platform, or maybe you’re an author who recently released a written tutorial or video how-to and your audience is complaining about how all of your examples are broken. Whatever the case, the situation is not optimal. Unfortunately this problem happens quite often but today I’m going to attempt to explain how to solve the problem and why it exists in the first place.

Android Studio is in rapid development and updates feel like they come each week. With such a rapid cycle things sometimes get out of sync leaving you with version mismatch problems. Updating an Android Studio project is sometimes a 2-4 step process and you have to satisfy a different set of errors at each step. Taking the update option from the dialog will faithfully update the Gradle plugin as promised but it leaves the gradle wrapper at whatever version was originally configured along with another error! In the latest version of Android Studio you get a hyperlink thing next to the error that you can use to automatically fix the problem, but most people new to Android will stop at this point and feel lost. (Two errors in a row? I must be making the problem worse!) If you’re a seasoned dev you may overthink the solution and go drilling through all of your Gradle build files flipping all different kinds of versions possibly introducing further errors. (I’ve done this on several occasions.) If you’re an intermediate level dev then you’ll probably Google the error and hit a Stack Overflow post where the top answer tells you something completely helpless like “use the default Gradle wrapper”. Any one of these common fixes will leave you frustrated.

The solution is actually quite simple. Just pay attention to what the error says, “Error:Gradle version 2.10 is required. Current version is 2.4.” It’s implying you need to update the Gradle version used by the Gradle wrapper to a specific version, 2.10. In your set the distributionUrl to:
Do NOT get this confused with the version of the Gradle plugin which may be set to something like 2.1.0. Using this
will give further errors and increase your frustration level, sending you off to Google what the latest version of Gradle actually is and which version works best with the Android Gradle plugin.

In the end always pay careful attention to your error messages and learn to distinguish between them. Be prepared to walk through 2-4 different types of errors when updating an Android project built in older versions of Android Studio. Each error should convey a different message and a unique proposed solution. I’m sharing this tip because I’ve been bitten several times by my own projects which were developed under Android Studio 0.9x migrated to 1.x and no longer work out of the box in 2.x. I’ve also been stung when downloading example projects created by others which were developed only months ago and no longer work out of the box. Android Studio gets updates at an incredible rate and projects will feel broken but with a little patience and understanding you can work through the initial errors.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s