Gradle productFlavors raises error - Cannot add task ':assembleTest' as a task with that name already exists

StackOverflow https://stackoverflow.com/questions/22154973

Question

New to Gradle, trying to create build variants. I just added a productFlavor to the gradle file all of a sudden I get this strange error


$ gradle tasks
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "srcDirs" on "source set aild", value: "[src]".

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'SegmentIO'.
> Cannot add task ':assembleTest' as a task with that name already exists.

Here is my complete build.gradle


buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.8.+'
    }
}

apply plugin: 'android'


dependencies {
    compile files('libs/android-support-v4.jar')
}

android {
    buildToolsVersion "19.0.1"
    compileSdkVersion 17

    productFlavors {
        test {
        }

        prod {
        }
    }

     sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src', 'bundled-src']
            resources.srcDirs = ['src']
            aild.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
        }

        // test.assets.srcDirs = ['$java-project-root/assets/test']
        // prod.assets.srcDirs = ['$java-project-root/assets/test']

        instrumentTest.setRoot('tests')
    }

    dependencies {
        compile fileTree(dir: './libs', include: 'Amplitude.jar')
    }
}
Was it helpful?

Solution

I see two problems:

Deprecated dynamic property: "srcDirs" on "source set aild", value: "[src]".

is because you misspelled aild.srcDirs in your build file -- it should be aidl.srcDirs.

> Cannot add task ':assembleTest' as a task with that name already exists.

is because you're trying to create a flavor named "test", but this is being used by something else in the build and it's colliding. Try using a different name.

To be more specific, the Android plugin makes a number of tasks based off the flavor name (it does this with build types, too). If you have a flavor name "foo", assembleFoo performs an assemble but only on the foo flavor. There's already an assembleTest task, so it's colliding when it tries to make one for your flavor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top