Android Studio 2.1.2: Downgrading Gradle Versions

Damn, that was hard. Android Studio 2.1.2 is really a bitch to tame. I had not used AS for a while, so when I opened it I needed to upgrade, which I did. That is when the pain started. If you are using an older phone than Android v21 Lollipop then you will need add a lower version of gradle 2.10 to work.

The different versions of Android require different versions of gradle. Upgrade your android version and your gradle version will correspond. Upgrade Android Studio and you support and older version of Android spells trouble.

I want to build apps for my older phone on Android 2.3.4 and need gradle 2.2. When I upgraded I unknowingly chose to upgrade the gradle plugin. This deletes your existing gradle plugin for he older version and installs the newer version, gradle 2.10. All your older apps that use a lower gradle version, will get the error “gradle project synch failed, basic functionality accessing invalid virtual file”. You will see in your Gradle Scripts > gradle-wrapper.properties > distributionURL the line “distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip”.

My old apps were looking for “distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip”, which, of course is no longer there. The upgrade process had deleted the old plugin, the one I wanted. You will need to go to services.gradle.org/distributions/, find your required gradle version and download it. Mine was gradle-2.10-all.zip. Move this .zip file to opt/android-studio/gradle, or where you installed your android studio. You should also see the gradle-2.10 directory. Extract here.

You will also need a version of Android v21 lollipop, so go download that as well. Though I do not need it, you will get an error without it. Once downloaded look for your app’s gradle properties and change the gradle version to the downgraded one, for me gradle 2.2. Follow these directions to run the gradle wrapper and build. Clean, build and then run. It worked for me, and I hope it works for you.

The default gradle version is still v2.10 but you can now use gradle 2.2 for your older phones.

Leave a Reply

Your email address will not be published. Required fields are marked *