Rendy Del Rosario
Rendy Del Rosario

Reputation: 1297

Android Studio - Error Building - Android tasks have already been created

Getting the following error when building the project:

Error:(2, 0) Android tasks have already been created. This happens when calling android.applicationVariants, android.libraryVariants or android.testVariants. Once these methods are called, it is not possible to continue configuring the model.

Root build.gradle:

buildscript {
      repositories {
        jcenter()
      }
      dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
      }
}
apply plugin: 'android'

android {
    compileSdkVersion 'Google Inc.:Google APIs:19'
    buildToolsVersion '19.1.0'
    defaultConfig {
       versionCode 5
       versionName '5'
       targetSdkVersion 19
       minSdkVersion 10
       applicationId 'tsp.movil'
    }
}
dependencies {
     compile 'com.google.android.gms:play-services:7.0.0'
     compile 'com.android.support:support-v4:22.1.1'
}

App build.gradle:

android {
     compileSdkVersion 'Google Inc.:Google APIs:19'
     buildToolsVersion '19.1.0'
     defaultConfig {
        applicationId "tsp.movil"
        minSdkVersion 10
        targetSdkVersion 19
        versionCode 5
        versionName '5'
     }
     buildTypes {
         release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),      'proguard-rules.txt'
         }
     }
     productFlavors {
     }
}
dependencies {
    compile 'com.android.support:support-v4:19.1.0'
    compile 'com.google.android.gms:play-services:+'
    compile files('libs/zbar.jar')
}

Upvotes: 3

Views: 6007

Answers (3)

Daniel Beleza
Daniel Beleza

Reputation: 419

I've faced a similar issue, with the same error message. The issue in my case was that I've had created a module inside a package and then deleted it manually in (MacOS) Finder.

The problem was that I forgot to also remove the include ::myModule line from the settings.gradle file.

Upvotes: 0

Piyush Agarwal
Piyush Agarwal

Reputation: 25858

Your Top Level build.gradle file should only have the configuration common for all modules of your project.

make the following changes :

Root build.gradle file should have only this piece of code

buildscript {
      repositories {
        jcenter()
      }
      dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
      }
}

allprojects{
    repositories {
        jcenter()
      }
}

Upvotes: 6

Noyisme
Noyisme

Reputation: 37

look on this: How to define common android properties for all modules using gradle the 3rd comment says Android tasks have already been created. This happens when calling android.applicationVariants, android.libraryVariants or android.testVariants. Once these methods are called, it is not possible to continue configuring the model.

Upvotes: -1

Related Questions