Gradle flavor问题:具有该名称的SourceSet已存在

时间:2014-09-17 16:28:36

标签: android gradle android-library

我试图使用另一个库设置库的构建并定义2种口味。

这里是build.gradle文件:

buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://jcenter.bintray.com' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.2'
        classpath 'org.robolectric:robolectric-gradle-plugin:0.12.0'
        classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1')
    }
}

apply plugin: 'com.android.library'
apply plugin: 'robolectric'
apply plugin: 'com.jfrog.artifactory-upload'

robolectric {
    include '**/*Test.class'
    exclude '**/espresso/**/*.class'
}

android {
    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
    }

    compileSdkVersion 20
    buildToolsVersion "20"

    defaultConfig {
        applicationId "com.nap.android.api.country"
        minSdkVersion 14
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    }

    buildTypes {
        release {
            runProguard false
        }

        productFlavors {
            nap {
                applicationId "com.nap.android.api.country.nap"
            }

            mrp {
                applicationId "com.nap.android.api.country.mrp"
            }
        }

        //allows publication of flavours
        publishNonDefault true
    }
}

    dependencies {
    compile project(':apiCoreLibrary')

    androidTestCompile 'junit:junit:4.11'
    androidTestCompile project(':apiCoreLibrary')

    //TEST

    androidTestCompile 'com.squareup.retrofit:retrofit:1.6.1'

    androidTestCompile 'com.jakewharton.espresso:espresso:1.1-r3'
    androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') {
        exclude group: 'com.squareup.dagger'
    }

    androidTestCompile 'com.google.guava:guava:18.0',
            'com.squareup.dagger:dagger:1.2.2',
            'org.hamcrest:hamcrest-integration:1.3',
            'org.hamcrest:hamcrest-core:1.3',
            'org.hamcrest:hamcrest-library:1.3'

    androidTestCompile('junit:junit:4.12-beta-1') {
        exclude module: 'hamcrest-core'
    }

    androidTestCompile 'org.mockito:mockito-core:1.9.5'
    androidTestCompile 'org.powermock:powermock-mockito-release-full:1.5.5'

    androidTestCompile('org.robolectric:robolectric:2.3') {
        exclude module: 'classworlds'
        exclude module: 'commons-logging'
        exclude module: 'httpclient'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        exclude module: 'plexus-container-default'
        exclude module: 'plexus-interpolation'
        exclude module: 'plexus-utils'
        exclude module: 'wagon-file'
        exclude module: 'wagon-http-lightweight'
        exclude module: 'wagon-provider-api'
    }

    androidTestCompile 'com.squareup:fest-android:1.0.8'
}

我收到以下错误:

 Error:Cannot add a SourceSet with name 'testDebug' as a SourceSet with that name already exists.

如果我注释掉一个味道块,错误就会消失。是否需要将某些内容添加到flavor配置中以解决此问题?

0 个答案:

没有答案