Search code examples
androidgradleandroid-gradle-pluginandroid-build

gradle task is ambiguous due to custom build variant


I have an android project with a 'debugMock' build type for connecting to a mock api. When my CI (App Center) tries to run tests I get the following error

Task 'testDebug' is ambiguous in root project 'my-project'. Candidates are: 'testDebugDebug', 'testDebugDebugMock', 'testDebugMockUnitTest', 'testDebugRelease', 'testDebugUnitTest'.

This is as a result of the gradle testDebug command and I can reproduce locally. How can I avoid the above error? My build config is pretty standard:

buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        debugMock.initWith(buildTypes.debug)
        debugMock {
            applicationIdSuffix = ".mock"
            matchingFallbacks = ['debug']

        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

Solution

  • It might be the name, which causes confusion:

    mock {
        initWith debug
        applicationIdSuffix = ".mock"
        matchingFallbacks = ['debug']
    
    }