Android Studio 0.4.5 breaks existing builds, here’s the fix
- select the contributor at the end of the page -
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 1When 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.
build.gradlefile that’s a peer to the application’s
srcfolder (be sure to open the correct
build.gradlefile, there are multiple in the project hierarchy).
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 2So 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.
build.gradlefile we worked on previously and locate the line for
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 togetherWe 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.gradlefile appears as follows: