5

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.

botteaap
  • 5,790
  • 3
  • 29
  • 35
  • What is your `Build Tools` version? – Prerak Sola Jul 08 '15 at 13:45
  • Maybe there's a conflict in your plugins. Try to remove the latest know you just added. – Nevin Chen Jul 09 '15 at 01:00
  • Nearly the same error began to occur in my env (Android Studio 1.3) today. desseim's answer fixed that. – findall Jul 09 '15 at 02:31
  • This issue has been fixed in 1.6. You probably used a `+` for the `android-apt` version, which always uses the latest version. The 1.5 version of `android-apt` introduced a bug, breaking your project. If you would have specified `1.4` as the version that would never happened. – botteaap Aug 01 '15 at 09:09

2 Answers2

4

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:+.
desseim
  • 7,968
  • 2
  • 24
  • 26
1

Use gradle 2.4. This happened to me as well and tried for it to work with gradle 2.2.1 changing the build tools and android gradle plugin. The only thing that worked was to update gradle. You can update the gradle wrapper.

Emarc Magtanong
  • 167
  • 1
  • 1
  • 7
  • 2
    got it working with gradle 2.2.1, the problem was that apt version I was using was classpath 'com.neenbedankt.gradle.plugins:android-apt:+' changed it to classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' – Emarc Magtanong Jul 09 '15 at 03:37
  • Indeed, I updated my answer with more information concerning the android apt plugin as well (thanks!). Note that gradle version is irrelevant though and only updating to `2.4` won't help ;) – desseim Jul 09 '15 at 10:21