Android Studio 0.4.5 breaks existing builds, here’s the fixBy Jim Wilson
I’m a big fan of Android Studio, and I’m fortunate to have had the opportunity to use it extensively ever since its original release. Officially, Android Studio is still considered a preview release, even if it is heavily used.
As a preview, Google does not have to guarantee that updates are free of breaking changes. Fortunately most updates do not introduce breaking changes, but breaking changes do sometimes happen. Android 0.4.5 is one of those updates that contains breaking changes.
To the casual observer, the fact that I’m addressing Android Studio 0.4.5 may seem odd because the current download over on the Android Studio download page (at least as of today) is Android Studio 0.4.2.
The issue is that Android Studio updates occur through a combination of full downloads and patches. Version 0.4.2 is the most recent version available as a full download, and is therefore the last version that was posted to the Android Studio download page. Any patch updates are applied through the update mechanism of Android Studio itself after Android Studio is installed. Version 0.4.5 is one of those patch updates.
This leads us to a good news/bad news situation: The bad news is that projects created with version 0.4.2, which has been the current full download for some time, will no longer build after you update to version 0.4.5. The good news is that fixing the problem is relatively easy, although the solution is not quite obvious.
Fix part 1
When you complete the update to Android Studio 0.4.5 and open one of your existing projects, you’ll see this scary message:
What in the world is that message telling us? It feels kind of like an “it’s broken” message. We know it’s bad but have no information as to what actually happened. Clicking on the “open event log” link to the right of the error message gives us a little more information.
Finally something we can work with.
Apparently the latest update to Android Studio requires a newer version of Gradle (the build system), and we now need version 1.9 or above. Updating our project configuration to use the newer version of Gradle should help.
To change the Gradle build settings, open the
build.gradle file that’s a peer to the application’s
src folder (be sure to open the correct
build.gradle file, there are multiple in the project hierarchy).
Inside that file you’ll find a number of dependencies including the following entry for Gradle:
Here’s where we have to be careful. Notice that you currently see a version number of
0.5. You might be tempted to change that version to 1.9 since the error message says you need version 1.9 or above, but this would be wrong. The version number ties to the tools package rather than directly to the Gradle version. The proper fix is for us to change the
Fix part 2
So with the Gradle version issue resolved, we can try to build our project. And with that comes more good news…and bad news. The good news is that scary “Gradle project sync failed” message is gone. The bad news? Now we have have a build error.
It looks like we need to download the latest Android build tools, which is reasonable. Keeping the build tools updated has long been part of being an Android developer. To get the latest build tools, launch the Android SDK Manager then download and install Rev. 19.0.1 of the Android SDK Build-tools.
Now that should do it. Let’s do the build again. And…we get the same error.
It turns out that we did indeed need to download the latest Android SDK Build-tools, but we also needed to tell the Android Studio project to use those latest build tools. To do this go back to the same
build.gradle file we worked on previously and locate the line for
We need to change the
buildToolsVersion value from
19.0.1. By changing the version number, the build system will now use the correct version of the build tools.
And now the build works!
Putting it all together
We touched on a number of issues as we went through the process of identifying how to fix our project to work with Android Studio 0.4.5, but in reality there are just a few steps to get things fixed up.
- Use the Android SDK Manager to download Android SDK Build Tools Rev. 19.0.1
- Open the
build.gradlefile that’s a peer to the
srcfolder in the project hierarchy
- Change the
com.android.tools.build:gradleentry to use version
- Change the
buildToolsVersionentry to use version
build.gradle file appears as follows:
And with that, you should be up and running with Android Studio 0.4.5.
About the Author
Jim Wilson is president of JW Hedgehog Inc., a consulting firm specializing in solutions for the Android, iOS, and Microsoft platforms. He has over 30 years of software development experience with the last 13 years heavily focused on mobile and location-based solutions. He is author of several Pluralsight courses on Android app development and cross-platform iOS/Android app development. Jim’s latest book is Creating Dynamic UI with Android Fragments.
Author's Website: http://jwhh.com