Search code examples
androidandroid-studiojunitmockito

Exception while executing unit test cases - Could not self-attach to current VM using external process


I am getting this error in the android studio since the last two days when I run any test cases.

Here are the error logs.

Caused by: java.lang.IllegalStateException: Could not self-attach to current VM using external process
    at net.bytebuddy.agent.ByteBuddyAgent.installExternal(ByteBuddyAgent.java:675)
    at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:606)
    at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:586)
    at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:538)
    at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:515)
    at io.mockk.proxy.jvm.JvmMockKAgentFactory.initInstrumentation(JvmMockKAgentFactory.kt:134)
    at io.mockk.proxy.jvm.JvmMockKAgentFactory.init(JvmMockKAgentFactory.kt:34)
    at io.mockk.impl.JvmMockKGateway.<init>(JvmMockKGateway.kt:46)

I have tried the below solutions but unfortunately nothing works for me.

  1. Invalid cache and restart
  2. Clear gradle cache and restart Tried
  3. following commands in terminal
rm -rfv ~/Library/Application Support/AndroidStudio*
rm -rfv ~/Library/Preferences/AndroidStudio*
rm -rfv ~/Library/Caches/AndroidStudio*
rm -rfv ~/Library/Logs/AndroidStudio*
rm -rfv ~/.AndroidStudio*
  1. Changed the JDK versions(Currently using 11.0.13)

  2. Tried with older versions of android studio

Can anyone help me to fix this. Thanks in advance.


Solution

  • Finally i got the solution to set the below line in .bash_profile in my mac.

    export JDK_JAVA_OPTIONS="-Djdk.attach.allowAttachSelf=true"