i too have also gotten the error "connection could not be made as the target machine actively refused it" recently (when i tried to connect to adb using command prompt)
Trying with -> adb connect localhost:5555 or adb connect 127.0.0.1:5555 would not work. You need to identify your bluestack device ip address. You can identify the ip address using the preferences in your bluestack emulator setting. (where you enabled ADB in bluestack).
I did the following to resolve the error you had encountered and successfully connect Android studio to Bluestack. please try the following steps. (I am using windows 10, Android Studio 4.0.1, Bluestacks 4.200.)
- find your android studio sdk platform tool folder. For me its is
custom installed in my D drive. for example->
D:\AppData\Local\Android\Sdk\platform-tools
- right click on adb.exe
and run as administrator. (click on yes if a pop up ask if you would
like to make changes to your devices. After that you would only see
another pop up that suddenly disappear.)
- open Bluestacks. Run your selected emulator (samsung/pixel etc). Ensure that
you have enable "Enable Android Debug Bridge (ADB) in the emulator
preferences.
- open command prompt. cd to your platform tools folder path.
- enter the following command->adb connect xxxxxxxxxxx where xxxxxx is your
device localhost ip. (see attach pic. My device ip is
127.0.0.1:xxxxx hence my command is ->adb connect 127.0.0.1:xxxxx
- continue with the following command->adb devices you would see your bluestack
emulator device. same ip listed.
- open your android studio. You would be able to see your bluestack emulator
[
