java – How do I fix "Could not connect to remote process" while trying to debug the application?-ThrowExceptions

Exception or error:

I am making a android studio project and I try to debug my application.

Running the application works fine, but when I try to debug it I get this error:

Could not connect to remote process. Aborting debug session.

What can I do to fix the issue?

How to solve:

You need to restart the ADB.

kill adb.exe process.

how to restart ADB manually from Android Studio

###

Check if you have selected the right Build Variant, usually “release” comes with debuggable false

Example:

 buildTypes {
        release {
            debuggable false
            ....
        }
    }

is not recommendable change release to debuggable true, just change the right variant

   debug {
        debuggable true
        ....
    }

###

In My case,
For some reason I disabled Instant run and it has changed the Launch value from “Default Activity” to “Nothing” in “Run/Debug configurations”. So always it says “Could not connect to remote process. Aborting debug session” and I was not able to debug. I enabled Instant and changed the Launch value from “Nothing” to “Default Activity” in “Run/Debug configurations” and it worked. Hope this will help some one.

(to get Run/Debug configurations, click “app” drop down and click Edit Configurations)

###

In command line :

adb kill-server && adb start-server

This command will restart ADB

###

By default Android Studio builds the debug version of the application. However, during the publishing phase you may have switched to the release one as the tutorial suggests.

ADB won’t be able to attach to the application unless you revert to the debug configuration or you allow to the debug the release one.

If nothing of this works, you may resort in restarting ADB as explianed in How to restart ADB manually from Android Studio

Revert to debug configuration

  1. Choose Build->Select Build Variant
  2. Pick up debug in the second column
  3. Deploy the application again

Allow the release version to be debugged

  1. Select your application node in the tree
  2. Right click and choose Open Module Settings (or hit F4)
  3. Select Build Variants on the left
  4. Choose release on the right
  5. Set debuggable to true
  6. Apply and deploy the application

Keep in mind that your life won’t be easy as your application may be optimized and therefore not debugger friendly (e.g. you might not be able to step in certain methods, or view some local variables).

Leave a Reply

Your email address will not be published. Required fields are marked *