How to debug when running Robolectric tests in Android Studio?

10,684

Solution 1

I found the reason of the error. To make it run you need to uncheck the "Use in-process build" option in Compiler -> Gradle settings of Android Studio.

enter image description here

Solution 2

I was getting this error on linux, and the problem was that the another previous process has taken the port and hung. So, the solution is a netstat to locate the process blocking the port, then kill this process, or you can restart the machine.

Share:
10,684
Eugene
Author by

Eugene

Updated on June 06, 2022

Comments

  • Eugene
    Eugene almost 2 years

    I need to run debug while my tests execution in Android Studio + Robolectric. Each time I try to run them by selecting debug for the test task from Gradle tasks I get the error message:

    Error running package_name:app_name [test]: Unable to open debugger port : java.net.SocketException "Socket closed"

    Any ideas?

  • StackFlowed
    StackFlowed over 9 years
    @HeathBorders can you please post detail how to make this work on Intellij
  • user963601
    user963601 over 9 years
    I don't remember now. I hope past me would have added more notes or a different answer if there were more steps.
  • Nilzor
    Nilzor over 9 years
    This slows down the build, so I hope Google comes around to fix this in Android Studio. @HeathBorders: IntelliJ IDEA does not have this issue, as it doesn't support In-process build in the first place.
  • parvus
    parvus about 9 years
    This does not help me. Running Android Studio 1.1.0
  • Maciek Czarnik
    Maciek Czarnik almost 9 years
    Where can I find this setting? Sorry I'm very new to Android Studio, and I don't like Android in general :P
  • Benjamin Burkhart
    Benjamin Burkhart over 7 years
    This doesn't seem to apply any more in IntelliJ 2016.3.3
  • Ms. Amelia S. Greene
    Ms. Amelia S. Greene about 7 years
    This setting seems to have disappeared in Android Studio v1.3. Here is a workaround: stackoverflow.com/a/31570957/1434060