Why can't I use gradle task connectedDebugAndroidTest in my build script?

I can refer to connectedCheck task (which came from android plugin) from my build script:

connectedCheck.finalizedBy AndroidShowTestResults

But trying to use connectedDebugAndroidTest (which came from android plugin too)

  • Android keystore corrupted
  • what is the meaning of ImageView.ScaleType=“MATRIX” : Android
  • Android intent filter: associate app with file extension
  • ScrollView disable focus move
  • How to use dagger in a android library project
  • inside Android Dialog, how to setup onActivityResult for startActivityForResult?
  • connectedDebugAndroidTest.finalizedBy AndroidShowTestResults

    gives me

    Error:(48, 0) Could not find property ‘connectedDebugAndroidTest’ on project ‘:app’.

    And if I try

    task connectedDebugAndroidTest << {print '123'}

    it curses me with

    Error:Cannot add task ‘:app:connectedDebugAndroidTest’ as a task with that name already exists.

    I don’t undestand why I cannot refer to connectedDebugAndroidTest?

    Available gradle tasks are shown below:

    Gradle tasks

  • Radial Gradient for different dpi
  • Method to get all EditTexts in a View
  • MediaRecorder.stop() hanging with Android 4.0 (ICS)
  • android toolbar popupTheme vs theme
  • How To Display Border To Imageview?
  • KeyStore and Key Alias
  • 3 Solutions collect form web for “Why can't I use gradle task connectedDebugAndroidTest in my build script?”

    The android plugin defers the addition of several tasks especially those that have buildType or flavor names in them till a very late stage of the configuration phase. Which in turn means if you try to refer to these yet-to-be-added-tasks by name, you’re likely to see a “does not exist” type error messages. If you want to add dependencies around deferred-created tasks, you should wait until configuration is complete:

    gradle.projectsEvaluated {
        connectedDebugAndroidTest.finalizedBy AndroidShowTestResults

    Alternatively, you can add a listener to task-graph events, so you can do stuff as soon as a certain task is added to task-graph:

    tasks.whenTaskAdded { task ->
        if (task.name == 'connectedDebugAndroidTest') {
            task.finalizedBy AndroidShowTestResults


    task connectedTest(dependsOn: ["connectedDebugAndroidTest"]){
    connectedTest.finalizedBy "AndroidShowTestResults"

    I think you should try to open test and rebuild.

    enter image description here

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.