Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 296
Andrzej Skrodzki Avatar asked Jul 08 '15 13:07

Andrzej Skrodzki


People also ask

Why is my gradle build failing?

If gradle --version works, but all of your builds fail with the same error, it is possible there is a problem with one of your Gradle build configuration scripts. You can verify the problem is with Gradle scripts by running gradle help which executes configuration scripts, but no Gradle tasks.

Does Android Studio have Gradle files for each module?

It's helpful to remember that you will have build.gradle files for each module in your Android Studio Project. I kept hitting my head against the wall - "Where the heck is that line everyone's telling me to change?!"

What version of Gradle do I need for apt-get?

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.

How to fix Gradle connection time fluctuation while building project?

Check the Internet Connection - it should not fluctuate while building the project Build>> Clean Project Or Rebuild Project. I fixed the error by inserting following lines in gradle.properties: This sets the Gradle's connection timeout from the default 30s to 180s (3m).

How do I add a library to a Gradle project?

You should navigate to your libs folder in the IDE, right click on the jar and select to add the library to the project, it still needs to establish the dependency even though the jar appears to be there. Also look at your gradle built script to make sure the dependency appears there.


2 Answers

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:+.
like image 66
desseim Avatar answered Oct 12 '22 10:10

desseim


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.

like image 41
Emarc Magtanong Avatar answered Oct 12 '22 09:10

Emarc Magtanong