Search code examples
androidandroid-studiogradleandroid-gradle-pluginandroid-apt

Gradle build error in Android Studio


I am getting following error while building Android project in Android Studio 1.2.2 (fresh instalation)

Error:(76, 0) Could not find property 'unitTestVariants' on com.android.build.gradle.internal.dsl.TestOptions_Decorated@261be0aa.

Gradle version is 2.4

Android build gradle version is 1.2.3

Android-apt version is 1.4

Android SDK version is 19.


Solution

  • This is triggered by the Android apt plugin using the unitTestVariants property in its 1.5 version which is only available in the Android gradle plugin from version 1.3 onwards (cf. bug report).

    So for now either use android apt plugin version 1.4, or Android gradle plugin version 1.3 (see instructions below).

    Note that gradle version itself doesn't matter as far as this bug is concerned and you could use 2.4 as well as 2.2.1.


    Use Android gradle plugin >= 1.3

    1. make sure the projects buildscript block references jcenter() (the beta versions aren't on maven)
    2. replace all instances of 'com.android.tools.build:gradle:1.2.3' by 'com.android.tools.build:gradle:1.3.0-beta4'
    3. re-sync the gradle project from within AndroidStudio

    Use Android apt plugin <= 1.4

    (courtesy of @emarc-magtanong)

    • make sure all references to the Android apt plugin read com.neenbedankt.gradle.plugins:android-apt:1.4 and not com.neenbedankt.gradle.plugins:android-apt:1.5 nor com.neenbedankt.gradle.plugins:android-apt:+.