Milos Zikic - Personal site, sharing thoughts about startups, products and engineering

Solving backward compatibility issues with new Android build system between Intellij Idea versions

New Android built tools based on gradle are awesome and it is great that we are heading to some form of standardization.

BUT!

Android SDK and gradle build plugin breaks compatibility between versions! And that is causing pain, especially for large teams. E.g. SDK Tools from version 23 do not include zipalign anymore and therefor android plugin 0.10.+ will not work -> workaround is to get zipalign from older sdk tools version :(

In the team we have people working in Idea 13 and some of the guys use AndroidStudio and some are on Eclipse. We need to support all of this environments and our Jenkins CI server.

In order to do this we created a small workaround so both Idea 13 and AndroidStudio devs can continue to work and utilize Idea Gradle integration.

Here is how:

  • People using Idea 14 EAP or AndroidStudio should set the following as Gradle VM Arguments:
-Didea.version=14
  • And then some changes to settings.gradle and build.gradle:

settings.gradle

// check if we are using AndStudio or Idea 14 EAP
boolean fromIdea14 = System.properties["idea.version"]?.toString().equals("14")

org.gradle.api.internal.initialization.DefaultScriptHandler.metaClass.toolsVersion = fromIdea14 ? "0.11.+" : "0.10.+"


build.gradle

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'com.android.tools.build', name: "gradle", version: getBuildscript().toolsVersion
}
}

And that is it!

Happy hacking ;)

Share this post

comments powered by Disqus