Search code examples
android-studioandroid-testing

Why is the 'connectedDebugAndroidTest' Gradle task hanging indefinitely in my Android application projects?


I have a couple of longstanding Android application projects which I returned to this week after a couple of months away.

When I run the connectedAndroidTest (specifically: connectedDebugAndroidTest) Gradle task in these projects, the Gradle task just hangs indefinitely and no tests run on the Android device. This is demonstrated in the following screenshot:

Android Studio screenshot

I have tested and observed this behaviour in the following environments thus far:

Android Studio version macOS version
Giraffe (2022.3.1 Patch 2) Ventura 13.6
Electric Eel (2022.1.1 Patch 2) Ventura 13.1
Dolphin (2021.3.1 Patch 1) Ventura 13.1

Is anybody else experiencing this? Have you managed to find the root cause of the problem?

Notes

  1. This problem persists for me despite restarting Android Studio and despite restarting my machine.
  2. This problem exists for me in different Android projects and on different macOS machines.

Solution

  • I peeled away at the build tools and libraries in my application projects and managed to find the root cause of the problem.

    The problem was the following dependency declaration:

    debugImplementation 'androidx.fragment:fragment-testing:1.5.5'
    

    I created a minimal Android application project here which demonstrates the problem. Run the connectedDebugAndroidTest Gradle task in this project and you will observe that the Gradle task hangs indefinitely. Remove the androidx.fragment:fragment-testing dependency from the build.gradle file in this project and re-run the connectedDebugAndroidTest Gradle task. This time you will observe that the Gradle task runs to completion swiftly.

    If your project actually requires the androidx.fragment:fragment-testing library, the fix is to change your androidx.fragment:fragment-testing dependency declaration to the following:

    debugImplementation 'androidx.fragment:fragment-testing-manifest:1.6.0'
    androidTestImplementation 'androidx.fragment:fragment-testing:1.6.0'
    

    For a detailed discussion about the androidx.fragment:fragment-testing dependency declaration, see Issue #128612536 in IssueTracker.