Installing Android Studio and an ensuing rabbit hole
I recently lost several hours trying to run a perfectly functional project I had just checked out from github on a new installation of Android Studio for Windows 10. I was not expecting any compilation errors at all because the project ran fine on two other machines.
The SDK manager was missing SDK Platform 22 (Lollipop 5.1.1). This should have been my first clue as to what was going on for problem 3 a little later, Android Studio comes with the most recent SDK Platform and tools, as of today that’s 23 (Marshmallow 6.0).
A simple click of the link provided in the error downloads and installs 22.
Error: Gradle 2.4 requires Android Gradle plugin 1.2.0 (or newer) but project is using version 1.1.0.
Please use Android Gradle plugin 1.2.0 or newer.
Hmm that was unexpected. Thinking about it for a little makes sense though, the new installation of Android Studio comes with a newer Gradle wrapper, so my gradle files need to use 1.2.0 now. This link explains what Android Gradle plugin versions are required, the compatibility seems to have levelled out now so this is unlikely to be a problem again for a while — though you should try and keep your Gradle plugin up to date to utilise new features.
I upgrade all Gradle versions to 1.2.0 and hit sync.
No resource found for a material button style? What?! Stack Overflow to the rescue:
When you updates your android studio, it uses api version 23 by default, Which is the main reason of its occurance. So…stackoverflow.com
In that link you will find a lovely highly voted answer from user Tanis.7x, the compileSdkVersion needs to match the support library’s major version. Beautiful I’ll just make them match and hit sync once more then I’ll be clear.
Uh oh they match already, compileSDKVersion reads 22. All support libraries are using 22.2.1. I carefully pour over every answer and comment in that first question, trying multiple gradle versions, cleans and rebuilds, restarts and finally resort to trying to upgrade to 23 to see what happens. That breaks a whole lot more in my project, apache http has been deprecated and all sorts. My team won’t like that.
Then I realize there is no reason I should have to use 23, the failure opens the v23\values-v23.xml file with the errors in red, but my code doesn’t use 23 anywhere. So I uninstall the SDK 23 Build-Tools via the manager, and clean and rebuild but that doesn’t help either. Then I very luckily come across the same question, worded slightly differently:
Sign up × Stack Overflow is a question and answer site for professional and enthusiast programmers. It’s 100% free…stackoverflow.com
Inside a beautiful comment on that question is this link to a bug report here, whereupon comment #8 has the answer:
You need to delete the build tools 23 from the sdk manager and then in the sdk folder (yes the actual folder) open up sdk/extras/android/m2repository/com/android/support/appcompat-v7
blow away the entire 23.0.0 folder
then in the same appcompat folder open maven-metadata.xml and delete the one line <version>23.0.0</version>
clean and rebuild
I do that, clean, rebuild and pray (remember I’ve been at this for over 2 hours at this stage). Hallelujah it works!
So even though I am targeting 22 explicitly everywhere in the project, the build tools are trying to default to 23 without me telling them to which aside from being a little scary is rather un-intuitive and in fact, requires a bug report. The only reason this wasn’t a problem on mine or my colleagues machines until now was that we hadn’t opened the SDK manager and updated since 23 came out — it just affected my new installation. What’s more, our SDK updates are not checked into a shared repo so if anyone had merely installed 23 just to play around, they would also break their project.
Moral of the story: if your project compiles on one machine and not on another, chances are it’s the build tools fault, so try and match them perfectly, even if it means digging into folders and manually removing items.
Problems or suggestions? You know what to do :)